Skip to content

Commit

Permalink
added first test cases (#4)
Browse files Browse the repository at this point in the history
* added first test cases
  • Loading branch information
athalhammer authored Nov 8, 2024
1 parent 761bd28 commit e1e6f61
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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

3 changes: 3 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
httpx>=0.27.2
pytest>=8.3.3
rdflib>=7.1.1
Empty file added test/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions test/fasterid_test.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e1e6f61

Please sign in to comment.