From e1e6f61bc9ac34c884dae818084c493b1944d8a6 Mon Sep 17 00:00:00 2001 From: Andreas Thalhammer Date: Fri, 8 Nov 2024 21:24:30 +0100 Subject: [PATCH] added first test cases (#4) * added first test cases --- .github/workflows/tests.yml | 21 +++++++++++++++++++++ requirements_dev.txt | 3 +++ test/__init__.py | 0 test/fasterid_test.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 requirements_dev.txt create mode 100644 test/__init__.py create mode 100644 test/fasterid_test.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..572d78b --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,21 @@ +name: fasterid + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10", "3.11", "3.12", "3.13"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: pip install -r requirements_dev.txt + - run: pip install -r requirements.txt + - run: pytest + diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..c715de8 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,3 @@ +httpx>=0.27.2 +pytest>=8.3.3 +rdflib>=7.1.1 diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/fasterid_test.py b/test/fasterid_test.py new file mode 100644 index 0000000..69d238d --- /dev/null +++ b/test/fasterid_test.py @@ -0,0 +1,28 @@ +from fasterid import app +from fastapi.testclient import TestClient +from rdflib import Graph + +client = TestClient(app) + +def test_basic(): + response = client.post("/") + assert response.status_code == 201 + assert isinstance(response.json(), dict) + assert "@id" in response.json().keys() + +def test_multiple(): + response = client.post("/", json={"number": 5}) + assert response.status_code == 201 + assert isinstance(response.json(), list) + assert len(response.json()) == 5 + +def test_content_negotiation(): + response = client.post("/", headers={'accept': 'application/ld+json'}) + assert response.status_code == 201 + assert response.headers["content-type"] == "application/ld+json" + +def test_json_ld(): + response = client.post("/", json={"number": 5}, headers={'accept': 'application/ld+json'}) + assert response.status_code == 201 + g = Graph().parse(data=response.content, format="json-ld") + assert len(g) == 5 \ No newline at end of file