BuildAPI: Add unit tests and mocks for Image Service.

BUG=chromium:1000852
TEST=run_tests

Change-Id: I241e8587f5f776403dab522b9e89bf315a4a1ed2
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1925652
Reviewed-by: Alex Klein <saklein@chromium.org>
Tested-by: Michael Mortensen <mmortensen@google.com>
diff --git a/api/controller/image_unittest.py b/api/controller/image_unittest.py
index 75e71ec..6cce6c5 100644
--- a/api/controller/image_unittest.py
+++ b/api/controller/image_unittest.py
@@ -49,6 +49,15 @@
     image_controller.Create(request, self.response, self.validate_only_config)
     patch.assert_not_called()
 
+  def testMockCall(self):
+    """Test that mock call does not execute any logic, returns mocked value."""
+    patch = self.PatchObject(image_service, 'Build')
+
+    request = self._GetRequest(board='board')
+    image_controller.Create(request, self.response, self.mock_call_config)
+    patch.assert_not_called()
+    self.assertEqual(self.response.success, True)
+
   def testNoBoard(self):
     """Test no board given fails."""
     request = self._GetRequest()
@@ -149,6 +158,19 @@
 
     patch.assert_not_called()
 
+  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 testSignerTestNoImage(self):
     """Test function argument validation."""
     input_proto = image_pb2.TestImageRequest()
@@ -203,6 +225,20 @@
     image_controller.Test(input_proto, output_proto, self.validate_only_config)
     patch.assert_not_called()
 
+  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 testTestArgumentValidation(self):
     """Test function argument validation tests."""
     self.PatchObject(image_service, 'Test', return_value=True)