Skip to content

Commit

Permalink
tests: Fix tests for removing community flow
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 committed Sep 23, 2024
1 parent c68f63b commit 7a2cb3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion invenio_rdm_records/services/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class CommunityNotSelectedError(Exception):
description = "Cannot publish without selecting a community."


class CannotRemoveCommunityError(PermissionDenied):
class CannotRemoveCommunityError(Exception):
"""Error thrown when the last community is being removed from the record."""

description = "Cannot remove. A record should be part of atleast 1 community."
14 changes: 9 additions & 5 deletions tests/resources/test_resources_communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ def test_add_record_to_community_submission_open_non_member(
def test_add_record_to_restricted_community_submission_open_non_member(
client,
uploader,
record_required_community,
record_community,
headers,
restricted_community,
):
Expand Down Expand Up @@ -988,7 +988,7 @@ def test_remove_last_community_api_error_handling(
):
"""Testing error message when trying to remove last community."""
record = record_required_community.create_record()
record_pid = record._record.pic_pid_value
record_pid = record._record.pid.pid_value
data = {"communities": [{"id": community.id}]}
for user in [uploader, curator]:
client = user.login(client)
Expand Down Expand Up @@ -1049,10 +1049,12 @@ def test_remove_record_last_community_with_multiple_communities(
] # one more in the rec fixture so it's 4
for com in comm:
_add_to_community(db, record, com)

Check failure on line 1051 in tests/resources/test_resources_communities.py

View workflow job for this annotation

GitHub Actions / Python / Tests (3.9, postgresql14, opensearch2)

test_remove_record_last_community_with_multiple_communities AttributeError: 'RecordItem' object has no attribute 'parent'

Check failure on line 1051 in tests/resources/test_resources_communities.py

View workflow job for this annotation

GitHub Actions / Python / Tests (3.12, postgresql14, opensearch2)

test_remove_record_last_community_with_multiple_communities AttributeError: 'RecordItem' object has no attribute 'parent'
assert len(record.parent.communities.ids) == 4
assert len(record._record.parent.communities.ids) == 4

with ensure_record_community_exists_config(app):
data = {"communities": [{"id": x} for x in record.parent.communities.ids]}
data = {
"communities": [{"id": x} for x in record._record.parent.communities.ids]
}

response = client.delete(
f"/records/{record_pid}/communities",
Expand All @@ -1070,7 +1072,9 @@ def test_remove_record_last_community_with_multiple_communities(
response = client.delete(
f"/records/{record_pid}/communities",
headers=headers,
json={"communities": [{"id": str(record.parent.communities.ids[0])}]},
json={
"communities": [{"id": str(record._record.parent.communities.ids[0])}]
},
)
assert response.status_code == 400
assert "error" in str(response.data)
Expand Down

0 comments on commit 7a2cb3d

Please sign in to comment.