Skip to content

Commit 19e4c8f

Browse files
committed
Update tests and schemas with stricter validation and content adjustments
1 parent 6f9609e commit 19e4c8f

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

conduit/api/schemas/requests/user.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from pydantic import BaseModel, EmailStr, Field
1+
from typing import Any
2+
3+
from pydantic import BaseModel, EmailStr, Field, field_validator
24

35
from conduit.domain.dtos.user import CreateUserDTO, LoginUserDTO, UpdateUserDTO
46

@@ -15,12 +17,17 @@ class UserLoginData(BaseModel):
1517

1618

1719
class UserUpdateData(BaseModel):
18-
email: str | None = Field(None)
19-
password: str | None = Field(None)
20-
username: str | None = Field(None)
20+
email: EmailStr | None = Field(None)
21+
password: str | None = Field(None, min_length=8)
22+
username: str | None = Field(None, min_length=3)
2123
bio: str | None = Field(None)
2224
image: str | None = Field(None)
2325

26+
@field_validator("*", mode="before")
27+
@classmethod
28+
def empty_as_none(cls, v: Any) -> Any:
29+
return v or None if isinstance(v, (str,)) else v
30+
2431

2532
class UserRegistrationRequest(BaseModel):
2633
user: UserRegistrationData

tests/api/routes/test_article.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async def test_user_can_create_new_article(authorized_test_client: AsyncClient)
1414
payload = {
1515
"article": {
1616
"title": "Test Article",
17-
"body": "test body",
17+
"body": "test body content",
1818
"description": "test description",
1919
"tagList": ["tag1", "tag2", "tag3"],
2020
}
@@ -30,7 +30,7 @@ async def test_user_can_create_article_without_tags(
3030
payload = {
3131
"article": {
3232
"title": "Test Article",
33-
"body": "test body",
33+
"body": "test body content",
3434
"description": "test description",
3535
"tagList": [],
3636
}
@@ -46,7 +46,7 @@ async def test_user_can_create_article_without_duplicated_tags(
4646
payload = {
4747
"article": {
4848
"title": "Test Article",
49-
"body": "test body",
49+
"body": "test body content",
5050
"description": "test description",
5151
"tagList": ["tag1", "tag2", "tag2", "tag3", "tag3"],
5252
}
@@ -63,7 +63,7 @@ async def test_user_can_create_article_with_existing_title(
6363
payload = {
6464
"article": {
6565
"title": test_article.title,
66-
"body": "test body",
66+
"body": "test body content",
6767
"description": "test description",
6868
"tagList": test_article.tags,
6969
}
@@ -79,7 +79,7 @@ async def test_user_can_retrieve_article_without_tags(
7979
payload = {
8080
"article": {
8181
"title": "Test Article",
82-
"body": "test body",
82+
"body": "test body content",
8383
"description": "test description",
8484
"tagList": [],
8585
}

tests/api/routes/test_login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def test_user_successful_login(
1717
"credentials,",
1818
(
1919
{"email": "invalid@gmail.com", "password": "password"},
20-
{"email": "test@gmail.com", "password": "invalid"},
20+
{"email": "test@gmail.com", "password": "invalidpassword"},
2121
),
2222
)
2323
@pytest.mark.anyio

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def article_to_create() -> CreateArticleDTO:
110110
return CreateArticleDTO(
111111
title="Test Article",
112112
description="Test Description",
113-
body="Test Body",
113+
body="Test Body Content",
114114
tags=["tag1", "tag2"],
115115
)
116116

tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def create_another_test_article(
2121
create_article_dto = CreateArticleDTO(
2222
title="One More Test Article",
2323
description="Test Description",
24-
body="Test Body",
24+
body="Test Body Content",
2525
tags=["tag1", "tag2", "tag3"],
2626
)
2727
return await article_repository.add(

0 commit comments

Comments
 (0)