Skip to content

Commit

Permalink
don't assume order of results
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanSoley committed Aug 29, 2024
1 parent 30dc2a0 commit 1cdbb47
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions tests/regression/test_repository_read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def test_read_regression(
def __test_additional_tags_and_comments(
tag_comment_dir, project_name, **entity_identification_kwargs
):
is_passing = True

add_tag_path = os.path.join(tag_comment_dir, f"tags_{uuid.uuid4()}.json")
with repository.filesystem.open(add_tag_path, "w") as file:
file.write(json.dumps({"added_tags": TAGS_TO_ADD}))
Expand All @@ -61,6 +63,16 @@ def __test_additional_tags_and_comments(
with repository.filesystem.open(remove_tag_path, "w") as file:
file.write(json.dumps({"removed_tags": TAGS_TO_REMOVE}))

additional_tags = repository.get_tags(
project_name,
**entity_identification_kwargs,
)
for tags in additional_tags:
if "added_tags" in tags:
is_passing &= tags["added_tags"] == TAGS_TO_ADD
if "removed_tags" in tags:
is_passing &= tags["removed_tags"] == TAGS_TO_REMOVE

add_comment_path = os.path.join(tag_comment_dir, f"comments_{uuid.uuid4()}.json")
with repository.filesystem.open(add_comment_path, "w") as file:
file.write(json.dumps({"added_comments": COMMENTS_TO_ADD}))
Expand All @@ -69,21 +81,17 @@ def __test_additional_tags_and_comments(
with repository.filesystem.open(remove_comment_path, "w") as file:
file.write(json.dumps({"removed_comments": COMMENTS_TO_REMOVE}))

additional_tags = repository.get_tags(
project_name,
**entity_identification_kwargs,
)
additional_comments = repository.get_comments(
project_name,
**entity_identification_kwargs,
)
for comments in additional_comments:
if "added_comments" in comments:
is_passing &= comments["added_comments"] == COMMENTS_TO_ADD
if "removed_tags" in comments:
is_passing &= comments["removed_comments"] == COMMENTS_TO_REMOVE

return (
additional_tags[0]["added_tags"] == TAGS_TO_ADD
and additional_tags[1]["removed_tags"] == TAGS_TO_REMOVE
and additional_comments[0]["added_comments"] == COMMENTS_TO_ADD
and additional_comments[1]["removed_comments"] == COMMENTS_TO_REMOVE
)
return is_passing

expected_project_dir = os.path.join(root_dir, slugify(project_json["name"]))
expected_project_path = os.path.join(expected_project_dir, "metadata.json")
Expand Down Expand Up @@ -379,6 +387,8 @@ def test_read_write_regression(
repository = repository_class(root_dir=root_dir)

def __test_additional_tags_and_comments(project_name, **entity_identification_kwargs):
is_passing = True

repository.add_tags(
project_name,
TAGS_TO_ADD,
Expand All @@ -393,6 +403,13 @@ def __test_additional_tags_and_comments(project_name, **entity_identification_kw
project_name,
**entity_identification_kwargs,
)

for tags in additional_tags:
if "added_tags" in tags:
is_passing &= tags["added_tags"] == TAGS_TO_ADD
if "removed_tags" in tags:
is_passing &= tags["removed_tags"] == TAGS_TO_REMOVE

repository.add_comments(
project_name,
COMMENTS_TO_ADD,
Expand All @@ -408,12 +425,13 @@ def __test_additional_tags_and_comments(project_name, **entity_identification_kw
**entity_identification_kwargs,
)

return (
additional_tags[0]["added_tags"] == TAGS_TO_ADD
and additional_tags[1]["removed_tags"] == TAGS_TO_REMOVE
and additional_comments[0]["added_comments"] == COMMENTS_TO_ADD
and additional_comments[1]["removed_comments"] == COMMENTS_TO_REMOVE
)
for comments in additional_comments:
if "added_comments" in comments:
is_passing &= comments["added_comments"] == COMMENTS_TO_ADD
if "removed_tags" in comments:
is_passing &= comments["removed_comments"] == COMMENTS_TO_REMOVE

return is_passing

repository.create_project(domain.Project(**project_json))
project = repository.get_project(project_json["name"]).__dict__
Expand Down

0 comments on commit 1cdbb47

Please sign in to comment.