From 8fa72daa6b73b7d77ea2b8459271721f5904f8ee Mon Sep 17 00:00:00 2001 From: "MH.Dmitrii" Date: Thu, 30 Jul 2026 20:58:53 +0300 Subject: [PATCH] makefile and http errors --- makefile | 70 +++++++++++++++++++++++++++----- src/errors/http_errors/errors.py | 28 ++++++++++++- 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/makefile b/makefile index 7ee5b5b..92047e4 100644 --- a/makefile +++ b/makefile @@ -1,19 +1,67 @@ -VENV=source .venv/bin/activate; -ALLURE=.venv/allure-2.44.0/bin/allure #linux&macos +VENV:=source .venv/bin/activate; +ALLURE:=.venv/allure-2.44.0/bin/allure #linux&macos #ALLURE=.venv\allure-2.44.0\bin\allure #Windows -.PHONY: - run, m_gen, m_up, allure, coverage, pytest +NUM_DOWN ?= 1 -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 -m_gen: + +## +## Migration section +## + +.PHONY: m_gen +m_gen: ## Generate alembic new revision ${VENV} alembic revision --autogenerate -m_up: + +.PHONY: m_up +m_up: ## Set new alembic revision ${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 -allure: + +.PHONY: allure +allure: ## Generate allure report ${VENV} ${ALLURE} generate tests/allure-results/reports --single-file -o tests/allure-results/html --clean -coverage: - ${VENV} pytest --cov=src tests/ \ No newline at end of file + +.PHONY: coverage +coverage: ## Run pytest coverage + ${VENV} pytest --cov=src tests/ + +.PHONY: clear +clear: ## Delete old test results + rm -rf ./tests/allure-results/reports \ No newline at end of file diff --git a/src/errors/http_errors/errors.py b/src/errors/http_errors/errors.py index 093aa70..430ca7f 100644 --- a/src/errors/http_errors/errors.py +++ b/src/errors/http_errors/errors.py @@ -11,4 +11,30 @@ class Errors: raise HTTPException(status_code=403, detail=detail, headers={"Cache-Control": "no-store, max-age=0"}) def not_found_error(self, detail:str)->HTTPException: - raise HTTPException(status_code=404, detail=detail, headers={"Cache-Control": "no-store, max-age=0"}) \ No newline at end of file + 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)} + ) \ No newline at end of file