Build API: Add mock-call functionality.

The core functionality for making mock calls to the API.
Support added for success, error, and invalid responses.
Allows consumers to test their implementations against the
potentially branched API without needing to run the full
endpoint.

BUG=chromium:999178
TEST=run_tests

Change-Id: I5de9c37f8a759c175627b6db5e9696533aada031
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1787836
Tested-by: Alex Klein <saklein@chromium.org>
Commit-Queue: Alex Klein <saklein@chromium.org>
Reviewed-by: Evan Hernandez <evanhernandez@chromium.org>
Reviewed-by: David Burger <dburger@chromium.org>
diff --git a/api/api_config.py b/api/api_config.py
index 117f69b..6880391 100644
--- a/api/api_config.py
+++ b/api/api_config.py
@@ -3,14 +3,33 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-"""API config object."""
+"""API config object and related helper functionality."""
 
 from __future__ import print_function
 
-import collections
 
+class ApiConfig(object):
+  """API Config class."""
 
-ApiConfig = collections.namedtuple('ApiConfig', ['validate_only'])
+  def __init__(self, validate_only=False, mock_call=False, mock_error=False):
+    assert [validate_only, mock_call, mock_error].count(True) <= 1
+    self.validate_only = validate_only
+    self.mock_call = mock_call
+    self.mock_error = mock_error
+    self._is_mock = self.mock_call or self.mock_error
+
+  def __eq__(self, other):
+    if self.__class__ is other.__class__:
+      return ((self.validate_only, self.mock_call, self.mock_error) ==
+              (other.validate_only, other.mock_call, other.mock_error))
+
+    return NotImplemented
+
+  __hash__ = NotImplemented
+
+  @property
+  def do_validation(self):
+    return not self._is_mock
 
 
 class ApiConfigMixin(object):
@@ -22,8 +41,20 @@
 
   @property
   def api_config(self):
-    return ApiConfig(validate_only=False)
+    return ApiConfig()
 
   @property
   def validate_only_config(self):
     return ApiConfig(validate_only=True)
+
+  @property
+  def no_validate_config(self):
+    return self.mock_call_config
+
+  @property
+  def mock_call_config(self):
+    return ApiConfig(mock_call=True)
+
+  @property
+  def mock_error_config(self):
+    return ApiConfig(mock_error=True)