Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mesemus committed Dec 17, 2023
1 parent 53ba030 commit 6091408
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
12 changes: 10 additions & 2 deletions tests/test_requests/test_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from invenio_pidstore.errors import PIDDeletedError, PIDUnregistered
from invenio_pidstore.errors import PIDDeletedError, PIDUnregistered, PIDDoesNotExistError
from invenio_records_resources.services.errors import PermissionDeniedError
from sqlalchemy.orm.exc import NoResultFound

Expand All @@ -20,8 +20,16 @@ def test_workflow(
identity_simple, resp1._obj.parent.publish_draft.id, "submit"
)

with pytest.raises(NoResultFound):
try:
record_service.read_draft(identity_simple, record_id)
raise Exception("Expecting PIDDoesNotExistError for RDM 12 or NoResultFound for RDM 11")
except PIDDoesNotExistError:
# RDM 12 error
pass
except NoResultFound:
# RDM 11 error
pass

resp2 = record_service.read(identity_simple, record_id)
assert resp2._obj.parent.publish_draft is None

Expand Down
10 changes: 8 additions & 2 deletions tests/test_ui/templates/TestDetail.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{#def extra_context #}
available_requests=
{
{% for request_name, request in extra_context.allowed_requests.items() %}
{{ request_name }}: {{ request }}
"{{ request_name }}": {
"type": {{ request.type|tojson|safe }},
"status": {{ request.status|tojson|safe }},
"receiver": {{ request.receiver|tojson|safe }},
"actions": {{ request.actions|tojson|safe }}
}
{% endfor %}
}
27 changes: 21 additions & 6 deletions tests/test_ui/templates/TestEdit.jinja
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
{#def form_config, extra_context #}
available_requests=
{
"available_requests":
{
{% for request_name, request in extra_context.allowed_requests.items() %}
{{ request_name }}: {{ request }}
"{{ request_name }}": {
"type": {{ request.type|tojson|safe }},
"status": {{ request.status|tojson|safe }},
"receiver": {{ request.receiver|tojson|safe }},
"actions": {{ request.actions|tojson|safe }}
}
{% endfor %}
{% if form_config %}
allowed requests in form config:
},

"form_config":
{
{% for request_name, request in form_config["allowed_requests"].items() %}
{{ request_name }}: {{ request }}
"{{ request_name }}": {
"type": {{ request.type|tojson|safe }},
"status": {{ request.status|tojson|safe }},
"receiver": {{ request.receiver|tojson|safe }},
"actions": {{ request.actions|tojson|safe }}
}
{% endfor %}
{% endif %}
}
}
21 changes: 12 additions & 9 deletions tests/test_ui/test_ui_resource.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import json


def test_draft_publish_request_present(
app, record_ui_resource, example_topic_draft, client_with_login, fake_manifest
):
Expand All @@ -10,9 +13,9 @@ def check_request(ctext):

with client_with_login.get(f"/thesis/{example_topic_draft['id']}/edit") as c:
assert c.status_code == 200
base_part, form_part = c.text.split("allowed requests in form config:")
check_request(base_part)
check_request(form_part)
data = json.loads(c.text)
assert data["available_requests"]["publish_draft"] == {'actions': ['submit', 'delete'], 'receiver': None, 'status': 'created', 'type': 'publish_draft'}
assert data["form_config"]["publish_draft"] == {'actions': ['submit', 'delete'], 'receiver': None, 'status': 'created', 'type': 'publish_draft'}


def test_draft_publish_unauthorized(
Expand All @@ -28,12 +31,12 @@ def test_record_delete_request_present(
):
with client_with_login.get(f"/thesis/{example_topic['id']}") as c:
assert c.status_code == 200
assert "delete_record: " in c.text
assert "'type': 'delete_record&#39" in c.text
assert "'receiver': None" in c.text
assert "'status': 'created'" in c.text
assert "'links': {}" in c.text
assert "'actions': ['submit']" in c.text
data = json.loads(c.text)
assert "delete_record" in data
assert data["delete_record"]['type'] == "delete_record"
assert data["delete_record"]["receiver"] is None
assert data["delete_record"]["status"] == "created"
assert data["delete_record"]["actions"] == ["submit", "delete"]


def test_record_delete_unauthorized(
Expand Down

0 comments on commit 6091408

Please sign in to comment.