Skip to content

Commit

Permalink
Make tag warn messages more precise
Browse files Browse the repository at this point in the history
  • Loading branch information
luisa-beerboom committed Dec 5, 2023
1 parent 6cfa8b1 commit 9f89ca8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
41 changes: 34 additions & 7 deletions openslides_backend/action/actions/motion/json_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ def validate_entry(self, entry: Dict[str, Any]) -> Dict[str, Any]:
[],
),
)
message_map["duplicate"] = (err_message, [*err_users, user])
message_map["duplicate"] = (
err_message,
list(set([*err_users, user])),
)
else:
username_set.add(user)
found_users = self.username_lookup.get(user, [])
Expand Down Expand Up @@ -360,13 +363,21 @@ def validate_entry(self, entry: Dict[str, Any]) -> Dict[str, Any]:

if tags := entry.get("tags"):
entry_list = []
message_set = set()
message_map = {}
tags_set: Set[str] = set()
for tag in tags:
if tag in tags_set:
entry_list.append({"value": tag, "info": ImportState.WARNING})
message_set.add(
"At least one tag has been referenced multiple times"
err_message, err_tags = message_map.get(
"duplicate",
(
"At least one tag has been referenced multiple times: ",
[],
),
)
message_map["duplicate"] = (
err_message,
list(set([*err_tags, tag])),
)
else:
tags_set.add(tag)
Expand All @@ -387,17 +398,33 @@ def validate_entry(self, entry: Dict[str, Any]) -> Dict[str, Any]:
"info": ImportState.WARNING,
}
)
message_set.add("Could not find at least one tag")
err_message, err_tags = message_map.get(
"not_found",
(
"Could not find at least one tag: ",
[],
),
)
message_map["not_found"] = (err_message, [*err_tags, tag])
else:
entry_list.append(
{
"value": tag,
"info": ImportState.WARNING,
}
)
message_set.add("Found multiple tags with the same name")
err_message, err_tags = message_map.get(
"multiple",
(
"Found multiple tags with the same name: ",
[],
),
)
message_map["multiple"] = (err_message, [*err_tags, tag])
entry["tags"] = entry_list
messages.extend([message for message in message_set])
messages.extend(
[message + ", ".join(tags) for message, tags in message_map.values()]
)

if (block := entry.get("block")) and isinstance(block, str):
found_blocks = self.block_lookup.get(block, [])
Expand Down
22 changes: 14 additions & 8 deletions tests/system/action/motion/test_json_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2961,7 +2961,7 @@ def assert_with_tags(
self.setup_assert_with_tags(meeting_id)
use_tags: List[str] = []
number_of_common_tags = 0
expected_not_found = 0
expected_not_found: List[str] = []
expect_duplicates = False
messages: List[str] = []
if common_tags:
Expand All @@ -2973,24 +2973,30 @@ def assert_with_tags(
use_tags.append("Got tag go")
if add_unidentifiable_tag:
use_tags.append("Tag-ether")
messages.append("Found multiple tags with the same name")
messages.append("Found multiple tags with the same name: Tag-ether")
if add_foreign_tag:
use_tags.append("rag-tag")
expected_not_found = 1
expected_not_found.append("rag-tag")
if add_unknown_tag:
use_tags.append("Not a tag")
expected_not_found += 1
expected_not_found.append("Not a tag")
if duplicates_in_row:
if number_of_common_tags:
use_tags.append("Tag-liatelle")
else:
number_of_common_tags = 1
use_tags = ["Tag-liatelle", *use_tags, "Tag-liatelle"]
expect_duplicates = True
messages.append("At least one tag has been referenced multiple times")
if expected_not_found:
messages.append("Could not find at least one tag")
has_warnings = add_unidentifiable_tag or expected_not_found or expect_duplicates
messages.append(
"At least one tag has been referenced multiple times: Tag-liatelle"
)
if len(expected_not_found):
messages.append(
"Could not find at least one tag: " + ", ".join(expected_not_found)
)
has_warnings = (
add_unidentifiable_tag or len(expected_not_found) or expect_duplicates
)
expected_data: List[Dict[str, Any]] = []
for i in range(len(use_tags)):
tag = use_tags[i]
Expand Down

0 comments on commit 9f89ca8

Please sign in to comment.