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

Request response parameters #19

Merged
merged 40 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d750a54
initial method to accept request paramaters and body
sudeepkunhis Jan 13, 2025
55676f0
formatting changes
sudeepkunhis Jan 13, 2025
26ad0b2
Merge branch 'main' into request-response-parameters
sudeepkunhis Jan 13, 2025
adbe41b
Merge branch 'main' into request-response-parameters
sudeepkunhis Jan 13, 2025
37191a6
solved body error
sudeepkunhis Jan 13, 2025
2802da9
Merge branch 'request-response-parameters' of https://github.com/ONSd…
sudeepkunhis Jan 13, 2025
876a0b9
build docker image
sudeepkunhis Jan 15, 2025
2fc0782
test client fixture
sudeepkunhis Jan 15, 2025
5a68a92
basic post endpoint
sudeepkunhis Jan 15, 2025
f67a535
test post endpoint
sudeepkunhis Jan 15, 2025
7c287e8
logging configuration
sudeepkunhis Jan 21, 2025
aedae1b
formatting changes
sudeepkunhis Jan 21, 2025
abd6c85
return type in logging config
sudeepkunhis Jan 21, 2025
3cd4707
formatting changes
sudeepkunhis Jan 21, 2025
025257e
log level for local docker container
sudeepkunhis Jan 21, 2025
4aa49c7
review changes
sudeepkunhis Jan 22, 2025
cd00591
formatting changes
sudeepkunhis Jan 22, 2025
7df3a3f
removed hello world
sudeepkunhis Jan 22, 2025
347b2af
renamed post method
sudeepkunhis Jan 22, 2025
add83ff
Merge branch 'main' into request-response-parameters
sudeepkunhis Jan 22, 2025
c5b9fe8
docker compose changes
sudeepkunhis Jan 23, 2025
7fabedf
added docstrings
sudeepkunhis Jan 23, 2025
b682734
cleared ignore warnings
sudeepkunhis Jan 23, 2025
9ad7a56
init files
sudeepkunhis Jan 23, 2025
f7fcafb
stable version
sudeepkunhis Jan 23, 2025
a988033
make file changes
sudeepkunhis Jan 24, 2025
885b612
revert make file
sudeepkunhis Jan 24, 2025
b05a970
stable version
sudeepkunhis Jan 24, 2025
79641a5
review changes
sudeepkunhis Jan 27, 2025
926901d
moved tests folder and solved PYTHONPATH problem
sudeepkunhis Jan 28, 2025
1ae9b6c
removed D100 warning
sudeepkunhis Jan 28, 2025
1086eea
renamed working directory
sudeepkunhis Jan 30, 2025
b62824e
Update README.md
sudeepkunhis Jan 31, 2025
812852c
updated logging config
sudeepkunhis Jan 31, 2025
6af672a
unit tests for logging
sudeepkunhis Jan 31, 2025
8cb52fa
unit tests for logging
sudeepkunhis Jan 31, 2025
b9097a9
Update README.md
sudeepkunhis Jan 31, 2025
0b82b90
removed docker-compose and updated make commands
sudeepkunhis Jan 31, 2025
d71e5c1
Merge branch 'request-response-parameters' of https://github.com/ONSd…
sudeepkunhis Jan 31, 2025
567d550
removed app directory
sudeepkunhis Feb 3, 2025
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: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12.6
FROM python:3.12.6-slim

liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
WORKDIR /app

Expand All @@ -8,6 +8,8 @@ RUN pip install --no-cache-dir poetry==1.8.4 && \
poetry config virtualenvs.create false && \
poetry install --no-root --no-dev

COPY . /app
COPY eq_cir_converter_service/app eq_cir_converter_service/app

CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "5010"]
ENV PYTHONPATH=eq_cir_converter_service/app

CMD ["uvicorn", "eq_cir_converter_service.app.main:app", "--host", "0.0.0.0", "--port", "5010"]
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ lint: ## Run all linters (black/ruff/pylint/mypy).

.PHONY: test
test: ## Run the tests and check coverage.
poetry run pytest -n auto --cov=src --cov-report term-missing --cov-fail-under=100
export PYTHONPATH=eq_cir_converter_service/app && \
poetry run pytest -n auto --cov=eq_cir_converter_service/app ./eq_cir_converter_service/tests --cov-report term-missing --cov-fail-under=100

.PHONY: mypy
mypy: ## Run mypy.
poetry run mypy src
poetry run mypy eq_cir_converter_service

