Skip to content

Commit

Permalink
Merge pull request #18 from oarepo/links-tests
Browse files Browse the repository at this point in the history
Links tests
  • Loading branch information
SilvyPuzzlewell authored Sep 19, 2023
2 parents 81339ad + 906249c commit e799e17
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
5 changes: 4 additions & 1 deletion oarepo_model_builder_tests/datatypes/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def process_tests(self, datatype, section, **extra_kwargs):
"service_create_method": "create",
"service_delete_method": "delete",
"service_update_method": "update",
"deleted_record_pid_error" : "PIDDeletedError"
"deleted_record_pid_error" : "PIDDeletedError",
"links": {
"self": "https://{site_hostname}/api{BASE_URL}{pid_value}",
}
}


Expand Down
35 changes: 34 additions & 1 deletion oarepo_model_builder_tests/templates/test_resource.py.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,37 @@ def test_search({{ vars.tests.extra_fixtures|generate_list(end=true) }} client_w
assert len(res_created.json["hits"]["hits"]) == 10
assert len(res_created_fail.json["hits"]["hits"]) == 0
assert len(res_facets.json["hits"]["hits"]) == 1
{% endif %}
{% endif %}


def assert_expected_links(pid_value, generated_links, site_hostname="127.0.0.1:5000"):
"""Compare generated links to expected links."""
required_links = {
{% for link_name, link in test_constants.links.items() %}
"{{ link_name }}": f"{{ link }}",
{% endfor %}
}
assert required_links.items() <= generated_links.items()


def test_create_links(app, client_with_credentials, input_data):
res = client_with_credentials.post(BASE_URL, json=input_data)

pid_value = res.json["id"]
assert_expected_links(pid_value, res.json["links"])


def test_read_links(app, client_with_credentials, {{ fixtures.sample_record }}):
pid_value = {{ fixtures.sample_record }}['id']
res = client_with_credentials.get(f"{BASE_URL}{pid_value}{{ test_constants.read_url }}")

assert_expected_links(pid_value, res.json["links"])


def test_update_links(app, client_with_credentials, {{ fixtures.sample_record }}, sample_metadata_list):
pid_value = {{ fixtures.sample_record }}['id']
res = client_with_credentials.get(f"{BASE_URL}{pid_value}{{ test_constants.read_url }}")
res = client_with_credentials.put(f"{BASE_URL}{pid_value}{{ test_constants.update_url }}", json=sample_metadata_list[1])

assert res.status_code == 200
assert_expected_links(pid_value, res.json["links"])
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-model-builder-tests
version = 4.0.2
version = 4.0.3
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit e799e17

Please sign in to comment.