Skip to content

Commit

Permalink
tests: update the uploader of reviews
Browse files Browse the repository at this point in the history
* fixes the identity for open review policy (community owner gets auto accept)
  tests should be running with regular users
  • Loading branch information
kpsherva committed Jul 8, 2024
1 parent b5c08a0 commit 75104e8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 25 deletions.
4 changes: 2 additions & 2 deletions tests/services/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
79 changes: 56 additions & 23 deletions tests/services/test_service_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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


Expand Down

0 comments on commit 75104e8

Please sign in to comment.