def test_save_and_upload(self): testrun_output = io.BytesIO() mock_converter = mock.MagicMock(return_value=MOCK_TEST_RUN_PROTO) callback = mfg_inspector.MfgInspector( user='******', keydata='keydata', token_uri='') callback.set_converter(mock_converter) callback.save_to_disk(filename_pattern=testrun_output)(MOCK_TEST_RUN) callback.upload()(MOCK_TEST_RUN) # Parse what was written to BytesIO back into a proto and compare testrun_output.seek(0) testrun = test_runs_pb2.TestRun() testrun.ParseFromString(testrun_output.read()) self.assertEqual(MOCK_TEST_RUN_PROTO, testrun) self.mock_send_mfg_inspector_data.assert_called_with( MOCK_TEST_RUN_PROTO, self.mock_credentials, callback.destination_url, guzzle_pb2.COMPRESSED_TEST_RUN) # Make sure mock converter only called once i.e. the test record was # was converted to a proto only once. This important because some custom # converters mutate the test record, so the converter is not idempotent. self.assertEqual(1, mock_converter.call_count)
def test_upload_only(self): mock_converter = mock.MagicMock(return_value=MOCK_TEST_RUN_PROTO) callback = mfg_inspector.MfgInspector( user='******', keydata='keydata', token_uri='').set_converter( mock_converter) callback.upload()(MOCK_TEST_RUN) self.mock_send_mfg_inspector_data.assert_called_with( MOCK_TEST_RUN_PROTO, self.mock_credentials, callback.destination_url)
def test_save_only(self, user_mock): user_mock.prompt.return_value = 'SomeWidget' record = yield self._test testrun_output = io.BytesIO() callback = mfg_inspector.MfgInspector() callback.set_converter( converter=test_runs_converter.test_run_from_test_record,) save_to_disk_callback = callback.save_to_disk( filename_pattern=testrun_output) save_to_disk_callback(record) # Parse what was written to BytesIO back into a proto and compare testrun_output.seek(0) testrun = test_runs_pb2.TestRun() testrun.ParseFromString(testrun_output.read()) expected_test_run_proto = test_runs_converter.test_run_from_test_record( record) self.assertEqual(expected_test_run_proto, testrun) self.assertFalse(self.mock_send_mfg_inspector_data.called)