|
1 | | -import unittest |
2 | | - |
3 | | -from cfa.scenarios.dataops.datasets.config_validator import ( |
4 | | - validate_dataset_config, |
5 | | - verify_no_repeats, |
6 | | -) |
7 | | - |
8 | | -good_config = { |
9 | | - "properties": { |
10 | | - "name": "test_dataset_name", |
11 | | - "automate": False, |
12 | | - "transform_template": "test_tf.sql", |
13 | | - "schema": "datasets/schemas/tests.py", |
14 | | - }, |
15 | | - "source": {"url": "https://data.csv", "pagination": {"limit": 1000}}, |
16 | | - "extract": { |
17 | | - "account": "test_account_raw", |
18 | | - "container": "test_container_raw", |
19 | | - "prefix": "dataops/scenarios/raw/test", |
20 | | - }, |
21 | | - "load": { |
22 | | - "account": "test_account_tf", |
23 | | - "container": "test_container_tf", |
24 | | - "prefix": "dataops/scenarios/transformed/test", |
25 | | - }, |
26 | | - "_metadata": {"filename": "test_filename"}, |
27 | | -} |
28 | | -bad_config = { |
29 | | - "properties": { |
30 | | - "name": "test_dataset_name", |
31 | | - "automate": False, |
32 | | - "transform_template": "test_tf.sql", |
33 | | - "schema": "datasets/schemas/tests.py", |
34 | | - }, |
35 | | - "source": {"url": "https://data.csv", "pagination": {"limit": 1000}}, |
36 | | - "extract": { |
37 | | - "account": "test_account_raw", |
38 | | - "container": "test_container_raw", |
39 | | - }, |
40 | | - "load": { |
41 | | - "account": "test_account_tf", |
42 | | - "container": "test_container_tf", |
43 | | - }, |
44 | | - "_metadata": {"filename": "test_filename"}, |
45 | | -} |
46 | | - |
47 | | - |
48 | | -class TestConfigVal(unittest.TestCase): |
49 | | - def test_validate_dataset_config(self): |
50 | | - self.assertEqual(validate_dataset_config(good_config), None) |
51 | | - |
52 | | - def test_bad_validate_dataset_config(self): |
53 | | - with self.assertRaises(KeyError): |
54 | | - validate_dataset_config(bad_config) |
55 | | - |
56 | | - |
57 | | -class TestVerifyNoRepeats(unittest.TestCase): |
58 | | - def test_verify_no_repeats_no_duplicates(self): |
59 | | - configs = [ |
60 | | - { |
61 | | - "properties": {"name": "dataset_one"}, |
62 | | - "_metadata": {"filename": "file1.toml"}, |
63 | | - }, |
64 | | - { |
65 | | - "properties": {"name": "dataset_two"}, |
66 | | - "_metadata": {"filename": "file2.toml"}, |
67 | | - }, |
68 | | - ] |
69 | | - # Should not raise |
70 | | - self.assertIsNone(verify_no_repeats(configs)) |
71 | | - |
72 | | - def test_verify_no_repeats_with_duplicates(self): |
73 | | - configs = [ |
74 | | - { |
75 | | - "properties": {"name": "dataset_one"}, |
76 | | - "_metadata": {"filename": "file1.toml"}, |
77 | | - }, |
78 | | - { |
79 | | - "properties": {"name": "dataset_one"}, |
80 | | - "_metadata": {"filename": "file2.toml"}, |
81 | | - }, |
82 | | - ] |
83 | | - with self.assertRaises(AttributeError) as exc: |
84 | | - verify_no_repeats(configs) |
85 | | - assert "dataset_one" in str(exc.exception) |
86 | | - assert "file1.toml" in str(exc.exception) |
87 | | - assert "file2.toml" in str(exc.exception) |
| 1 | +import unittest |
| 2 | + |
| 3 | +from cfa.scenarios.dataops.datasets.config_validator import ( |
| 4 | + validate_dataset_config, |
| 5 | + verify_no_repeats, |
| 6 | +) |
| 7 | + |
| 8 | +good_config = { |
| 9 | + "properties": { |
| 10 | + "name": "test_dataset_name", |
| 11 | + "automate": False, |
| 12 | + "transform_template": "test_tf.sql", |
| 13 | + "schema": "datasets/schemas/tests.py", |
| 14 | + }, |
| 15 | + "source": {"url": "https://data.csv", "pagination": {"limit": 1000}}, |
| 16 | + "extract": { |
| 17 | + "account": "test_account_raw", |
| 18 | + "container": "test_container_raw", |
| 19 | + "prefix": "dataops/scenarios/raw/test", |
| 20 | + }, |
| 21 | + "load": { |
| 22 | + "account": "test_account_tf", |
| 23 | + "container": "test_container_tf", |
| 24 | + "prefix": "dataops/scenarios/transformed/test", |
| 25 | + }, |
| 26 | + "_metadata": {"filename": "test_filename"}, |
| 27 | +} |
| 28 | +bad_config = { |
| 29 | + "properties": { |
| 30 | + "name": "test_dataset_name", |
| 31 | + "automate": False, |
| 32 | + "transform_template": "test_tf.sql", |
| 33 | + "schema": "datasets/schemas/tests.py", |
| 34 | + }, |
| 35 | + "source": {"url": "https://data.csv", "pagination": {"limit": 1000}}, |
| 36 | + "extract": { |
| 37 | + "account": "test_account_raw", |
| 38 | + "container": "test_container_raw", |
| 39 | + }, |
| 40 | + "load": { |
| 41 | + "account": "test_account_tf", |
| 42 | + "container": "test_container_tf", |
| 43 | + }, |
| 44 | + "_metadata": {"filename": "test_filename"}, |
| 45 | +} |
| 46 | + |
| 47 | + |
| 48 | +class TestConfigVal(unittest.TestCase): |
| 49 | + def test_validate_dataset_config(self): |
| 50 | + self.assertEqual(validate_dataset_config(good_config), None) |
| 51 | + |
| 52 | + def test_bad_validate_dataset_config(self): |
| 53 | + with self.assertRaises(KeyError): |
| 54 | + validate_dataset_config(bad_config) |
| 55 | + |
| 56 | + |
| 57 | +class TestVerifyNoRepeats(unittest.TestCase): |
| 58 | + def test_verify_no_repeats_no_duplicates(self): |
| 59 | + configs = [ |
| 60 | + { |
| 61 | + "properties": {"name": "dataset_one"}, |
| 62 | + "_metadata": {"filename": "file1.toml"}, |
| 63 | + }, |
| 64 | + { |
| 65 | + "properties": {"name": "dataset_two"}, |
| 66 | + "_metadata": {"filename": "file2.toml"}, |
| 67 | + }, |
| 68 | + ] |
| 69 | + # Should not raise |
| 70 | + self.assertIsNone(verify_no_repeats(configs)) |
| 71 | + |
| 72 | + def test_verify_no_repeats_with_duplicates(self): |
| 73 | + configs = [ |
| 74 | + { |
| 75 | + "properties": {"name": "dataset_one"}, |
| 76 | + "_metadata": {"filename": "file1.toml"}, |
| 77 | + }, |
| 78 | + { |
| 79 | + "properties": {"name": "dataset_one"}, |
| 80 | + "_metadata": {"filename": "file2.toml"}, |
| 81 | + }, |
| 82 | + ] |
| 83 | + with self.assertRaises(AttributeError) as exc: |
| 84 | + verify_no_repeats(configs) |
| 85 | + assert "dataset_one" in str(exc.exception) |
| 86 | + assert "file1.toml" in str(exc.exception) |
| 87 | + assert "file2.toml" in str(exc.exception) |
0 commit comments