1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2024-11-18 04:17:03 +01:00
dspace-statistics-api/tests/test_api.py
Alan Orth 60e6ea57b1 tests/test_api.py: Use UUID
DSpace 6+ uses a UUID for item identifiers instead of an integer so
we need to adapt our tests accordingly. The Python UUID object must
be cast to a string to use it elsewhere in the code.
2020-03-02 11:10:41 +02:00

68 lines
1.8 KiB
Python

from falcon import testing
import json
import pytest
from dspace_statistics_api.app import api
@pytest.fixture
def client():
return testing.TestClient(api)
def test_get_docs(client):
"""Test requesting the documentation at the root."""
response = client.simulate_get("/")
assert isinstance(response.content, bytes)
assert response.status_code == 200
def test_get_item(client):
"""Test requesting a single item."""
response = client.simulate_get("/item/c3910974-c3a5-4053-9dce-104aa7bb1621")
response_doc = json.loads(response.text)
assert isinstance(response_doc["downloads"], int)
assert isinstance(response_doc["id"], str)
assert isinstance(response_doc["views"], int)
assert response.status_code == 200
def test_get_missing_item(client):
"""Test requesting a single non-existing item."""
response = client.simulate_get("/item/c3910974-c3a5-4053-9dce-104aa7bb1620")
assert response.status_code == 404
def test_get_items(client):
"""Test requesting 100 items."""
response = client.simulate_get("/items", query_string="limit=100")
response_doc = json.loads(response.text)
assert isinstance(response_doc["currentPage"], int)
assert isinstance(response_doc["totalPages"], int)
assert isinstance(response_doc["statistics"], list)
assert response.status_code == 200
def test_get_items_invalid_limit(client):
"""Test requesting 100 items with an invalid limit parameter."""
response = client.simulate_get("/items", query_string="limit=101")
assert response.status_code == 400
def test_get_items_invalid_page(client):
"""Test requesting 100 items with an invalid page parameter."""
response = client.simulate_get("/items", query_string="page=-1")
assert response.status_code == 400