BuildAPI: Add unit tests and mocks for Android service.
BUG=chromium:1000844
TEST=run_tests
Change-Id: Id43111a4224e73ebd202aae687506bbfd9a94d25
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1930267
Reviewed-by: Alex Klein <saklein@chromium.org>
Tested-by: Michael Mortensen <mmortensen@google.com>
Commit-Queue: Michael Mortensen <mmortensen@google.com>
diff --git a/api/controller/android_unittest.py b/api/controller/android_unittest.py
index dee7b35..4e5d65c 100644
--- a/api/controller/android_unittest.py
+++ b/api/controller/android_unittest.py
@@ -44,6 +44,18 @@
self.validate_only_config)
self.uprev.assert_not_called()
+ def testMockCall(self):
+ """Test that a mock call does not execute logic, returns mocked value."""
+ android.MarkStable(self.input_proto, self.response,
+ self.mock_call_config)
+ self.uprev.assert_not_called()
+ self.assertEqual(self.response.status,
+ android_pb2.MARK_STABLE_STATUS_SUCCESS)
+ self.assertEqual(self.response.android_atom.category, 'category')
+ self.assertEqual(self.response.android_atom.package_name,
+ 'android-package-name')
+ self.assertEqual(self.response.android_atom.version, '1.2')
+
def testFailsIfTrackingBranchMissing(self):
"""Fails if tracking_branch is missing."""
self.input_proto.tracking_branch = ''
@@ -146,3 +158,11 @@
android.UnpinVersion(None, None, self.validate_only_config)
safeunlink.assert_not_called()
+
+ def testMockCall(self):
+ """Test that a mock call does not execute logic."""
+ safeunlink = self.PatchObject(osutils, 'SafeUnlink')
+
+ android.UnpinVersion(None, None, self.mock_call_config)
+ safeunlink.assert_not_called()
+ # android.UnpinVersion does not modify the response.