-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtest_dot_utils_schema_improved.py
More file actions
107 lines (96 loc) · 3.78 KB
/
test_dot_utils_schema_improved.py
File metadata and controls
107 lines (96 loc) · 3.78 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
"""
Replicates tests in test_dot_utils.py adding the column id_column_name to the schema
"""
import uuid
import logging
from mock import patch
from .test_dot_utils import UtilsTest
# UT after base_self_test_class imports
from utils.utils import ( # pylint: disable=wrong-import-order
get_configured_tests_row,
get_test_rows,
setup_custom_logger,
)
class UtilsTestImproved(UtilsTest):
"""Test Class"""
def setUp(self) -> None:
self.create_self_tests_db_schema(
"\n".join(
[
"ALTER TABLE self_tests_dot.configured_tests "
"ADD COLUMN id_column_name VARCHAR(300) NULL;",
"UPDATE self_tests_dot.configured_tests "
"SET id_column_name = 'uuid';",
]
)
)
def tearDown(self) -> None:
self.drop_self_tests_db_schema()
@patch("utils.configuration_utils._get_filename_safely")
def test_get_configured_tests_row(
self, mock_get_filename_safely
): # pylint: disable=no-value-for-parameter
"""test yaml file creation for 1 core entity -see file in filename below"""
mock_get_filename_safely.side_effect = self.mock_get_filename_safely
configured_tests_row = get_configured_tests_row(
test_type="accepted_values",
entity_id="all_flight_data",
column="stops",
project_id="ScanProject1",
test_parameters='{"values": ["1", "2", "3", "Non-stop"]}',
)
expected_test_id = "cad13f73-27b5-3427-be8f-4d213bba3b19"
self.assertEqual(
expected_test_id,
configured_tests_row["test_id"],
f"difference in generated_test_id {configured_tests_row['test_id']} "
f"vs {expected_test_id} for possible_duplicate_forms test",
)
expected_row = {
"test_activated": True,
"project_id": "ScanProject1",
"test_id": expected_test_id,
"scenario_id": "INCONSISTENT-1",
"priority": 3,
"description": "Disallowed FP methods entered in form",
"impact": "",
"proposed_remediation": "",
"entity_id": "all_flight_data",
"test_type": "accepted_values",
"column_name": "stops",
"column_description": "",
"id_column_name": "uuid",
"test_parameters": "{'values': ['1', '2', '3', 'Non-stop']}",
"last_updated_by": "Matt",
}
for k, v in expected_row.items(): # pylint: disable=invalid-name
self.assertEqual(
str(v),
str(configured_tests_row.get(k)),
f"difference in {k}; {v} vs {configured_tests_row[k]}",
)
@patch("utils.configuration_utils._get_filename_safely")
def test_get_test_rows(
self, mock_get_filename_safely
): # pylint: disable=no-value-for-parameter
"""test get failing rows for custom test"""
mock_get_filename_safely.side_effect = self.mock_get_filename_safely
# create data for the test view that has failing rows
run_id = uuid.UUID("4541476c-814e-43fe-ab38-786f36beecbc")
self.prepare_failing_test_view()
# create data for the test view of failing rows
test_summary, run_id = self.get_test_summary(run_id)
test_rows = get_test_rows(
test_summary,
run_id,
project_id="ScanProject1",
logger=setup_custom_logger("self_tests/output/test.log", logging.INFO),
)
self.assertEqual(
len(test_rows.id_column_value.to_list()),
253,
)
self.assertEqual(
sorted(test_rows.id_column_value.to_list())[0],
"000ea267-ffb3-3a58-8e71-eaa3c6a0a81f",
)