Skip to content

Commit

Permalink
finalizing pytest oarepo refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Krist committed Jan 21, 2025
1 parent 351f09e commit c68a0c5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 52 deletions.
4 changes: 2 additions & 2 deletions tests/test_requests/test_new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ def test_redirect_url(
new_draft = [
x
for x in draft_search
if x["parent"]["id"] == record1.json["parent"]["id"] and x["state"] == "draft"
if x["parent"]["id"] == record1["parent"]["id"] and x["state"] == "draft"
][0]
assert (
link2testclient(request["links"]["ui_redirect_url"], ui=True)
== f"/thesis/{new_draft['id']}/edit"
)

new_draft = creator_client.get(f"{urls['BASE_URL']}{new_draft['id']}/draft")
new_draft = creator_client.get(f"{urls['BASE_URL']}{new_draft['id']}/draft").json
publish_request = submit_request_on_draft(creator.identity, new_draft['id'], "publish_draft")
receiver_request = receiver_client.get(
f"{urls['BASE_URL_REQUESTS']}{publish_request['id']}"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_requests/test_param_interpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def _init(users, logged_client, draft_factory, submit_request, urls):
draft2 = draft_factory(user2.identity, custom_workflow="different_recipients")

submit_response_user1 = submit_request(
user1_client, draft1, "publish_draft"
user1.identity, draft1["id"], "publish_draft"
) # recipient should be 2
submit_response_user2 = submit_request(
user2_client, draft2, "another_topic_updating"
user2.identity, draft2["id"], "another_topic_updating"
) # should be 1

search_unfiltered = user2_client.get(urls["BASE_URL_REQUESTS"])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_requests/test_record_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_read_requests_on_record(
ThesisRecord.index.refresh()
ThesisDraft.index.refresh()
resp_request_submit = submit_request_on_record(
creator.identity, record1, "delete_published_record"
creator.identity, record1_id, "delete_published_record"
)
record = receiver_client.get(f"{urls['BASE_URL']}{record1_id}?expand=true")
decline = receiver_client.post(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_requests/test_topic_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def test_publish(
)
record = receiver_client.get(
f"{urls['BASE_URL']}{draft1_id}/draft?expand=true"
)
).json
publish = receiver_client.post(
link2testclient(
record.json["expanded"]["requests"][0]["links"]["actions"]["accept"]
record["expanded"]["requests"][0]["links"]["actions"]["accept"]
),
)
check_publish_topic_update(creator_client, urls, record, resp_request_submit)
60 changes: 32 additions & 28 deletions tests/test_requests/test_ui_serialialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def test_user_serialization(
draft_factory,
logged_client,
user_links,
create_request_on_record,
create_request_on_draft,
search_clear,
):
fallback_label = logged_client(users[0])
username_label = logged_client(users[1])
fullname_label = logged_client(users[2])
fallback_label = users[0]
username_label = users[1]
fullname_label = users[2]

fallback_label_client = logged_client(users[0])
username_label_client = logged_client(users[1])
Expand All @@ -44,23 +44,22 @@ def test_user_serialization(
ThesisRecord.index.refresh()
ThesisDraft.index.refresh()

resp_request_create = create_request_on_record(
resp_request_create = create_request_on_draft(
fallback_label.identity,
draft1_id,
"publish_draft",
headers={"Accept": "application/vnd.inveniordm.v1+json"},
"publish_draft"
)
resp_request_create_username = create_request_on_record(
resp_request_create = fallback_label_client.get(f"{urls['BASE_URL_REQUESTS']}{resp_request_create['id']}",
headers={"Accept": "application/vnd.inveniordm.v1+json"}).json
resp_request_create_username = create_request_on_draft(
username_label.identity,
draft2_id,
"publish_draft",
headers={"Accept": "application/vnd.inveniordm.v1+json"},
)
resp_request_create_fullname = create_request_on_record(
resp_request_create_fullname = create_request_on_draft(
fullname_label.identity,
draft3_id,
"publish_draft",
headers={"Accept": "application/vnd.inveniordm.v1+json"},
)

pprint(resp_request_create)
Expand Down Expand Up @@ -119,7 +118,7 @@ def test_user_serialization(
headers={"Accept": "application/vnd.inveniordm.v1+json"},
).json
ui_record_fullname = fullname_label_client.get(
f"{urls['BASE_URL']}{draft3._id}/draft?expand=true",
f"{urls['BASE_URL']}{draft3_id}/draft?expand=true",
headers={"Accept": "application/vnd.inveniordm.v1+json"},
).json

Expand All @@ -140,7 +139,7 @@ def test_resolver_fallback(
urls,
ui_serialization_result,
draft_factory,
create_request_on_record,
create_request_on_draft,
logged_client,
search_clear,
):
Expand All @@ -153,29 +152,32 @@ def test_resolver_fallback(
creator_client = logged_client(creator)

draft1 = draft_factory(creator.identity)
draft_id = draft1.json["id"]
draft_id = draft1["id"]
ThesisRecord.index.refresh()
ThesisDraft.index.refresh()

resp_request_create = create_request_on_record(
resp_request_create = create_request_on_draft(
creator.identity,
draft_id,
"publish_draft",
headers={"Accept": "application/vnd.inveniordm.v1+json"},
"publish_draft"
)
assert resp_request_create["stateful_name"] == "Submit for review"
request_id = resp_request_create['id']
ui_serialization_read = creator_client.get(f"{urls['BASE_URL_REQUESTS']}{request_id}",
headers={"Accept": "application/vnd.inveniordm.v1+json"}).json
assert ui_serialization_read["stateful_name"] == "Submit for review"
assert (
resp_request_create["stateful_description"]
ui_serialization_read["stateful_description"]
== "Submit for review. After submitting the draft for review, it will be locked and no further modifications will be possible."
)

resp_request_submit = creator_client.post(
link2testclient(resp_request_create["links"]["actions"]["submit"]),
headers={"Accept": "application/vnd.inveniordm.v1+json"},
link2testclient(resp_request_create["links"]["actions"]["submit"])
)
assert resp_request_submit.json["stateful_name"] == "Submitted for review"
ui_serialization_read_submitted = creator_client.get(f"{urls['BASE_URL_REQUESTS']}{request_id}",
headers={"Accept": "application/vnd.inveniordm.v1+json"}).json
assert ui_serialization_read_submitted["stateful_name"] == "Submitted for review"
assert (
resp_request_submit.json["stateful_description"]
ui_serialization_read_submitted["stateful_description"]
== "The draft has been submitted for review. It is now locked and no further changes are possible. You will be notified about the decision by email."
)

Expand Down Expand Up @@ -221,7 +223,7 @@ def test_role(
users,
role,
urls,
create_request_on_record,
create_request_on_draft,
logged_client,
role_ui_serialization,
draft_factory,
Expand All @@ -241,19 +243,21 @@ def current_receiver(record=None, request_type=None, **kwargs):
creator_client = logged_client(creator)

draft1 = draft_factory(creator.identity)
draft_id = draft1.json["id"]
draft_id = draft1["id"]
ThesisRecord.index.refresh()
ThesisDraft.index.refresh()

resp_request_create = create_request_on_record(
resp_request_create = create_request_on_draft(
creator.identity,
draft_id,
"publish_draft",
headers={"Accept": "application/vnd.inveniordm.v1+json"},
)
assert resp_request_create["stateful_name"] == "Submit for review"
ui_serialization_read = creator_client.get(f"{urls['BASE_URL_REQUESTS']}{resp_request_create['id']}",
headers={"Accept": "application/vnd.inveniordm.v1+json"}).json
assert ui_serialization_read["stateful_name"] == "Submit for review"
assert (
resp_request_create["stateful_description"]
ui_serialization_read["stateful_description"]
== "Submit for review. After submitting the draft for review, it will be locked and no further modifications will be possible."
)

Expand Down
36 changes: 19 additions & 17 deletions tests/test_requests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_publish_with_workflows(
users,
urls,
draft_factory,
create_request_on_record,
create_request_on_draft,
patch_requests_permissions,
record_service,
search_clear,
Expand All @@ -88,7 +88,7 @@ def test_publish_with_workflows(
create_non_owner = receiver_client.post(
f"{urls['BASE_URL']}{draft1_id}/draft/requests/publish_draft",
)
resp_request_create = create_request_on_record(
resp_request_create = create_request_on_draft(
creator.identity, draft1_id, "publish_draft"
)
assert create_non_owner.status_code == 403
Expand Down Expand Up @@ -143,7 +143,7 @@ def test_autorequest(
receiver_client = logged_client(receiver)

draft1 = draft_factory(creator.identity, custom_workflow="with_approve")
record_id = draft1.json["id"]
record_id = draft1["id"]

approve_request_data = {
"request_type": "approve_draft",
Expand Down Expand Up @@ -190,11 +190,11 @@ def test_if_no_new_version_draft(
record = record_factory(creator.identity)
record2 = record_factory(creator.identity)
record_id = record["id"]
record2_id = record["id"]
record2_id = record2["id"]

record = creator_client.get(
f"{urls['BASE_URL']}{record_id}?expand=true",
)
).json
requests = record["expanded"]["request_types"]
assert "new_version" in {r["type_id"] for r in requests}

Expand All @@ -206,25 +206,27 @@ def test_if_no_new_version_draft(
assert request["status"] == "accepted"
record = creator_client.get(
f"{urls['BASE_URL']}{record_id}?expand=true",
)
).json
requests = record["expanded"]["request_types"]
assert "new_version" not in {
r["type_id"] for r in requests
} # new version created, requests should not be available again

resp_request_submit = submit_request_on_record(
creator.identity, record2_id, "edit_published_record"
)
request = creator_client.get(
f'{urls["BASE_URL_REQUESTS"]}{resp_request_submit["id"]}',
).json # request is autoaccepted
assert request["status"] == "accepted"

record = creator_client.get(
f"{urls['BASE_URL']}{record2_id}?expand=true",
)
).json
requests = record["expanded"]["request_types"]
assert "new_version" in {
r["type_id"] for r in requests
} # new version created, requests should not be available again
}


def test_if_no_edit_draft(
Expand All @@ -241,8 +243,8 @@ def test_if_no_edit_draft(

record = record_factory(creator.identity)
record2 = record_factory(creator.identity)
id_ = record.json["id"]
id2_ = record2.json["id"]
id_ = record["id"]
id2_ = record2["id"]

record = creator_client.get(
f"{urls['BASE_URL']}{id_}?expand=true",
Expand Down Expand Up @@ -303,7 +305,7 @@ def test_workflow_events(
user1_client = logged_client(user1)
user2_client = logged_client(user2)

draft1 = draft_factory(user1_client, custom_workflow="with_approve")
draft1 = draft_factory(user1.identity, custom_workflow="with_approve")
record_id = draft1["id"]

resp_request_submit = submit_request_on_draft(user1.identity, record_id, "approve_draft")
Expand Down Expand Up @@ -341,7 +343,7 @@ def test_workflow_events(
assert publishing_record["state"] == "publishing"

read_from_record = user2_client.get(
f"{urls['BASE_URL']}{draft1.json['id']}/draft?expand=true",
f"{urls['BASE_URL']}{record_id}/draft?expand=true",
)
publish_request = [
request
Expand Down Expand Up @@ -386,8 +388,8 @@ def test_workflow_events_resource(
user1_client = logged_client(user1)
user2_client = logged_client(user2)

draft1 = draft_factory(user1_client, custom_workflow="with_approve")
record_id = draft1.json["id"]
draft1 = draft_factory(user1.identity, custom_workflow="with_approve")
record_id = draft1["id"]

resp_request_submit = submit_request_on_draft(user1.identity, record_id, "approve_draft")

Expand Down Expand Up @@ -422,7 +424,7 @@ def test_workflow_events_resource(
assert publishing_record["state"] == "publishing"

read_from_record = user2_client.get(
f"{urls['BASE_URL']}{draft1.json['id']}/draft?expand=true",
f"{urls['BASE_URL']}{record_id}/draft?expand=true",
)
publish_request = [
request
Expand Down Expand Up @@ -458,7 +460,7 @@ def test_delete_log(
receiver_client = logged_client(receiver)

record = record_factory(creator.identity)
record_id = record.json["id"]
record_id = record["id"]

record_response = creator_client.get(
f"{urls['BASE_URL']}{record_id}?expand=true",
Expand Down Expand Up @@ -530,6 +532,6 @@ def test_cancel_transition(
)

record = creator_client.get(
f"{urls['BASE_URL']}{draft1.json['id']}/draft?expand=true"
f"{urls['BASE_URL']}{draft_id}/draft?expand=true"
)
assert record.json["state"] == "draft"

0 comments on commit c68a0c5

Please sign in to comment.