diff --git a/examples/miniapps/fastapi-sqlalchemy/webapp/application.py b/examples/miniapps/fastapi-sqlalchemy/webapp/application.py index 9e46af20..d6aa9eeb 100644 --- a/examples/miniapps/fastapi-sqlalchemy/webapp/application.py +++ b/examples/miniapps/fastapi-sqlalchemy/webapp/application.py @@ -8,7 +8,7 @@ from . import endpoints def create_app() -> FastAPI: container = Container() - container.config.from_yaml('config.yml') + container.config.from_yaml("config.yml") container.wire(modules=[endpoints]) db = container.db() diff --git a/examples/miniapps/fastapi-sqlalchemy/webapp/database.py b/examples/miniapps/fastapi-sqlalchemy/webapp/database.py index 763f4c37..3ce2e257 100644 --- a/examples/miniapps/fastapi-sqlalchemy/webapp/database.py +++ b/examples/miniapps/fastapi-sqlalchemy/webapp/database.py @@ -34,7 +34,7 @@ class Database: try: yield session except Exception: - logger.exception('Session rollback because of exception') + logger.exception("Session rollback because of exception") session.rollback() raise finally: diff --git a/examples/miniapps/fastapi-sqlalchemy/webapp/endpoints.py b/examples/miniapps/fastapi-sqlalchemy/webapp/endpoints.py index 799e6171..4d27101e 100644 --- a/examples/miniapps/fastapi-sqlalchemy/webapp/endpoints.py +++ b/examples/miniapps/fastapi-sqlalchemy/webapp/endpoints.py @@ -10,7 +10,7 @@ from .repositories import NotFoundError router = APIRouter() -@router.get('/users') +@router.get("/users") @inject def get_list( user_service: UserService = Depends(Provide[Container.user_service]), @@ -18,7 +18,7 @@ def get_list( return user_service.get_users() -@router.get('/users/{user_id}') +@router.get("/users/{user_id}") @inject def get_by_id( user_id: int, @@ -30,7 +30,7 @@ def get_by_id( return Response(status_code=status.HTTP_404_NOT_FOUND) -@router.post('/users', status_code=status.HTTP_201_CREATED) +@router.post("/users", status_code=status.HTTP_201_CREATED) @inject def add( user_service: UserService = Depends(Provide[Container.user_service]), @@ -38,7 +38,7 @@ def add( return user_service.create_user() -@router.delete('/users/{user_id}', status_code=status.HTTP_204_NO_CONTENT) +@router.delete("/users/{user_id}", status_code=status.HTTP_204_NO_CONTENT) @inject def remove( user_id: int, @@ -52,6 +52,6 @@ def remove( return Response(status_code=status.HTTP_204_NO_CONTENT) -@router.get('/status') +@router.get("/status") def get_status(): - return {'status': 'OK'} + return {"status": "OK"} diff --git a/examples/miniapps/fastapi-sqlalchemy/webapp/models.py b/examples/miniapps/fastapi-sqlalchemy/webapp/models.py index 1f3afe49..daefaa59 100644 --- a/examples/miniapps/fastapi-sqlalchemy/webapp/models.py +++ b/examples/miniapps/fastapi-sqlalchemy/webapp/models.py @@ -7,7 +7,7 @@ from .database import Base class User(Base): - __tablename__ = 'users' + __tablename__ = "users" id = Column(Integer, primary_key=True) email = Column(String, unique=True) @@ -15,7 +15,7 @@ class User(Base): is_active = Column(Boolean, default=True) def __repr__(self): - return f'' + return f"" diff --git a/examples/miniapps/fastapi-sqlalchemy/webapp/repositories.py b/examples/miniapps/fastapi-sqlalchemy/webapp/repositories.py index e76a107b..f86e41ee 100644 --- a/examples/miniapps/fastapi-sqlalchemy/webapp/repositories.py +++ b/examples/miniapps/fastapi-sqlalchemy/webapp/repositories.py @@ -46,9 +46,9 @@ class NotFoundError(Exception): entity_name: str def __init__(self, entity_id): - super().__init__(f'{self.entity_name} not found, id: {entity_id}') + super().__init__(f"{self.entity_name} not found, id: {entity_id}") class UserNotFoundError(NotFoundError): - entity_name: str = 'User' + entity_name: str = "User" diff --git a/examples/miniapps/fastapi-sqlalchemy/webapp/services.py b/examples/miniapps/fastapi-sqlalchemy/webapp/services.py index c48cccbb..8c0cb4f6 100644 --- a/examples/miniapps/fastapi-sqlalchemy/webapp/services.py +++ b/examples/miniapps/fastapi-sqlalchemy/webapp/services.py @@ -20,7 +20,7 @@ class UserService: def create_user(self) -> User: uid = uuid4() - return self._repository.add(email=f'{uid}@email.com', password='pwd') + return self._repository.add(email=f"{uid}@email.com", password="pwd") def delete_user_by_id(self, user_id: int) -> None: return self._repository.delete_by_id(user_id) diff --git a/examples/miniapps/fastapi-sqlalchemy/webapp/tests.py b/examples/miniapps/fastapi-sqlalchemy/webapp/tests.py index fe2e6a12..cf3a9939 100644 --- a/examples/miniapps/fastapi-sqlalchemy/webapp/tests.py +++ b/examples/miniapps/fastapi-sqlalchemy/webapp/tests.py @@ -18,18 +18,18 @@ def client(): def test_get_list(client): repository_mock = mock.Mock(spec=UserRepository) repository_mock.get_all.return_value = [ - User(id=1, email='test1@email.com', hashed_password='pwd', is_active=True), - User(id=2, email='test2@email.com', hashed_password='pwd', is_active=False), + User(id=1, email="test1@email.com", hashed_password="pwd", is_active=True), + User(id=2, email="test2@email.com", hashed_password="pwd", is_active=False), ] with app.container.user_repository.override(repository_mock): - response = client.get('/users') + response = client.get("/users") assert response.status_code == 200 data = response.json() assert data == [ - {'id': 1, 'email': 'test1@email.com', 'hashed_password': 'pwd', 'is_active': True}, - {'id': 2, 'email': 'test2@email.com', 'hashed_password': 'pwd', 'is_active': False}, + {"id": 1, "email": "test1@email.com", "hashed_password": "pwd", "is_active": True}, + {"id": 2, "email": "test2@email.com", "hashed_password": "pwd", "is_active": False}, ] @@ -37,17 +37,17 @@ def test_get_by_id(client): repository_mock = mock.Mock(spec=UserRepository) repository_mock.get_by_id.return_value = User( id=1, - email='xyz@email.com', - hashed_password='pwd', + email="xyz@email.com", + hashed_password="pwd", is_active=True, ) with app.container.user_repository.override(repository_mock): - response = client.get('/users/1') + response = client.get("/users/1") assert response.status_code == 200 data = response.json() - assert data == {'id': 1, 'email': 'xyz@email.com', 'hashed_password': 'pwd', 'is_active': True} + assert data == {"id": 1, "email": "xyz@email.com", "hashed_password": "pwd", "is_active": True} repository_mock.get_by_id.assert_called_once_with(1) @@ -56,35 +56,35 @@ def test_get_by_id_404(client): repository_mock.get_by_id.side_effect = UserNotFoundError(1) with app.container.user_repository.override(repository_mock): - response = client.get('/users/1') + response = client.get("/users/1") assert response.status_code == 404 -@mock.patch('webapp.services.uuid4', return_value='xyz') +@mock.patch("webapp.services.uuid4", return_value="xyz") def test_add(_, client): repository_mock = mock.Mock(spec=UserRepository) repository_mock.add.return_value = User( id=1, - email='xyz@email.com', - hashed_password='pwd', + email="xyz@email.com", + hashed_password="pwd", is_active=True, ) with app.container.user_repository.override(repository_mock): - response = client.post('/users') + response = client.post("/users") assert response.status_code == 201 data = response.json() - assert data == {'id': 1, 'email': 'xyz@email.com', 'hashed_password': 'pwd', 'is_active': True} - repository_mock.add.assert_called_once_with(email='xyz@email.com', password='pwd') + assert data == {"id": 1, "email": "xyz@email.com", "hashed_password": "pwd", "is_active": True} + repository_mock.add.assert_called_once_with(email="xyz@email.com", password="pwd") def test_remove(client): repository_mock = mock.Mock(spec=UserRepository) with app.container.user_repository.override(repository_mock): - response = client.delete('/users/1') + response = client.delete("/users/1") assert response.status_code == 204 repository_mock.delete_by_id.assert_called_once_with(1) @@ -95,13 +95,13 @@ def test_remove_404(client): repository_mock.delete_by_id.side_effect = UserNotFoundError(1) with app.container.user_repository.override(repository_mock): - response = client.delete('/users/1') + response = client.delete("/users/1") assert response.status_code == 404 def test_status(client): - response = client.get('/status') + response = client.get("/status") assert response.status_code == 200 data = response.json() - assert data == {'status': 'OK'} + assert data == {"status": "OK"}