<s> import os <EOL> from . import makeprefs , dummyarchive <EOL> from testtools import TestCase <EOL> from testtools . matchers import Contains <EOL> from mock import Mock , patch <EOL> from StringIO import StringIO <EOL> class FetchCommandTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( FetchCommandTest , self ) . setUp ( ) <EOL> self . prefs = makeprefs ( ) <EOL> self . home = os . path . join ( '<STR_LIT:t>' , '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> def tearDown ( self ) : <EOL> super ( FetchCommandTest , self ) . tearDown ( ) <EOL> def _makeit ( self , * args , ** kwargs ) : <EOL> from lacli . command import LaFetchCommand <EOL> return LaFetchCommand ( * args , ** kwargs ) <EOL> def _makeupload ( self , * args , ** kwargs ) : <EOL> return Mock ( upload = Mock ( ** kwargs ) ) <EOL> def test_command ( self ) : <EOL> assert self . _makeit ( Mock ( ) , Mock ( ) , self . prefs ) <EOL> def test_fetch_archive_nonexistent ( self ) : <EOL> with patch ( '<STR_LIT>' , new_callable = StringIO ) as out : <EOL> registry = Mock ( ) <EOL> registry . prefs = self . prefs <EOL> registry . session . archives . return_value = ( ) <EOL> cli = self . _makeit ( registry ) <EOL> cli . onecmd ( '<STR_LIT>' ) <EOL> self . assertEqual ( "<STR_LIT>" , out . getvalue ( ) ) <EOL> def test_fetch_archive ( self ) : <EOL> with patch ( '<STR_LIT>' , new_callable = StringIO ) as out : <EOL> with patch ( '<STR_LIT>' ) as ask_key : <EOL> ask_key . return_value = '<STR_LIT>' * <NUM_LIT:8> <EOL> registry = Mock ( ) <EOL> registry . prefs = self . prefs <EOL> registry . cache . save_cert . return_value = ( '<STR_LIT>' , None ) <EOL> registry . session . archives . return_value = ( dummyarchive , ) <EOL> cli = self . _makeit ( registry ) <EOL> cli . onecmd ( '<STR_LIT>' ) <EOL> self . assertThat ( out . getvalue ( ) , <EOL> Contains ( '<STR_LIT>' ) ) <EOL> docs = registry . cache . save_cert . call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertTrue ( '<STR_LIT>' in docs ) <EOL> self . assertTrue ( '<STR_LIT>' in docs ) <EOL> self . assertTrue ( '<STR_LIT>' in docs ) <EOL> self . assertEqual ( docs [ '<STR_LIT>' ] . title , '<STR_LIT>' ) </s>
