Skip to content

Commit

Permalink
create tests for account, archives and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
CharleyDL committed May 2, 2024
1 parent 3a56614 commit aa47c4e
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .github/workflows/aissyr_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,26 @@ jobs:
- name: Install dependencies
run: pip install -r requirements.txt

- name: Set up environment variables
shell: bash
env:
API_URL: ${{ secrets.API_URL }}
DB_HOST: ${{ secrets.DB_HOST }}
DB_PORT: ${{ secrets.DB_PORT }}
DB_NAME: ${{ secrets.DB_NAME }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
run: |
echo "API_URL=${API_URL}" >> .env
echo "DAGSHUB_REPO_OWNER=${DAGSHUB_REPO_OWNER}" >> .env
echo "DAGSHUB_REPO=${DAGSHUB_REPO}" >> .env
echo "DAGSHUB_USER_TOKEN=${DAGSHUB_USER_TOKEN}" >> .env
echo "MODEL_URI=${MODEL_URI}" >> .env
echo "DB_HOST=${DB_HOST}" >> .env
echo "DB_PORT=${DB_PORT}" >> .env
echo "DB_NAME=${DB_NAME}" >> .env
echo "DB_USERNAME=${DB_USERNAME}" >> .env
echo "DB_PASSWORD=${DB_PASSWORD}" >> .env
- name: Run tests with pytest
run: pytest tests
2 changes: 1 addition & 1 deletion routers/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def archive_classification():
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail='No archive for classification found')

return MessageAccount(result=True,
message="Archive classification found",
content=result)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import pytest
import sys

from fastapi.testclient import TestClient

## Add the current directory to the path
sys.path.append(".")
from api import app


class TestAPIAccount:

client = TestClient(app)
API_URL = os.getenv("API_URL")

@pytest.mark.parametrize("email, input_pwd, expected_result", [
("DEMO", "demotest", True),
("wrong@example.com", "badpass", False)
])
def test_verify_login(self, email, input_pwd, expected_result):
credentials = {
"email": email,
"input_pwd": input_pwd
}

response = self.client.post(
url=f"{self.API_URL}/account/verify_login/",
json=credentials
)

assert response.status_code == 200
assert response.json()["result"] == expected_result
36 changes: 36 additions & 0 deletions tests/test_archives.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import sys

from fastapi.testclient import TestClient

## Add the current directory to the path
sys.path.append(".")
from api import app


class TestArchiveClassification:

client = TestClient(app)
API_URL = os.getenv("API_URL")

def test_archive_classification_found(self):
response = self.client.get(url=f"{self.API_URL}/archives/classification/")

assert response.status_code == 200
assert response.json()["result"] == True
assert response.json()["message"] == "Archive classification found"
assert response.json()["content"] is not None


class TestArchiveLabelisation:

client = TestClient(app)
API_URL = os.getenv("API_URL")

def test_archive_labelisation_found(self):
response = self.client.get(url=f"{self.API_URL}/archives/labelisation/")

assert response.status_code == 200
assert response.json()["result"] == True
assert response.json()["message"] == "Archive labelisation found"
assert response.json()["content"] is not None
48 changes: 48 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ==============================================================================
# Created By : Charley ∆. Lebarbier
# Date Created : Thursday 2 May 2024
# ==============================================================================

import os
import sys

from fastapi.testclient import TestClient

## Add the current directory to the path
sys.path.append(".")
from api import app


class TestAPIResources:

client = TestClient(app)
API_URL = os.getenv("API_URL")

def test_all_glyphs(self):
response = self.client.get(url=f"{self.API_URL}/resources/glyphs/")

assert response.status_code == 200
assert isinstance(response.json(), dict)
assert len(response.json()) > 0 and len(response.json()) <= 907


def test_glyph_by_mzl(self):
mzl_number = 13
expected_response = {
"mzl_number": 13,
"glyph_name": "MUG@g",
"glyph": "𒈯",
"glyph_phonetic": [
"uttu₄",
"uṭu₄",
"zadim"
]
}

response = self.client.get(url=f"{self.API_URL}/resources/glyphs/{mzl_number}/")

assert response.status_code == 200
assert isinstance(response.json(), dict)
assert response.json() == expected_response

0 comments on commit aa47c4e

Please sign in to comment.