test api build

This commit is contained in:
berkay 2025-02-15 17:26:21 +03:00
parent 240474a0d6
commit 97567209e1
11 changed files with 245 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -0,0 +1,35 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyInterpreterInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="21">
<item index="0" class="java.lang.String" itemvalue="rsa" />
<item index="1" class="java.lang.String" itemvalue="pydantic" />
<item index="2" class="java.lang.String" itemvalue="alembic" />
<item index="3" class="java.lang.String" itemvalue="starlette-context" />
<item index="4" class="java.lang.String" itemvalue="pymongo" />
<item index="5" class="java.lang.String" itemvalue="arrow" />
<item index="6" class="java.lang.String" itemvalue="unidecode" />
<item index="7" class="java.lang.String" itemvalue="python-dotenv" />
<item index="8" class="java.lang.String" itemvalue="psycopg2-binary" />
<item index="9" class="java.lang.String" itemvalue="cryptography" />
<item index="10" class="java.lang.String" itemvalue="requests" />
<item index="11" class="java.lang.String" itemvalue="redis" />
<item index="12" class="java.lang.String" itemvalue="sqlalchemy" />
<item index="13" class="java.lang.String" itemvalue="pandas" />
<item index="14" class="java.lang.String" itemvalue="fastapi" />
<item index="15" class="java.lang.String" itemvalue="Deprecated" />
<item index="16" class="java.lang.String" itemvalue="faker" />
<item index="17" class="java.lang.String" itemvalue="textdistance" />
<item index="18" class="java.lang.String" itemvalue="uvicorn" />
<item index="19" class="java.lang.String" itemvalue="redmail" />
<item index="20" class="java.lang.String" itemvalue="sqlalchemy-mixins" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.10 (data_manager)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (data_manager)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/test-dummy-api.iml" filepath="$PROJECT_DIR$/.idea/test-dummy-api.iml" />
</modules>
</component>
</project>

8
.idea/test-dummy-api.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.10 (data_manager)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

30
Dockerfile Normal file
View File

@ -0,0 +1,30 @@
FROM python:3.12-slim
WORKDIR /app
# Install system dependencies and Poetry
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/* \
&& pip install --no-cache-dir poetry
# Copy Poetry configuration
COPY /pyproject.toml ./pyproject.toml
# Configure Poetry and install dependencies with optimizations
RUN poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root --only main \
&& pip cache purge \
&& rm -rf ~/.cache/pypoetry
# Copy application code
COPY . .
# Set Python path to include app directory
ENV PYTHONPATH=/app \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Run the application using the configured uvicorn server
CMD ["poetry", "run", "python", "app.py"]

59
app.py Normal file
View File

@ -0,0 +1,59 @@
"""
FastAPI Application Entry Point
This module initializes and configures the FastAPI application with:
- CORS middleware for cross-origin requests
- Request timing middleware for performance monitoring
- Custom exception handlers for consistent error responses
- Prometheus instrumentation for metrics
- API routers for endpoint organization
"""
import uvicorn
from arrow import now
from fastapi import FastAPI
from fastapi.responses import JSONResponse, RedirectResponse
app = FastAPI(
title="Dummy api",
description="Api from test purposes",
default_response_class=JSONResponse,
) # Initialize FastAPI app
@app.get(path="/current/date", summary="Receive token via device id and encrypt data")
def receive_api_current_date():
"""
Output
* utc_string: str
* utc_float_timestamp: float
* utc_timezone: Optional[str]
* current_string: str
* current_float_timestamp: float
* current_timezone: Optional[str]
* source: str
* source_address: str
"""
return dict(
utc_string=str(now()),
utc_float_timestamp=now().float_timestamp,
utc_timezone=now().tzname(),
current_string=now().shift(hours=+3).__str__(),
current_float_timestamp=now().shift(hours=+3).float_timestamp,
current_timezone="GMT +3",
source="TITLE",
source_address="Ankara/Turkey",
)
if __name__ == "__main__":
# Run the application with Uvicorn
config_dict = dict(
app="app:app",
host = "0.0.0.0",
port = 8000,
log_level = "info",
reload = True,
)
uvicorn.Server(uvicorn.Config(**config_dict)).run()

7
docker-compose.yml Normal file
View File

@ -0,0 +1,7 @@
services:
dummy-api-service:
build:
context: .
ports:
- "8000:8000"

76
pyproject.toml Normal file
View File

@ -0,0 +1,76 @@
[tool.poetry]
name = "wag-management-api-services"
version = "0.1.0"
description = "WAG Management API Services"
authors = ["Karatay Berkay <karatay.berkay@evyos.com.tr>"]
[tool.poetry.dependencies]
python = "^3.12"
# FastAPI and Web
fastapi = "^0.104.1"
uvicorn = "^0.24.0"
pydantic = "^2.5.2"
# MongoDB
motor = "3.3.2" # Pinned version
pymongo = "4.5.0" # Pinned version to match motor
# PostgreSQL
sqlalchemy = "^2.0.23"
sqlalchemy-mixins = "^2.0.5"
psycopg2-binary = "^2.9.9"
# Redis
redis = "^5.0.1"
arrow = "^1.3.0"
# Email
redmail = "^0.6.0"
# Testing
pytest = "^7.4.3"
pytest-asyncio = "^0.21.1"
pytest-cov = "^4.1.0"
# Utilities
python-dateutil = "^2.8.2"
typing-extensions = "^4.8.0"
[tool.poetry.group.dev.dependencies]
black = "^23.11.0"
isort = "^5.12.0"
mypy = "^1.7.1"
flake8 = "^6.1.0"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.black]
line-length = 88
target-version = ['py39']
include = '\.pyi?$'
[tool.isort]
profile = "black"
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
line_length = 88
[tool.mypy]
python_version = "3.9"
warn_return_any = true
warn_unused_configs = true
disallow_untyped_defs = true
check_untyped_defs = true
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q --cov=Services"
testpaths = [
"Ztest",
]
python_files = ["test_*.py"]
asyncio_mode = "auto"