blob: a616af913e41d8b93ab810e6450119e5f73e14fe [file] [log] [blame]
Alex Klein2008aee2019-08-20 16:25:27 -06001# -*- coding: utf-8 -*-
2# Copyright 2019 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""API Config unit tests."""
7
8from __future__ import print_function
9
10from chromite.api.api_config import ApiConfig
11from chromite.lib import cros_test_lib
12
13
14class ApiConfigTest(cros_test_lib.TestCase):
15 """ApiConfig tests."""
16
17 def test_incompatible_arguments(self):
18 """Test incompatible argument checks."""
19 # Can only specify True for one of validate_only, mock_call, and mock_error.
20 # Enumerating them was unnecessary, but it's only 4 cases.
21 with self.assertRaises(AssertionError):
22 ApiConfig(validate_only=True, mock_call=True)
23 with self.assertRaises(AssertionError):
24 ApiConfig(validate_only=True, mock_error=True)
25 with self.assertRaises(AssertionError):
26 ApiConfig(mock_call=True, mock_error=True)
27 with self.assertRaises(AssertionError):
28 ApiConfig(validate_only=True, mock_call=True, mock_error=True)
29
30 def test_do_validation(self):
31 """Sanity check for the do validation property being True."""
32 # Should validate by default, and when only doing validation.
33 config = ApiConfig()
34 self.assertTrue(config.do_validation)
35 config = ApiConfig(validate_only=True)
36 self.assertTrue(config.do_validation)
37
38 def test_no_do_validation(self):
39 """Sanity check for skipping validation for mock calls."""
40 config = ApiConfig(mock_call=True)
41 self.assertFalse(config.do_validation)
42 config = ApiConfig(mock_error=True)
43 self.assertFalse(config.do_validation)