Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1297 from strictdoc-project/stan…
Browse files Browse the repository at this point in the history
…islaw/section_uid_must_be_unique

traceability_index: fix finding an existing node with a given UID
  • Loading branch information
stanislaw authored Sep 6, 2023
2 parents 5cecce4 + 75ff2b3 commit 933af85
Show file tree
Hide file tree
Showing 127 changed files with 305 additions and 24 deletions.
2 changes: 1 addition & 1 deletion strictdoc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from strictdoc.core.environment import SDocRuntimeEnvironment

__version__ = "0.0.44a6"
__version__ = "0.0.44a7"


environment = SDocRuntimeEnvironment(__file__)
42 changes: 22 additions & 20 deletions strictdoc/core/traceability_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,25 @@ def get_coverage_info(
def get_node_by_uid(self, uid):
return self._requirements_parents[uid].requirement

def find_node_by_uid_weak(
self, uid
) -> Union[Document, Section, Requirement, None]:
for document in self.document_tree.document_list:
document_iterator = DocumentCachingIterator(document)
for node in document_iterator.all_content():
if isinstance(node, Document):
if node.config.uid == uid:
return node
elif isinstance(node, Section):
if node.reserved_uid == uid:
return node
elif isinstance(node, Requirement):
if node.reserved_uid == uid:
return node
else:
raise NotImplementedError
return None

def get_section_by_uid_weak(self, uid):
if uid not in self._requirements_parents:
return None
Expand Down Expand Up @@ -555,27 +574,10 @@ def validate_can_create_uid(self, uid: str):

existing_node_with_uid: Union[
Document, Section, Requirement, None
] = None
] = self.find_node_by_uid_weak(uid)

for document in self.document_tree.document_list:
document_iterator = DocumentCachingIterator(document)
for node in document_iterator.all_content():
if isinstance(node, Document):
if node.config.uid == uid:
existing_node_with_uid = node
break
elif isinstance(node, Section):
if node.reserved_uid == uid:
existing_node_with_uid = node
break
elif isinstance(node, Requirement):
if node.reserved_uid == uid:
existing_node_with_uid = node
break
else:
raise NotImplementedError
else:
return
if existing_node_with_uid is None:
return

