Skip to content

Commit 30d330c

Browse files
committed
upd
1 parent 2cb8fa1 commit 30d330c

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

app/models/types/unix.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ def process_bind_param(
2020
elif isinstance(value, str):
2121
return int(dt.datetime.fromisoformat(value).timestamp())
2222

23-
def process_result_value(
24-
self, value: int | None, dialect
25-
) -> dt.datetime | None:
23+
def process_result_value(self, value: int | None, dialect) -> dt.datetime | None:
2624
if isinstance(value, int):
2725
return dt.datetime.fromtimestamp(value, dt.UTC)

src/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88

99
app.include_router(user_router)
1010

11+
1112
@app.exception_handler(Exception)
1213
async def exception_handler(request, exc: DomainError):
1314
return JSONResponse(
1415
status_code=exc.status,
1516
content={"detail": exc.message},
1617
)
1718

19+
1820
if __name__ == "__main__":
1921
import uvicorn
22+
2023
uvicorn.run(app, host="0.0.0.0", port=8000)

src/domain/auth/exceptions/token.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ class TokenExpiredError(DomainError):
1919
@property
2020
def message(self) -> str:
2121
return f"Token expired {self.token}"
22-
23-
24-

src/domain/auth/value_objects/token.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
JWT_SECRET = "your_secret_key" # Замените на секретный ключ из конфигурации
1111

12+
1213
@dataclass(frozen=True)
1314
class Token(BaseValueObject[str]):
1415
"""
@@ -17,6 +18,7 @@ class Token(BaseValueObject[str]):
1718
Атрибуты:
1819
value: Строковое значение токена.
1920
"""
21+
2022
value: str
2123

2224
@classmethod

src/presentation/api/user_controller.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
user_service = UserService(InMemoryUserRepository())
88

9+
910
@router.post("/users")
1011
def create_user(username: str, password: str):
1112
user = user_service.create_user(username, password)
1213
return {"user_id": user.oid, "username": user.username.to_raw()}
1314

15+
1416
@router.get("/users/{username}")
1517
def get_user(username: str):
1618
user = user_service.get_user_by_username(username)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from domain.user.entities.user import User
22

3+
34
def test_create():
45
user = User.create("john_doe", "SecureP@ss1")
56
assert user
67

78

89
def test_check_pasword():
910
user = User.create("john_doe", "SecureP@ss1")
10-
assert user.check_password("SecureP@ss1") == True
11+
assert user.check_password("SecureP@ss1")
12+
1113

1214
def test_change_pasword():
1315
user = User.create("john_doe", "SecureP@ss1")
1416
user.change_password("SecureP@ss2")
15-
assert user.check_password("SecureP@ss2") == True
16-
17-
17+
assert user.check_password("SecureP@ss2")

src/tests/domain/user/value_objects/test_password.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
11
import pytest
22

3-
from domain.user.exceptions.password import PasswordRequiresDigitError, PasswordRequiresLowercaseError, PasswordRequiresSpecialCharError, PasswordRequiresUppercaseError, PasswordTooLongError, PasswordTooShortError, WrongPasswordFormatError
3+
from domain.user.exceptions.password import (
4+
PasswordRequiresDigitError,
5+
PasswordRequiresLowercaseError,
6+
PasswordRequiresSpecialCharError,
7+
PasswordRequiresUppercaseError,
8+
PasswordTooLongError,
9+
PasswordTooShortError,
10+
)
411
from domain.user.value_objects.password import Password
512

13+
614
def test_valid_password():
715
password = Password("SecureP@ss1")
816
assert password.to_raw() == "SecureP@ss1"
917

18+
1019
def test_password_too_short():
1120
with pytest.raises(PasswordTooShortError):
1221
Password("Short1")
1322

23+
1424
def test_password_too_long():
1525
with pytest.raises(PasswordTooLongError):
1626
Password("a" * 65)
1727

28+
1829
def test_password_requires_digit():
1930
with pytest.raises(PasswordRequiresDigitError):
2031
Password("NoDigits!")
2132

33+
2234
def test_password_requires_uppercase():
2335
with pytest.raises(PasswordRequiresUppercaseError):
2436
Password("nouppercase1!")
2537

38+
2639
def test_password_requires_lowercase():
2740
with pytest.raises(PasswordRequiresLowercaseError):
2841
Password("NOLOWERCASE1!")
2942

43+
3044
def test_password_requires_special_char():
3145
with pytest.raises(PasswordRequiresSpecialCharError):
3246
Password("NoSpecialChar1")
33-
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import pytest
22

3-
from domain.user.exceptions.username import UsernameTooLongError, UsernameTooShortError, WrongUsernameFormatError
3+
from domain.user.exceptions.username import (
4+
UsernameTooLongError,
5+
UsernameTooShortError,
6+
WrongUsernameFormatError,
7+
)
48
from domain.user.value_objects.username import Username
59

10+
611
def test_valid_username():
712
username = Username("john_doe")
813
assert username.to_raw() == "john_doe"
914

15+
1016
def test_username_too_short():
1117
with pytest.raises(UsernameTooShortError):
1218
Username("jo")
1319

20+
1421
def test_username_too_long():
1522
with pytest.raises(UsernameTooLongError):
1623
Username("a" * 33)
1724

25+
1826
def test_wrong_username_format():
1927
with pytest.raises(WrongUsernameFormatError):
2028
Username("123_john")

0 commit comments

Comments
 (0)