Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a route GET "/version" #326

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Loading