From 7a2cb3dd8712bd2413ae3b39b2751074ad697fdd Mon Sep 17 00:00:00 2001 From: Saksham Date: Mon, 23 Sep 2024 16:31:22 +0200 Subject: [PATCH] tests: Fix tests for removing community flow --- invenio_rdm_records/services/errors.py | 2 +- tests/resources/test_resources_communities.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/invenio_rdm_records/services/errors.py b/invenio_rdm_records/services/errors.py index 5757c5d55..011460fcc 100644 --- a/invenio_rdm_records/services/errors.py +++ b/invenio_rdm_records/services/errors.py @@ -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." diff --git a/tests/resources/test_resources_communities.py b/tests/resources/test_resources_communities.py index 2913ddf9e..12e0021d2 100644 --- a/tests/resources/test_resources_communities.py +++ b/tests/resources/test_resources_communities.py @@ -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, ): @@ -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) @@ -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) - 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", @@ -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)