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

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
39 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
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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
poetry run pytest -vv -n auto --cov=src --cov-report term-missing --cov-fail-under=100
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: mypy
mypy: ## Run mypy.
Expand Down Expand Up @@ -59,7 +59,7 @@ docker-build: ## Build the docker image.

.PHONY: docker-compose-up
docker-compose-up: ## Start the docker container using docker-compose.
docker-compose up -d
docker-compose up --build -d
berroar marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: docker-compose-down
docker-compose-down: ## Stop the docker container using docker-compose.
Expand 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
15 changes: 15 additions & 0 deletions src/logging_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import logging
import os
from typing import Any


def get_log_level() -> Any:
"""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",
)
5 changes: 5 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import fastapi

from src.routers import schema_router

app = fastapi.FastAPI()


# Simple hello world endpoint
@app.get("/")
def index() -> dict:
return {"message": "Hello World!"}


app.include_router(schema_router.router)
25 changes: 25 additions & 0 deletions src/routers/schema_router.py
berroar marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from fastapi import APIRouter

from src.logging_config import logging

router = APIRouter()

logger = logging.getLogger(__name__)


# The POST endpoint to convert the CIR schema from one version to another
@router.post(
"/convert/schema",
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
response_model=dict,
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
)
async def post_schema(
current_version: str,
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
berroar marked this conversation as resolved.
Show resolved Hide resolved
target_version: str,
schema: dict,
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
) -> dict:
logger.info("Posting the cir schema...")
logger.debug(f"Input body: {{{schema}}}")
berroar marked this conversation as resolved.
Show resolved Hide resolved

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

return schema
15 changes: 9 additions & 6 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# import pytest
import pytest
from fastapi.testclient import TestClient


# @pytest.fixture()
# def calculator():
# # Create a new instance of the Calculator class for each test session.
# yield Calculator()
# # Clean up after the test session is complete.
@pytest.fixture
def test_client():
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
"""General client for hitting endpoints in tests."""
import src.main as app

test_client = TestClient(app.app)
yield test_client
18 changes: 18 additions & 0 deletions tests/unit/test_post_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from unittest import TestCase

import pytest
from fastapi import status


class PostSchemaTest(TestCase):
@pytest.fixture(autouse=True)
def prepare_fixture(self, test_client):
self.test_client = test_client

def test_post_schema_with_valid_json(self):
response = self.test_client.post(
"/convert/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"
liamtoozer marked this conversation as resolved.
Show resolved Hide resolved
Loading