Skip to content

Commit

Permalink
Merge pull request #326 from Boavizta/dev
Browse files Browse the repository at this point in the history
Adding a route GET "/version"
  • Loading branch information
da-ekchajzer authored Oct 9, 2024
2 parents a554fdd + 8093bc1 commit 5b0194b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion boaviztapi/routers/utils_router.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import os

import pandas as pd
import toml
from fastapi import APIRouter, Query

from boaviztapi.dto.component.cpu import CPU
Expand All @@ -23,6 +23,12 @@
_ram_manuf = pd.read_csv(os.path.join(data_dir, 'crowdsourcing/ram_manufacture.csv'))



@utils_router.get('/version', description="Get the version of the API")
async def version():
return toml.loads(open(os.path.join(os.path.dirname(__file__), '../../pyproject.toml'), 'r').read())['tool']['poetry'][
'version']

@utils_router.get('/country_code', description=country_code)
async def utils_get_all_countries():
return get_available_countries()
Expand Down
15 changes: 15 additions & 0 deletions tests/api/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
from httpx import AsyncClient
import re

from boaviztapi.main import app

Expand Down Expand Up @@ -54,3 +55,17 @@ async def test_complete_cpu_from_name():
async with AsyncClient(app=app, base_url="http://test") as ac:
res = await ac.get('/v1/utils/name_to_cpu?cpu_name=deijeijdiejdzij')
assert res.json() == "CPU name deijeijdiejdzij is not found in our database"

@pytest.mark.asyncio
async def test_get_api_version_is_not_empty_string():
async with AsyncClient(app=app, base_url="http://test") as ac:
res = await ac.get('/v1/utils/version')
assert res.json()

# @pytest.mark.asyncio
# async def test_get_api_version_is_semver():
# async with AsyncClient(app=app, base_url="http://test") as ac:
# res = await ac.get('/v1/utils/version')
# # Check returned version matches semver regex
# # See https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
# assert re.match("^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$", res.json())

0 comments on commit 5b0194b

Please sign in to comment.