makefile and http errors

This commit is contained in:
2026-07-30 20:58:53 +03:00
parent 3705ac4f0c
commit 8fa72daa6b
2 changed files with 86 additions and 12 deletions

View File

@@ -1,19 +1,67 @@
VENV=source .venv/bin/activate; VENV:=source .venv/bin/activate;
ALLURE=.venv/allure-2.44.0/bin/allure #linux&macos ALLURE:=.venv/allure-2.44.0/bin/allure #linux&macos
#ALLURE=.venv\allure-2.44.0\bin\allure #Windows #ALLURE=.venv\allure-2.44.0\bin\allure #Windows
.PHONY: NUM_DOWN ?= 1
run, m_gen, m_up, allure, coverage, pytest
run: .DEFAULT_GOAL := help
.PHONY: help
help:
@grep -E '(^[a-zA-Z0-9_-]+:.*?##.*$$)|(^##)' Makefile | awk 'BEGIN {FS = ":.*?## "}{printf "[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m## /[33m/' | sed -e 's/\[32m/ /' | sed -e 's/\[33m//'
##
## Init section
##
.PHONY: run
run: ## Run application
${VENV} python3 main.py ${VENV} python3 main.py
m_gen:
##
## Migration section
##
.PHONY: m_gen
m_gen: ## Generate alembic new revision
${VENV} alembic revision --autogenerate ${VENV} alembic revision --autogenerate
m_up:
.PHONY: m_up
m_up: ## Set new alembic revision
${VENV} alembic upgrade head ${VENV} alembic upgrade head
pytest:
.PHONY: m_down
m_down: ## Downgrade alembic revision
${VENV} alembic downgrade -${NUM_DOWN}
.PHONY: m_history
m_history: ## List history of migrations
${VENV} alembic history
.PHONY: m_current
m_current: ## Current migration
${VENV} alembic current
.PHONY: m_stamp
m_stamp: ## Stamp head
${VENV} alembic stamp head
##
## Test section
##
.PHONY: test
test: ## Run tests
${VENV} pytest ${VENV} pytest
allure:
.PHONY: allure
allure: ## Generate allure report
${VENV} ${ALLURE} generate tests/allure-results/reports --single-file -o tests/allure-results/html --clean ${VENV} ${ALLURE} generate tests/allure-results/reports --single-file -o tests/allure-results/html --clean
coverage:
${VENV} pytest --cov=src tests/ .PHONY: coverage
coverage: ## Run pytest coverage
${VENV} pytest --cov=src tests/
.PHONY: clear
clear: ## Delete old test results
rm -rf ./tests/allure-results/reports

View File

@@ -11,4 +11,30 @@ class Errors:
raise HTTPException(status_code=403, detail=detail, headers={"Cache-Control": "no-store, max-age=0"}) raise HTTPException(status_code=403, detail=detail, headers={"Cache-Control": "no-store, max-age=0"})
def not_found_error(self, detail:str)->HTTPException: def not_found_error(self, detail:str)->HTTPException:
raise HTTPException(status_code=404, detail=detail, headers={"Cache-Control": "no-store, max-age=0"}) raise HTTPException(status_code=404, detail=detail, headers={"Cache-Control": "no-store, max-age=0"})
def conflict_error(self, detail:str)->HTTPException:
raise HTTPException(status_code=409, detail=detail)
def bad_request_error(self, detail:str) -> HTTPException:
raise HTTPException(status_code=400, detail=detail)
def validation_error(self, detail:str) -> HTTPException:
raise HTTPException(status_code=422, detail=detail)
def rate_limit_error(self, detail:str, retry_after: int = 60) -> HTTPException:
raise HTTPException(
status_code=429,
detail=detail,
headers={"Retry-After":str(retry_after)}
)
def internal_server_error(self, detail:str = "Internal server error") -> HTTPException:
raise HTTPException(status_code=500, detail=detail)
def service_unavailable_error(self, detail:str, retry_after: int = 30) -> HTTPException:
raise HTTPException(
status_code=503,
detail=detail,
headers={"Retry-After":str(retry_after)}
)