.PHONY: install
install: ## Install the dependencies excluding dev.
Expand All @@ -51,16 +52,17 @@ megalint: ## Run the mega-linter.

.PHONY: run
run: ## Start the local application.
poetry run uvicorn src.main:app --reload --port 5010
export PYTHONPATH=eq_cir_converter_service/app && \
poetry run uvicorn eq_cir_converter_service.app.main:app --reload --port 5010

.PHONY: docker-build
docker-build: ## Build the docker image.
docker build -t cir-converter-service .

.PHONY: docker-compose-up
docker-compose-up: ## Start the docker container using docker-compose.
docker-compose up -d
docker compose up --build -d

.PHONY: docker-compose-down
docker-compose-down: ## Stop the docker container using docker-compose.
docker-compose down
docker compose down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ services:
- "5010:5010"
volumes:
- .:/app
environment:
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
- LOG_LEVEL=DEBUG
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions eq_cir_converter_service/app/config/logging_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Configure the logging level for the application."""
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved

import logging
import os
from typing import Any


def get_log_level() -> Any:
berroar marked this conversation as resolved.
Show resolved Hide resolved
"""Get the logging level from the LOG_LEVEL environment variable, or use the default value of INFO."""
log_level = os.environ.get("LOG_LEVEL", "INFO")
return getattr(logging, log_level)


logging.basicConfig(
level=get_log_level(),
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
8 changes: 8 additions & 0 deletions eq_cir_converter_service/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""This module is the entry point of the FastAPI application."""

import fastapi
from routers import schema_router

app = fastapi.FastAPI()

app.include_router(schema_router.router)
File renamed without changes.
41 changes: 41 additions & 0 deletions eq_cir_converter_service/app/routers/schema_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""This module contains the FastAPI router for the schema conversion endpoint."""

from config.logging_config import logging
from fastapi import APIRouter

router = APIRouter()

logger = logging.getLogger(__name__)

"""The POST endpoint to convert the CIR schema from one version to another."""


@router.post(
"/schema",
response_model=dict,
)
async def convert_schema(
current_version: str,
target_version: str,
schema: dict,
) -> dict:
"""Convert the CIR schema from one version to another.

Request query parameters:
- current_version: The current version of the schema.
- target_version: The target version of the schema.

Request body:
- schema: The schema to convert.

Returns:
- dict: The converted schema.
"""
logger.info("Posting the cir schema...")

logger.debug("Received current version %s and target version %s", current_version, target_version)
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
logger.debug("Input body: %s", schema)

# TO DO: Implement the logic to convert the schema from one version to another

return schema
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions eq_cir_converter_service/tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Configuration for unit tests."""

from collections.abc import Generator

import app.main as app
import pytest
from fastapi.testclient import TestClient


@pytest.fixture
def test_client() -> Generator[TestClient, None, None]:
"""General client for hitting endpoints in tests."""
yield TestClient(app.app)
16 changes: 16 additions & 0 deletions eq_cir_converter_service/tests/unit/routers/test_schema_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""This module contains the unit tests for the schema router."""

from fastapi import status
from fastapi.testclient import TestClient

"""Test the schema router with valid JSON."""


def test_schema_router_with_valid_json(test_client: TestClient) -> None:
"""Test the post schema method with valid JSON."""
response = test_client.post(
"/schema?current_version=1&target_version=2",
json={"valid_json": "valid_json"},
)
assert response.status_code == status.HTTP_200_OK
assert response.json()["valid_json"] == "valid_json"
11 changes: 3 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,17 @@ select = [
]

ignore = [
# Conflicts with google docstring style
"D205",
# Allow missing docstring, remove to enforce docstrings across the board
"D100", "D101", "D102", "D103", "D104", "D105", "D106", "D107",
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
# Disable line length check as it is handled by black
# :TODO: Remove E501 when ruff supports all black rules
"D100", "D104",
# Remove E501 when ruff supports all black rules
"E501",
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
# indentation contains tabs
"W191",
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"eq_cir_converter_service/tests/*" = [
# Allow use of assert statements in tests
"S101",
]
Expand Down
9 changes: 0 additions & 9 deletions src/main.py

This file was deleted.

8 changes: 0 additions & 8 deletions tests/unit/conftest.py

This file was deleted.

12 changes: 0 additions & 12 deletions tests/unit/test_main.py

This file was deleted.

Loading