This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
test_e2e.py
64 lines (48 loc) · 2.72 KB
/
test_e2e.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
62
63
64
#!/usr/bin/env python
import subprocess
import unittest
import os
DEBUG_COMMAND_OUTPUT = False
class TestEndToEnd(unittest.TestCase):
@staticmethod
def remove_test_files():
_ = subprocess.run(["rm", "-f", "./tests/tmp/regions.xml"])
_ = subprocess.run(["rm", "-f", "./tests/tmp/regions-v3.xml"])
_ = subprocess.run(["rm", "-f", "./tests/tmp/regions.json"])
_ = subprocess.run(["rm", "-f", "./tests/tmp/regions-v3.json"])
def setUp(self) -> None:
self.remove_test_files()
return super().setUp()
def tearDown(self) -> None:
self.remove_test_files()
return super().tearDown()
@staticmethod
def read_file_as_string(file_path):
# Determine the directory of the current script (test_e2e.py)
current_script_directory = os.path.dirname(os.path.realpath(__file__))
# Construct an absolute path by combining the script directory with the relative file path
absolute_file_path = os.path.join(current_script_directory, file_path)
with open(absolute_file_path, 'r', encoding='utf-8') as file:
return file.read()
def test_update_regions_output(self):
command = ["python", "update_regions.py", "--input-file", "./tests/fixtures/server_directory.csv", "--output-dir", "./tests/tmp", "--pretty"]
out = subprocess.run(command, capture_output=True, text=True)
if DEBUG_COMMAND_OUTPUT:
print(f"stdout:\n{out.stdout}")
print(f"stderr:\n{out.stdout}")
print(out.stderr)
regions_xml_fixture = self.read_file_as_string('tests/fixtures/regions.xml')
regions_xml_output = self.read_file_as_string('tests/tmp/regions.xml')
self.assertEqual(regions_xml_fixture, regions_xml_output, "regions.xml should be identical")
regions_xml_v3_fixture = self.read_file_as_string('tests/fixtures/regions-v3.xml')
regions_xml_v3_output = self.read_file_as_string('tests/tmp/regions-v3.xml')
self.assertEqual(regions_xml_v3_fixture, regions_xml_v3_output, "regions-v3.xml should be identical")
regions_json_fixture = self.read_file_as_string('tests/fixtures/regions.json')
regions_json_output = self.read_file_as_string('tests/tmp/regions.json')
self.assertEqual(regions_json_fixture, regions_json_output, "regions.json should be identical")
regions_json_v3_fixture = self.read_file_as_string('tests/fixtures/regions-v3.json')
regions_json_v3_output = self.read_file_as_string('tests/tmp/regions-v3.json')
self.assertEqual(regions_json_v3_fixture, regions_json_v3_output, "regions-v3.json should be identical")
# This allows the test to be run from the command line
if __name__ == '__main__':
unittest.main()