#NEWLINE# @ mock . patch ( 'hashlib.md5' ) #NEWLINE# @ mock . patch ( 'six.moves.builtins.open' ) #NEWLINE# @ mock . patch ( 'requests.get' ) #NEWLINE# def test_stream_raw_image_onto_device( self , requests_mock , open_mock , md5_mock ) : #NEWLINE# #INDENT# image_info = _build_fake_image_info ( ) #NEWLINE# response = requests_mock . return_value #NEWLINE# response . status_code = 200 #NEWLINE# response . iter_content . return_value = [ 'some' , 'content' ] #NEWLINE# file_mock = mock . Mock ( ) #NEWLINE# open_mock . return_value . __enter__ . return_value = file_mock #NEWLINE# file_mock . read . return_value = None #NEWLINE# hexdigest_mock = md5_mock . return_value . hexdigest #NEWLINE# hexdigest_mock . return_value = image_info [ 'checksum' ] #NEWLINE# self . agent_extension . _stream_raw_image_onto_device ( image_info , '/dev/foo' ) #NEWLINE# requests_mock . assert_called_once_with ( image_info [ 'urls' ] [ 0 ] , stream = True , proxies = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# expected_calls = [ mock . call ( 'some' ) , mock . call ( 'content' ) ] #NEWLINE# file_mock . write . assert_has_calls ( expected_calls )