Skip to content

Commit 3c52756

Browse files
committed
Update quotes in fastapi-sqlalchemy example
1 parent 274d1fe commit 3c52756

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

Diff for: examples/miniapps/fastapi-sqlalchemy/webapp/application.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def create_app() -> FastAPI:
1010
container = Container()
11-
container.config.from_yaml('config.yml')
11+
container.config.from_yaml("config.yml")
1212
container.wire(modules=[endpoints])
1313

1414
db = container.db()

Diff for: examples/miniapps/fastapi-sqlalchemy/webapp/database.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def session(self) -> Callable[..., AbstractContextManager[Session]]:
3434
try:
3535
yield session
3636
except Exception:
37-
logger.exception('Session rollback because of exception')
37+
logger.exception("Session rollback because of exception")
3838
session.rollback()
3939
raise
4040
finally:

Diff for: examples/miniapps/fastapi-sqlalchemy/webapp/endpoints.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
router = APIRouter()
1111

1212

13-
@router.get('/users')
13+
@router.get("/users")
1414
@inject
1515
def get_list(
1616
user_service: UserService = Depends(Provide[Container.user_service]),
1717
):
1818
return user_service.get_users()
1919

2020

21-
@router.get('/users/{user_id}')
21+
@router.get("/users/{user_id}")
2222
@inject
2323
def get_by_id(
2424
user_id: int,
@@ -30,15 +30,15 @@ def get_by_id(
3030
return Response(status_code=status.HTTP_404_NOT_FOUND)
3131

3232

33-
@router.post('/users', status_code=status.HTTP_201_CREATED)
33+
@router.post("/users", status_code=status.HTTP_201_CREATED)
3434
@inject
3535
def add(
3636
user_service: UserService = Depends(Provide[Container.user_service]),
3737
):
3838
return user_service.create_user()
3939

4040

41-
@router.delete('/users/{user_id}', status_code=status.HTTP_204_NO_CONTENT)
41+
@router.delete("/users/{user_id}", status_code=status.HTTP_204_NO_CONTENT)
4242
@inject
4343
def remove(
4444
user_id: int,
@@ -52,6 +52,6 @@ def remove(
5252
return Response(status_code=status.HTTP_204_NO_CONTENT)
5353

5454

55-
@router.get('/status')
55+
@router.get("/status")
5656
def get_status():
57-
return {'status': 'OK'}
57+
return {"status": "OK"}

Diff for: examples/miniapps/fastapi-sqlalchemy/webapp/models.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
class User(Base):
99

10-
__tablename__ = 'users'
10+
__tablename__ = "users"
1111

1212
id = Column(Integer, primary_key=True)
1313
email = Column(String, unique=True)
1414
hashed_password = Column(String)
1515
is_active = Column(Boolean, default=True)
1616

1717
def __repr__(self):
18-
return f'<User(id="{self.id}", ' \
19-
f'email="{self.email}", ' \
20-
f'hashed_password="{self.hashed_password}", ' \
21-
f'is_active="{self.is_active}")>'
18+
return f"<User(id={self.id}, " \
19+
f"email=\"{self.email}\", " \
20+
f"hashed_password=\"{self.hashed_password}\", " \
21+
f"is_active={self.is_active})>"

Diff for: examples/miniapps/fastapi-sqlalchemy/webapp/repositories.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class NotFoundError(Exception):
4646
entity_name: str
4747

4848
def __init__(self, entity_id):
49-
super().__init__(f'{self.entity_name} not found, id: {entity_id}')
49+
super().__init__(f"{self.entity_name} not found, id: {entity_id}")
5050

5151

5252
class UserNotFoundError(NotFoundError):
5353

54-
entity_name: str = 'User'
54+
entity_name: str = "User"

Diff for: examples/miniapps/fastapi-sqlalchemy/webapp/services.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_user_by_id(self, user_id: int) -> User:
2020

2121
def create_user(self) -> User:
2222
uid = uuid4()
23-
return self._repository.add(email=f'{uid}@email.com', password='pwd')
23+
return self._repository.add(email=f"{uid}@email.com", password="pwd")
2424

2525
def delete_user_by_id(self, user_id: int) -> None:
2626
return self._repository.delete_by_id(user_id)

Diff for: examples/miniapps/fastapi-sqlalchemy/webapp/tests.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,36 @@ def client():
1818
def test_get_list(client):
1919
repository_mock = mock.Mock(spec=UserRepository)
2020
repository_mock.get_all.return_value = [
21-
User(id=1, email='[email protected]', hashed_password='pwd', is_active=True),
22-
User(id=2, email='[email protected]', hashed_password='pwd', is_active=False),
21+
User(id=1, email="[email protected]", hashed_password="pwd", is_active=True),
22+
User(id=2, email="[email protected]", hashed_password="pwd", is_active=False),
2323
]
2424

2525
with app.container.user_repository.override(repository_mock):
26-
response = client.get('/users')
26+
response = client.get("/users")
2727

2828
assert response.status_code == 200
2929
data = response.json()
3030
assert data == [
31-
{'id': 1, 'email': '[email protected]', 'hashed_password': 'pwd', 'is_active': True},
32-
{'id': 2, 'email': '[email protected]', 'hashed_password': 'pwd', 'is_active': False},
31+
{"id": 1, "email": "[email protected]", "hashed_password": "pwd", "is_active": True},
32+
{"id": 2, "email": "[email protected]", "hashed_password": "pwd", "is_active": False},
3333
]
3434

3535

3636
def test_get_by_id(client):
3737
repository_mock = mock.Mock(spec=UserRepository)
3838
repository_mock.get_by_id.return_value = User(
3939
id=1,
40-
41-
hashed_password='pwd',
40+
41+
hashed_password="pwd",
4242
is_active=True,
4343
)
4444

4545
with app.container.user_repository.override(repository_mock):
46-
response = client.get('/users/1')
46+
response = client.get("/users/1")
4747

4848
assert response.status_code == 200
4949
data = response.json()
50-
assert data == {'id': 1, 'email': '[email protected]', 'hashed_password': 'pwd', 'is_active': True}
50+
assert data == {"id": 1, "email": "[email protected]", "hashed_password": "pwd", "is_active": True}
5151
repository_mock.get_by_id.assert_called_once_with(1)
5252

5353

@@ -56,35 +56,35 @@ def test_get_by_id_404(client):
5656
repository_mock.get_by_id.side_effect = UserNotFoundError(1)
5757

5858
with app.container.user_repository.override(repository_mock):
59-
response = client.get('/users/1')
59+
response = client.get("/users/1")
6060

6161
assert response.status_code == 404
6262

6363

64-
@mock.patch('webapp.services.uuid4', return_value='xyz')
64+
@mock.patch("webapp.services.uuid4", return_value="xyz")
6565
def test_add(_, client):
6666
repository_mock = mock.Mock(spec=UserRepository)
6767
repository_mock.add.return_value = User(
6868
id=1,
69-
70-
hashed_password='pwd',
69+
70+
hashed_password="pwd",
7171
is_active=True,
7272
)
7373

7474
with app.container.user_repository.override(repository_mock):
75-
response = client.post('/users')
75+
response = client.post("/users")
7676

7777
assert response.status_code == 201
7878
data = response.json()
79-
assert data == {'id': 1, 'email': '[email protected]', 'hashed_password': 'pwd', 'is_active': True}
80-
repository_mock.add.assert_called_once_with(email='[email protected]', password='pwd')
79+
assert data == {"id": 1, "email": "[email protected]", "hashed_password": "pwd", "is_active": True}
80+
repository_mock.add.assert_called_once_with(email="[email protected]", password="pwd")
8181

8282

8383
def test_remove(client):
8484
repository_mock = mock.Mock(spec=UserRepository)
8585

8686
with app.container.user_repository.override(repository_mock):
87-
response = client.delete('/users/1')
87+
response = client.delete("/users/1")
8888

8989
assert response.status_code == 204
9090
repository_mock.delete_by_id.assert_called_once_with(1)
@@ -95,13 +95,13 @@ def test_remove_404(client):
9595
repository_mock.delete_by_id.side_effect = UserNotFoundError(1)
9696

9797
with app.container.user_repository.override(repository_mock):
98-
response = client.delete('/users/1')
98+
response = client.delete("/users/1")
9999

100100
assert response.status_code == 404
101101

102102

103103
def test_status(client):
104-
response = client.get('/status')
104+
response = client.get("/status")
105105
assert response.status_code == 200
106106
data = response.json()
107-
assert data == {'status': 'OK'}
107+
assert data == {"status": "OK"}

0 commit comments

Comments
 (0)