StrictDoc Documentation
tests/end2end/screens/diff/01_view_basic_diff/test_case.py
Source file coverage
Path:
tests/end2end/screens/diff/01_view_basic_diff/test_case.py
Lines:
116
Non-empty lines:
102
Non-empty lines covered with requirements:
102 / 102 (100.0%)
Functions:
2
Functions covered by requirements:
2 / 2 (100.0%)
1
"""
2
@relation(SDOC-SRS-111, scope=file)
3
"""
4
 
5
import os
6
import subprocess
7
import tempfile
8
 
9
from tests.end2end.e2e_case import E2ECase
10
from tests.end2end.helpers.screens.diff.diff import Screen_Diff
11
from tests.end2end.helpers.screens.project_index.screen_project_index import (
12
    Screen_ProjectIndex,
13
)
14
from tests.end2end.server import SDocTestServer
15
 
16
path_to_this_test_file_folder = os.path.dirname(os.path.realpath(__file__))
17
 
18
 
19
class Test(E2ECase):
20
    def test(self):
21
        path_to_sdoc_config = os.path.join(
22
            path_to_this_test_file_folder, "strictdoc_config.py"
23
        )
24
        assert os.path.isfile(path_to_sdoc_config)
25
        path_to_sdoc_input = os.path.join(
26
            path_to_this_test_file_folder, "input.sdoc"
27
        )
28
        assert os.path.isfile(path_to_sdoc_input)
29
        path_to_sdoc_input_delta = os.path.join(
30
            path_to_this_test_file_folder, "input_delta.sdoc"
31
        )
32
        assert os.path.isfile(path_to_sdoc_input_delta)
33
 
34
        with tempfile.TemporaryDirectory() as path_to_temp_folder_:
35
            # It is important that realpath is used because macOS symlinks
36
            # /var → /private/var, so $TMPDIR is actually:
37
            # '/private/var/folders/sy/_sd67yzn5td5flr2_6vf73w40000gp/T/'.
38
            real_path_to_temp_folder = os.path.realpath(path_to_temp_folder_)
39
 
40
            subprocess.run(
41
                ["cp", path_to_sdoc_config, "."],
42
                check=True,
43
                cwd=real_path_to_temp_folder,
44
            )
45
            subprocess.run(
46
                ["cp", path_to_sdoc_input, "."],
47
                check=True,
48
                cwd=real_path_to_temp_folder,
49
            )
50
            subprocess.run(
51
                ["git", "init"], check=True, cwd=real_path_to_temp_folder
52
            )
53
            subprocess.run(
54
                'git config user.name "Your Name"'.split(" "),
55
                check=True,
56
                cwd=real_path_to_temp_folder,
57
            )
58
            subprocess.run(
59
                'git config user.email "you@example.com'.split(" "),
60
                check=True,
61
                cwd=real_path_to_temp_folder,
62
            )
63
            subprocess.run(
64
                ["git", "add", "."], check=True, cwd=real_path_to_temp_folder
65
            )
66
            subprocess.run(
67
                ["git", "commit", "-m", "Test commit #1"],
68
                check=True,
69
                cwd=real_path_to_temp_folder,
70
            )
71
 
72
            subprocess.run(
73
                ["cp", path_to_sdoc_input_delta, "input.sdoc"],
74
                check=True,
75
                cwd=real_path_to_temp_folder,
76
            )
77
            subprocess.run(
78
                ["git", "add", "."], check=True, cwd=real_path_to_temp_folder
79
            )
80
            subprocess.run(
81
                ["git", "commit", "-m", "Test commit #2"],
82
                check=True,
83
                cwd=real_path_to_temp_folder,
84
            )
85
 
86
            with SDocTestServer(
87
                input_path=real_path_to_temp_folder,
88
                cwd=real_path_to_temp_folder,
89
            ) as test_server:
90
                self.open(test_server.get_host_and_port())
91
 
92
                screen_project_index = Screen_ProjectIndex(self)
93
                screen_project_index.assert_on_screen()
94
                screen_project_index.assert_link_to_diff_screen_present()
95
 
96
                diff_screen: Screen_Diff = (
97
                    screen_project_index.do_click_on_diff_screen_link()
98
                )
99
                diff_screen.assert_on_screen("diff")
100
 
101
                diff_screen.do_enter_field_lhs("HEAD^")
102
                diff_screen.do_enter_field_rhs("HEAD")
103
                diff_screen.do_submit()
104
 
105
                self.assert_text("Test document")
106
                self.assert_text("Modified test document")
107
 
108
                diff_screen.do_switch_tab_to_changelog()
109
                diff_screen.assert_documents_modified("1")
110
                diff_screen.assert_nodes_modified("SECTION", "1 (1 modified)")
111
                diff_screen.assert_nodes_modified(
112
                    "TEXT", "No nodes were modified."
113
                )
114
                diff_screen.assert_nodes_modified(
115
                    "REQUIREMENT", "2 (1 modified, 1 added)"
116
                )