def testTestArgumentValidation(self): """Test function argument validation tests.""" self.PatchObject(image_service, 'Test', return_value=True) input_proto = image_pb2.TestImageRequest() output_proto = image_pb2.TestImageResult() # Nothing provided. with self.assertRaises(cros_build_lib.DieSystemExit): image_controller.Test(input_proto, output_proto, self.api_config) # Just one argument. input_proto.build_target.name = self.board with self.assertRaises(cros_build_lib.DieSystemExit): image_controller.Test(input_proto, output_proto, self.api_config) # Two arguments provided. input_proto.result.directory = self.result_directory with self.assertRaises(cros_build_lib.DieSystemExit): image_controller.Test(input_proto, output_proto, self.api_config) # Invalid image path. input_proto.image.path = '/invalid/image/path' with self.assertRaises(cros_build_lib.DieSystemExit): image_controller.Test(input_proto, output_proto, self.api_config) # All valid arguments. input_proto.image.path = self.image_path image_controller.Test(input_proto, output_proto, self.api_config)
def testSignerTestSuccess(self): """Test successful call handling.""" self.PatchObject(image_lib, 'SecurityTest', return_value=True) input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path output_proto = image_pb2.TestImageResult() image_controller.SignerTest(input_proto, output_proto, self.api_config)
def testSignerTestFailure(self): """Test function output tests.""" input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path output_proto = image_pb2.TestImageResult() self.PatchObject(image_lib, 'SecurityTest', return_value=False) image_controller.SignerTest(input_proto, output_proto, self.api_config) self.assertFalse(output_proto.success)
def testSignerTestNoImage(self): """Test function argument validation.""" input_proto = image_pb2.TestImageRequest() output_proto = image_pb2.TestImageResult() # Nothing provided. with self.assertRaises(cros_build_lib.DieSystemExit): image_controller.SignerTest(input_proto, output_proto, self.api_config)
def testValidateOnly(self): """Sanity check that validate-only calls don't execute any logic.""" patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True) input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path output_proto = image_pb2.TestImageResult() image_controller.SignerTest(input_proto, output_proto, self.validate_only_config) patch.assert_not_called()
def testMockError(self): """Test that mock call does not execute any logic, returns error.""" patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True) input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path output_proto = image_pb2.TestImageResult() rc = image_controller.SignerTest(input_proto, output_proto, self.mock_error_config) patch.assert_not_called() self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
def testMockCall(self): """Test that mock call does not execute any logic, returns mocked value.""" patch = self.PatchObject(image_lib, 'SecurityTest', return_value=True) input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path output_proto = image_pb2.TestImageResult() image_controller.SignerTest(input_proto, output_proto, self.mock_call_config) patch.assert_not_called() self.assertEqual(output_proto.success, True)
def testMockCall(self): """Test that mock call does not execute any logic, returns mocked value.""" patch = self.PatchObject(image_service, 'Test') input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path input_proto.build_target.name = self.board input_proto.result.directory = self.result_directory output_proto = image_pb2.TestImageResult() image_controller.Test(input_proto, output_proto, self.mock_call_config) patch.assert_not_called() self.assertEqual(output_proto.success, True)
def testValidateOnly(self): """Sanity check that a validate only call does not execute any logic.""" patch = self.PatchObject(image_service, 'Test') input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path input_proto.build_target.name = self.board input_proto.result.directory = self.result_directory output_proto = image_pb2.TestImageResult() image_controller.Test(input_proto, output_proto, self.validate_only_config) patch.assert_not_called()
def testMockError(self): """Test that mock call does not execute any logic, returns error.""" patch = self.PatchObject(image_service, 'Test') input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path input_proto.build_target.name = self.board input_proto.result.directory = self.result_directory output_proto = image_pb2.TestImageResult() rc = image_controller.Test(input_proto, output_proto, self.mock_error_config) patch.assert_not_called() self.assertEqual(controller.RETURN_CODE_COMPLETED_UNSUCCESSFULLY, rc)
def testTestOutputHandling(self): """Test function output tests.""" input_proto = image_pb2.TestImageRequest() input_proto.image.path = self.image_path input_proto.build_target.name = self.board input_proto.result.directory = self.result_directory output_proto = image_pb2.TestImageResult() self.PatchObject(image_service, 'Test', return_value=True) image_controller.Test(input_proto, output_proto, self.api_config) self.assertTrue(output_proto.success) self.PatchObject(image_service, 'Test', return_value=False) image_controller.Test(input_proto, output_proto, self.api_config) self.assertFalse(output_proto.success)