Skip to content

Commit

Permalink
[RSPEED-427] Add systems endpoint
Browse files Browse the repository at this point in the history
Add endpoint for returning RHEL systems start/end dates
  • Loading branch information
hosekadam committed Jan 15, 2025
1 parent 4d551b0 commit 5dab81d
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ repos:
rev: v0.7.0
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.1
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ test:
.PHONY: build
build:
docker build -t digital_roadmap:latest -f Containerfile .

.PHONY: tests
tests:
$(VENV_DIR)/bin/pytest
2 changes: 2 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi import APIRouter, FastAPI

from app.v1.lifecycle.router import v1_router as lifecycle_v1_router
from app.v1.released.endpoints import v1_router as released_v1_router
from app.v1.upcoming.endpoints import v1_router as upcoming_v1_router

Expand All @@ -12,6 +13,7 @@
# Include individual service routers under the main API router
api_router.include_router(released_v1_router, prefix="/v1/release-notes", tags=["release-notes"])
api_router.include_router(upcoming_v1_router, prefix="/v1/upcoming-changes", tags=["upcoming-changes"])
api_router.include_router(lifecycle_v1_router, prefix="/v1/lifecycle", tags=["lifecycle"])

# Include the main API router in the FastAPI app with the prefix
app.include_router(api_router, prefix="/api/digital-roadmap", tags=["digital-roadmap"])
Empty file added app/tests/lifecycle/__init__.py
Empty file.
Empty file.
43 changes: 43 additions & 0 deletions app/tests/lifecycle/systems/test_systems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest
from fastapi.testclient import TestClient

from app.main import app

client = TestClient(app)


@pytest.mark.parametrize(
("path", "response"),
(
(
"/8/3",
[
{
"name": "RHEL",
"major": 8,
"minor": 3,
"release_date": "2020-11-01",
"retirement_date": "2021-05-01",
"systems": 50,
}
],
),
(
"/9/0",
[
{
"name": "RHEL",
"major": 9,
"minor": 0,
"release_date": "2022-05-18",
"retirement_date": "2032-05-01",
"systems": 45,
}
],
),
("/9/20", []),
),
)
def test_system_specified(path, response):
data = client.get(f"/api/digital-roadmap/v1/lifecycle/systems{path}")
assert data.json() == response
Empty file added app/v1/lifecycle/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions app/v1/lifecycle/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import APIRouter

from app.v1.lifecycle.systems.endpoints import v1_router as systems_v1_router

v1_router = APIRouter()

v1_router.include_router(systems_v1_router, tags=["lifecycle"])
Empty file.
71 changes: 71 additions & 0 deletions app/v1/lifecycle/systems/endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from datetime import date

from fastapi import APIRouter

v1_router = APIRouter()

OS_DATA_MOCKED = [
{
"name": "RHEL",
"major": 9,
"minor": 2,
"release_date": date(2023, 5, 1),
"retirement_date": date(2023, 11, 1),
"systems": 5,
},
{
"name": "RHEL",
"major": 8,
"minor": 3,
"release_date": date(2020, 11, 1),
"retirement_date": date(2021, 5, 1),
"systems": 50,
},
{
"name": "RHEL",
"major": 8,
"minor": 7,
"release_date": date(2023, 5, 1),
"retirement_date": date(2023, 5, 1),
"systems": 12,
},
{
"name": "RHEL",
"major": 9,
"minor": 0,
"release_date": date(2022, 5, 18),
"retirement_date": date(2032, 5, 1),
"systems": 45,
},
]


@v1_router.get("/systems")
async def get_systems():
systems = get_systems_data()
return systems


@v1_router.get("/systems/{major}/{minor}")
async def get_systems_filtered_minor(major: int, minor: int):
systems = get_systems_data(major, minor)
return systems


@v1_router.get("/systems/{major}")
async def get_systems_filtered_major(major: int):
systems = get_systems_data(major)
return systems


def get_systems_data(major=None, minor=None):
data = OS_DATA_MOCKED

print(minor)

if major is not None:
data = [d for d in data if d["major"] == major]
if minor is not None:
data = [d for d in data if d["minor"] == minor]

return data

0 comments on commit 5dab81d

Please sign in to comment.