raise SingleValidationError(
"UID uniqueness validation error: "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from seleniumbase import BaseCase

from tests.end2end.e2e_case import E2ECase
from tests.end2end.end2end_test_setup import End2EndTestSetup
from tests.end2end.helpers.screens.document.form_edit_section import (
Form_EditSection,
Expand All @@ -10,7 +9,7 @@
from tests.end2end.server import SDocTestServer


class Test_UC03_G1_T01_SectionWithEmptyName(BaseCase):
class Test(E2ECase):
def test(self):
test_setup = End2EndTestSetup(path_to_test_file=__file__)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[DOCUMENT]
TITLE: Document 1

[FREETEXT]
Hello world!
[/FREETEXT]

[SECTION]
UID: SAME-UID
TITLE: Section 1

[FREETEXT]
Section 1 free text.
[/FREETEXT]

[/SECTION]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[DOCUMENT]
TITLE: Document 1

[FREETEXT]
Hello world!
[/FREETEXT]
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from tests.end2end.e2e_case import E2ECase
from tests.end2end.end2end_test_setup import End2EndTestSetup
from tests.end2end.helpers.screens.document.form_edit_section import (
Form_EditSection,
)
from tests.end2end.helpers.screens.project_index.screen_project_index import (
Screen_ProjectIndex,
)
from tests.end2end.server import SDocTestServer


class Test(E2ECase):
def test(self):
test_setup = End2EndTestSetup(path_to_test_file=__file__)

with SDocTestServer(
input_path=test_setup.path_to_sandbox
) as test_server:
self.open(test_server.get_host_and_port())

screen_project_index = Screen_ProjectIndex(self)

screen_project_index.assert_on_screen()
screen_project_index.assert_contains_document("Document 1")

screen_document = screen_project_index.do_click_on_first_document()

screen_document.assert_on_screen_document()
screen_document.assert_header_document_title("Document 1")

screen_document.assert_text("Hello world!")

root_node = screen_document.get_root_node()

root_node_menu = root_node.do_open_node_menu()

form_edit_section: Form_EditSection = (
root_node_menu.do_node_add_section_first()
)

form_edit_section.do_fill_in_title("Section 1")
form_edit_section.do_fill_in_text("Section 1 free text.")
form_edit_section.do_fill_in_uid("SAME-UID")
form_edit_section.do_form_submit()

created_section = screen_document.get_section()
created_section_menu = created_section.do_open_node_menu()

form_edit_section: Form_EditSection = (
created_section_menu.do_node_add_section_below()
)
form_edit_section.do_fill_in_title("Section 2")
form_edit_section.do_fill_in_text("Section 2 free text.")
form_edit_section.do_fill_in_uid("SAME-UID")

form_edit_section.do_form_submit_and_catch_error(
"The chosen UID must be unique. "
"There is another section 'Section 1' with a UID 'SAME-UID'."
)

assert test_setup.compare_sandbox_and_expected_output()
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[DOCUMENT]
TITLE: Document 1

[FREETEXT]
Hello world!
[/FREETEXT]

[SECTION]
UID: SAME-UID
TITLE: Section 1

[FREETEXT]
Section 1 free text.
[/FREETEXT]

[/SECTION]

[SECTION]
TITLE: Section 2

[FREETEXT]
Section 2 free text.
[/FREETEXT]

[/SECTION]
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[DOCUMENT]
TITLE: Document 1

[FREETEXT]
Hello world!
[/FREETEXT]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from tests.end2end.e2e_case import E2ECase
from tests.end2end.end2end_test_setup import End2EndTestSetup
from tests.end2end.helpers.screens.document.form_edit_section import (
Form_EditSection,
)
from tests.end2end.helpers.screens.project_index.screen_project_index import (
Screen_ProjectIndex,
)
from tests.end2end.server import SDocTestServer


class Test(E2ECase):
def test(self):
test_setup = End2EndTestSetup(path_to_test_file=__file__)

with SDocTestServer(
input_path=test_setup.path_to_sandbox
) as test_server:
self.open(test_server.get_host_and_port())

screen_project_index = Screen_ProjectIndex(self)

screen_project_index.assert_on_screen()
screen_project_index.assert_contains_document("Document 1")

screen_document = screen_project_index.do_click_on_first_document()

screen_document.assert_on_screen_document()
screen_document.assert_header_document_title("Document 1")

screen_document.assert_text("Hello world!")

root_node = screen_document.get_root_node()

root_node_menu = root_node.do_open_node_menu()

form_edit_section: Form_EditSection = (
root_node_menu.do_node_add_section_first()
)

form_edit_section.do_fill_in_title("Section 1")
form_edit_section.do_fill_in_text("Section 1 free text.")
form_edit_section.do_fill_in_uid("SAME-UID")
form_edit_section.do_form_submit()

created_section = screen_document.get_section()
created_section_menu = created_section.do_open_node_menu()

form_edit_section: Form_EditSection = (
created_section_menu.do_node_add_section_below()
)
form_edit_section.do_fill_in_title("Section 2")
form_edit_section.do_fill_in_text("Section 2 free text.")
form_edit_section.do_form_submit()

created_section = screen_document.get_section(node_order=2)
form_edit_section: Form_EditSection = (
created_section.do_open_form_edit_section()
)
form_edit_section.do_fill_in_uid("SAME-UID")
form_edit_section.do_form_submit_and_catch_error(
"UID uniqueness validation error: "
"There is already an existing node with this UID: Section 1."
)

assert test_setup.compare_sandbox_and_expected_output()
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[DOCUMENT]
TITLE: Document 1

[FREETEXT]
Hello world!
[/FREETEXT]

[SECTION]
UID: DUPLICATE_UID
TITLE: First section

[FREETEXT]
This is a free text of this section.
[/FREETEXT]

[/SECTION]

[SECTION]
TITLE: Second section

[FREETEXT]
This is a free text of this section.
[/FREETEXT]

[/SECTION]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[DOCUMENT]
TITLE: Document 1

[FREETEXT]
Hello world!
[/FREETEXT]

[SECTION]
TITLE: First section

[FREETEXT]
This is a free text of this section.
[/FREETEXT]

[/SECTION]

[SECTION]
TITLE: Second section

[FREETEXT]
This is a free text of this section.
[/FREETEXT]

[/SECTION]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from seleniumbase import BaseCase

from tests.end2end.end2end_test_setup import End2EndTestSetup
from tests.end2end.helpers.screens.document.form_edit_section import (
Form_EditSection,
)
from tests.end2end.helpers.screens.project_index.screen_project_index import (
Screen_ProjectIndex,
)
from tests.end2end.server import SDocTestServer


class Test(BaseCase):
def test(self):
test_setup = End2EndTestSetup(path_to_test_file=__file__)

with SDocTestServer(
input_path=test_setup.path_to_sandbox
) as test_server:
self.open(test_server.get_host_and_port())

screen_project_index = Screen_ProjectIndex(self)

screen_project_index.assert_on_screen()
screen_project_index.assert_contains_document("Document 1")

screen_document = screen_project_index.do_click_on_first_document()

screen_document.assert_on_screen_document()
screen_document.assert_header_document_title("Document 1")

screen_document.assert_text("Hello world!")

section = screen_document.get_section()
form_edit_section: Form_EditSection = (
section.do_open_form_edit_section()
)
form_edit_section.do_fill_in_uid("DUPLICATE_UID")
form_edit_section.do_form_submit()

section = screen_document.get_section(node_order=2)
form_edit_section: Form_EditSection = (
section.do_open_form_edit_section()
)
form_edit_section.do_fill_in_uid("DUPLICATE_UID")
form_edit_section.do_form_submit_and_catch_error(
"UID uniqueness validation error: "
"There is already an existing node with this UID: First section."
)

assert test_setup.compare_sandbox_and_expected_output()

0 comments on commit 933af85

Please sign in to comment.