Skip to content

Commit

Permalink
Update linear sort error messages (#1891)
Browse files Browse the repository at this point in the history
  • Loading branch information
reiterl authored Sep 5, 2023
1 parent f7bde0b commit 9ca701b
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 18 deletions.
8 changes: 6 additions & 2 deletions openslides_backend/action/mixins/linear_sort_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ def sort_linear(
valid_instance_ids = []
for id_ in nodes:
if id_ not in db_instances:
raise ActionException(f"Id {id_} not in db_instances.")
raise ActionException(
f"{self.model.collection} sorting failed, because element {self.model.collection}/{id_} doesn't exist."
)
valid_instance_ids.append(id_)
if len(valid_instance_ids) != len(db_instances):
raise ActionException("Additional db_instances found.")
raise ActionException(
f"{self.model.collection} sorting failed, because some elements were not included in the call."
)

weight = 1
for id_ in valid_instance_ids:
Expand Down
10 changes: 8 additions & 2 deletions tests/system/action/assignment_candidate/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ def test_sort_missing_model(self) -> None:
{"assignment_id": 222, "candidate_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Id 32 not in db_instances." in response.json["message"]
assert (
"assignment_candidate sorting failed, because element assignment_candidate/32 doesn't exist."
in response.json["message"]
)

def test_sort_another_section_db(self) -> None:
self.set_models(
Expand Down Expand Up @@ -148,7 +151,10 @@ def test_sort_another_section_db(self) -> None:
{"assignment_id": 222, "candidate_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Additional db_instances found." in response.json["message"]
assert (
"assignment_candidate sorting failed, because some elements were not included in the call."
in response.json["message"]
)

def test_create_no_permissions(self) -> None:
self.base_permission_test(
Expand Down
10 changes: 8 additions & 2 deletions tests/system/action/chat_group/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def test_sort_missing_model(self) -> None:
{"meeting_id": 222, "chat_group_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Id 32 not in db_instances." in response.json["message"]
assert (
"chat_group sorting failed, because element chat_group/32 doesn't exist."
in response.json["message"]
)

def test_sort_additional_chat_groups_in_meeting(self) -> None:
self.set_models(
Expand Down Expand Up @@ -118,7 +121,10 @@ def test_sort_additional_chat_groups_in_meeting(self) -> None:
{"meeting_id": 222, "chat_group_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Additional db_instances found." in response.json["message"]
assert (
"chat_group sorting failed, because some elements were not included in the call."
in response.json["message"]
)

def test_sort_no_permissions(self) -> None:
self.base_permission_test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ def test_sort_missing_model(self) -> None:
{"id": 222, "motion_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Id 32 not in db_instances." in response.json["message"]
assert (
"motion sorting failed, because element motion/32 doesn't exist."
in response.json["message"]
)

def test_sort_another_section_db(self) -> None:
self.set_models(
Expand All @@ -67,7 +70,10 @@ def test_sort_another_section_db(self) -> None:
{"id": 222, "motion_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Additional db_instances found." in response.json["message"]
assert (
"motion sorting failed, because some elements were not included in the call."
in response.json["message"]
)

def test_sort_no_permission(self) -> None:
self.base_permission_test(
Expand Down
10 changes: 8 additions & 2 deletions tests/system/action/motion_comment_section/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def test_sort_missing_model(self) -> None:
{"meeting_id": 222, "motion_comment_section_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Id 32 not in db_instances." in response.json["message"]
assert (
"motion_comment_section sorting failed, because element motion_comment_section/32 doesn't exist."
in response.json["message"]
)

def test_sort_another_section_db(self) -> None:
self.set_models(
Expand Down Expand Up @@ -91,7 +94,10 @@ def test_sort_another_section_db(self) -> None:
{"meeting_id": 222, "motion_comment_section_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Additional db_instances found." in response.json["message"]
assert (
"motion_comment_section sorting failed, because some elements were not included in the call."
in response.json["message"]
)

def test_sort_no_permissions(self) -> None:
self.base_permission_test(
Expand Down
10 changes: 8 additions & 2 deletions tests/system/action/motion_state/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def test_sort_extra_id_in_payload(self) -> None:
{"workflow_id": 1, "motion_state_ids": [3, 2, 4, 1]},
)
self.assert_status_code(response, 400)
assert "Id 4 not in db_instances." == response.json["message"]
assert (
"motion_state sorting failed, because element motion_state/4 doesn't exist."
== response.json["message"]
)

def test_sort_missing_id_in_payload(self) -> None:
self.set_models(self.permission_test_models)
Expand All @@ -47,7 +50,10 @@ def test_sort_missing_id_in_payload(self) -> None:
{"workflow_id": 1, "motion_state_ids": [3, 1]},
)
self.assert_status_code(response, 400)
assert "Additional db_instances found." == response.json["message"]
assert (
"motion_state sorting failed, because some elements were not included in the call."
== response.json["message"]
)

def test_sort_no_permissions(self) -> None:
self.base_permission_test(
Expand Down
10 changes: 8 additions & 2 deletions tests/system/action/motion_statute_paragraph/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def test_sort_missing_model(self) -> None:
{"meeting_id": 222, "statute_paragraph_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Id 32 not in db_instances." in response.json["message"]
assert (
"motion_statute_paragraph sorting failed, because element motion_statute_paragraph/32 doesn't exist."
in response.json["message"]
)

def test_sort_another_section_db(self) -> None:
self.set_models(
Expand Down Expand Up @@ -91,7 +94,10 @@ def test_sort_another_section_db(self) -> None:
{"meeting_id": 222, "statute_paragraph_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Additional db_instances found." in response.json["message"]
assert (
"motion_statute_paragraph sorting failed, because some elements were not included in the call."
in response.json["message"]
)

def test_sort_no_permissions(self) -> None:
self.base_permission_test(
Expand Down
10 changes: 8 additions & 2 deletions tests/system/action/motion_submitter/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def test_sort_missing_model(self) -> None:
{"motion_id": 222, "motion_submitter_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Id 32 not in db_instances." in response.json["message"]
assert (
"motion_submitter sorting failed, because element motion_submitter/32 doesn't exist."
in response.json["message"]
)

def test_sort_another_section_db(self) -> None:
self.set_models(
Expand All @@ -62,7 +65,10 @@ def test_sort_another_section_db(self) -> None:
{"motion_id": 222, "motion_submitter_ids": [32, 31]},
)
self.assert_status_code(response, 400)
assert "Additional db_instances found." in response.json["message"]
assert (
"motion_submitter sorting failed, because some elements were not included in the call."
in response.json["message"]
)

def test_sort_no_permissions(self) -> None:
self.base_permission_test(
Expand Down
10 changes: 8 additions & 2 deletions tests/system/action/speaker/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ def test_sort_missing_model(self) -> None:
"speaker.sort", {"list_of_speakers_id": 222, "speaker_ids": [32, 31]}
)
self.assert_status_code(response, 400)
assert "Id 32 not in db_instances." in response.json["message"]
assert (
"speaker sorting failed, because element speaker/32 doesn't exist."
in response.json["message"]
)

def test_sort_another_section_db(self) -> None:
self.set_models(
Expand All @@ -59,7 +62,10 @@ def test_sort_another_section_db(self) -> None:
"speaker.sort", {"list_of_speakers_id": 222, "speaker_ids": [32, 31]}
)
self.assert_status_code(response, 400)
assert "Additional db_instances found." in response.json["message"]
assert (
"speaker sorting failed, because some elements were not included in the call."
in response.json["message"]
)

def test_sort_no_permissions(self) -> None:
self.base_permission_test(
Expand Down

0 comments on commit 9ca701b

Please sign in to comment.