-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
Copy pathtest_validate_mongocryptd.py
61 lines (45 loc) · 2.11 KB
/
test_validate_mongocryptd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Unit tests for the validate_mongocryptd script."""
from __future__ import absolute_import
import unittest
from mock import MagicMock, patch
from buildscripts import validate_mongocryptd as under_test
NS = "buildscripts.validate_mongocryptd"
def ns(relative_name): # pylint: disable=invalid-name
"""Return a full name from a name relative to the test module"s name space."""
return NS + "." + relative_name
class TestCanValidationBeSkipped(unittest.TestCase):
def test_non_existing_variant_can_be_skipped(self):
mock_evg_config = MagicMock()
mock_evg_config.get_variant.return_value = None
self.assertTrue(under_test.can_validation_be_skipped(mock_evg_config, "variant"))
def test_variant_with_no_push_task_can_be_skipped(self):
mock_evg_config = MagicMock()
mock_evg_config.get_variant.return_value.task_names = ["task 1", "task 2"]
self.assertTrue(under_test.can_validation_be_skipped(mock_evg_config, "variant"))
def test_variant_with_push_task_cannot_be_skipped(self):
mock_evg_config = MagicMock()
mock_evg_config.get_variant.return_value.task_names = ["task 1", "push", "task 2"]
self.assertFalse(under_test.can_validation_be_skipped(mock_evg_config, "variant"))
class TestReadVariableFromYml(unittest.TestCase):
@patch(ns("open"))
@patch(ns("yaml"))
def test_variable_not_in_variables(self, yaml_mock, _):
mock_nodes = {
"variables": {},
}
yaml_mock.safe_load.return_value = mock_nodes
self.assertIsNone(under_test.read_variable_from_yml("filename", "variable"))
@patch(ns("open"))
@patch(ns("yaml"))
def test_variable_is_in_variables(self, yaml_mock, _):
search_key = "var 2"
expected_value = "value 2"
mock_nodes = {
"variables": [
{"var 1": "value 1"},
{search_key: expected_value},
{"var 3": "value 3"},
],
}
yaml_mock.safe_load.return_value = mock_nodes
self.assertEqual(expected_value, under_test.read_variable_from_yml("filename", search_key))