From 75104e8943a9db73b8630d6fe594b7cc007a9c40 Mon Sep 17 00:00:00 2001 From: Karolina Przerwa Date: Mon, 8 Jul 2024 11:01:53 +0200 Subject: [PATCH] tests: update the uploader of reviews * fixes the identity for open review policy (community owner gets auto accept) tests should be running with regular users --- tests/services/conftest.py | 4 +- tests/services/test_service_review.py | 79 +++++++++++++++++++-------- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/tests/services/conftest.py b/tests/services/conftest.py index e63737075..7ef1b6052 100644 --- a/tests/services/conftest.py +++ b/tests/services/conftest.py @@ -36,7 +36,7 @@ def anyuser_identity(): @pytest.fixture(scope="function") def authenticated_identity(): """Authenticated identity fixture.""" - identity = Identity(1) - identity.provides.add(UserNeed(1)) + identity = Identity(100) + identity.provides.add(UserNeed(100)) identity.provides.add(authenticated_user) return identity diff --git a/tests/services/test_service_review.py b/tests/services/test_service_review.py index ed7f26424..44f13903a 100644 --- a/tests/services/test_service_review.py +++ b/tests/services/test_service_review.py @@ -92,6 +92,26 @@ def draft_for_open_review( return service.create(community_owner.identity, minimal_record) +@pytest.fixture() +def draft_for_open_review_user( + minimal_record, + open_review_community, + service, + uploader, + authenticated_identity, + db, +): + minimal_record["parent"] = { + "review": { + "type": CommunitySubmission.type_id, + "receiver": {"community": open_review_community.data["id"]}, + } + } + + # Create draft with review + return service.create(uploader.identity, minimal_record) + + @pytest.fixture() def draft_for_closed_review( minimal_record, closed_review_community, service, community_owner, db @@ -624,11 +644,12 @@ def test_review_gives_access_to_curator(running_app, draft, service, requests_se def test_review_submit_notification( - draft_for_open_review, + draft_for_open_review_user, running_app, open_review_community, curator, community_owner, + uploader, service, inviter, replace_notification_builder, @@ -648,25 +669,31 @@ def test_review_submit_notification( with mail.record_messages() as outbox: # Validate that email was sent req = service.review.submit( - community_owner.identity, draft_for_open_review.id + uploader.identity, draft_for_open_review_user.id ).to_dict() assert req["status"] == "submitted" # check notification is build on submit assert mock_build.called - assert len(outbox) == 1 + assert len(outbox) == 2 sent_mail = outbox[0] + sent_mail_2 = outbox[1] # TODO: update to `req["links"]["self_html"]` when addressing https://github.com/inveniosoftware/invenio-rdm-records/issues/1327 assert "/me/requests/{}".format(req["id"]) in sent_mail.html - assert community_owner.email not in sent_mail.recipients - assert curator.email in sent_mail.recipients + assert community_owner.email in sent_mail.recipients + assert ( + uploader.email not in sent_mail.recipients + and uploader.email not in sent_mail_2.recipients + ) + assert curator.email in sent_mail_2.recipients def test_review_accept_notification( - draft_for_open_review, + draft_for_open_review_user, running_app, open_review_community, curator, - community_owner, + uploader, + authenticated_identity, service, requests_service, inviter, @@ -685,7 +712,7 @@ def test_review_accept_notification( assert mail req = service.review.submit( - community_owner.identity, draft_for_open_review.id + uploader.identity, draft_for_open_review_user.id ).to_dict() with mail.record_messages() as outbox: @@ -699,15 +726,16 @@ def test_review_accept_notification( sent_mail = outbox[0] # TODO: update to `req["links"]["self_html"]` when addressing https://github.com/inveniosoftware/invenio-rdm-records/issues/1327 assert "/me/requests/{}".format(req["id"]) in sent_mail.html - assert community_owner.email in sent_mail.recipients + assert uploader.email in sent_mail.recipients assert curator.email not in sent_mail.recipients def test_review_cancel_notification( - draft_for_open_review, + draft_for_open_review_user, running_app, open_review_community, curator, + uploader, community_owner, service, requests_service, @@ -727,30 +755,35 @@ def test_review_cancel_notification( assert mail req = service.review.submit( - community_owner.identity, draft_for_open_review.id + uploader.identity, draft_for_open_review_user.id ).to_dict() with mail.record_messages() as outbox: # Validate that email was sent req = requests_service.execute_action( - community_owner.identity, req["id"], "cancel", {} + uploader.identity, req["id"], "cancel", {} ).to_dict() # check notification is build on submit assert mock_build.called - assert len(outbox) == 1 + assert len(outbox) == 2 sent_mail = outbox[0] + sent_mail_2 = outbox[1] # TODO: update to `req["links"]["self_html"]` when addressing https://github.com/inveniosoftware/invenio-rdm-records/issues/1327 assert "/me/requests/{}".format(req["id"]) in sent_mail.html - assert community_owner.email not in sent_mail.recipients - assert curator.email in sent_mail.recipients + assert ( + uploader.email not in sent_mail.recipients + and not uploader.email in sent_mail_2.recipients + ) + assert community_owner.email in sent_mail.recipients + assert curator.email in sent_mail_2.recipients def test_review_decline_notification( - draft_for_open_review, + draft_for_open_review_user, running_app, open_review_community, curator, - community_owner, + uploader, service, requests_service, inviter, @@ -769,7 +802,7 @@ def test_review_decline_notification( assert mail req = service.review.submit( - community_owner.identity, draft_for_open_review.id + uploader.identity, draft_for_open_review_user.id ).to_dict() with mail.record_messages() as outbox: @@ -783,16 +816,16 @@ def test_review_decline_notification( sent_mail = outbox[0] # TODO: update to `req["links"]["self_html"]` when addressing https://github.com/inveniosoftware/invenio-rdm-records/issues/1327 assert "/me/requests/{}".format(req["id"]) in sent_mail.html - assert community_owner.email in sent_mail.recipients + assert uploader.email in sent_mail.recipients assert curator.email not in sent_mail.recipients def test_review_expire_notification( - draft_for_open_review, + draft_for_open_review_user, running_app, open_review_community, curator, - community_owner, + uploader, service, requests_service, inviter, @@ -811,7 +844,7 @@ def test_review_expire_notification( assert mail req = service.review.submit( - community_owner.identity, draft_for_open_review.id + uploader.identity, draft_for_open_review_user.id ).to_dict() with mail.record_messages() as outbox: @@ -825,7 +858,7 @@ def test_review_expire_notification( sent_mail = outbox[0] # TODO: update to `req["links"]["self_html"]` when addressing https://github.com/inveniosoftware/invenio-rdm-records/issues/1327 assert "/me/requests/{}".format(req["id"]) in sent_mail.html - assert community_owner.email in sent_mail.recipients + assert uploader.email in sent_mail.recipients assert curator.email not in sent_mail.recipients