Skip to content

Commit 1e2393e

Browse files
committed
Implement new fields on schema and database model
1 parent 98c3e4b commit 1e2393e

File tree

6 files changed

+62
-25
lines changed

6 files changed

+62
-25
lines changed

app/routers/libraries/routes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ async def create_library(
3636
library = Library(
3737
library_name=body.library_name,
3838
user_email="", # TODO: Considerar obter o email do usuário autenticado
39-
releases_url=body.releases_url.encoded_string(),
4039
logo=body.logo.encoded_string(),
40+
version=body.version,
41+
release_date=body.release_date,
42+
releases_doc_url=body.releases_doc_url.encoded_string(),
43+
fixed_release_url=body.fixed_release_url.encoded_string(),
4144
)
4245
try:
4346
await insert_library(library, request.app.db_session_factory)

app/schemas.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
from datetime import date
12
from enum import Enum
23
from typing import List
34

45
from pydantic import BaseModel, HttpUrl
56

67

8+
class LibraryTagEnum(str, Enum):
9+
UPDATES = "updates"
10+
BUG_FIX = "bug_fix"
11+
NEW_FEATURE = "new_feature"
12+
SECURITY_FIX = "security_fix"
13+
DEPRECATION = "deprecation"
14+
15+
16+
class LibraryNews(BaseModel):
17+
tag: LibraryTagEnum
18+
description: str
19+
20+
721
class Library(BaseModel):
822
library_name: str
9-
releases_url: HttpUrl
23+
news: List[LibraryNews]
1024
logo: HttpUrl
25+
version: str
26+
release_date: date
27+
releases_doc_url: HttpUrl
28+
fixed_release_url: HttpUrl
1129

1230

1331
# Community / User Class
@@ -31,15 +49,7 @@ class TokenPayload(BaseModel):
3149
username: str
3250

3351

34-
# Subscription Class
35-
class SubscriptionTagEnum(str, Enum):
36-
UPDATE = "update"
37-
BUG_FIX = "bug_fix"
38-
NEW_FEATURE = "new_feature"
39-
SECURITY_FIX = "security_fix"
40-
41-
4252
class Subscription(BaseModel):
4353
email: str
44-
tags: List[SubscriptionTagEnum]
54+
tags: List[LibraryTagEnum]
4555
libraries_list: List[str]

app/services/database/models/libraries.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from datetime import date
12
from typing import Optional
23

34
from sqlmodel import Field, SQLModel
@@ -9,8 +10,11 @@ class Library(SQLModel, table=True):
910
id: Optional[int] = Field(default=None, primary_key=True)
1011
library_name: str
1112
user_email: str
12-
releases_url: str
1313
logo: str
14+
version: str
15+
release_date: date
16+
releases_doc_url: str
17+
fixed_release_url: str
1418
community_id: Optional[int] = Field(
1519
default=None, foreign_key="communities.id"
1620
)

app/services/database/models/subscriptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List, Optional
22

3-
from schemas import SubscriptionTagEnum
3+
from schemas import LibraryTagEnum
44
from sqlalchemy import JSON, Column
55
from sqlmodel import Field, SQLModel
66

@@ -10,7 +10,7 @@ class Subscription(SQLModel, table=True):
1010

1111
id: Optional[int] = Field(default=None, primary_key=True)
1212
email: str
13-
tags: List[SubscriptionTagEnum] = Field(sa_column=Column(JSON))
13+
tags: List[LibraryTagEnum] = Field(sa_column=Column(JSON))
1414
community_id: Optional[int] = Field(
1515
default=None, foreign_key="communities.id"
1616
)

tests/test_libraries.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import date
2+
13
import pytest
24
import pytest_asyncio
35
from httpx import AsyncClient
@@ -20,8 +22,11 @@ async def test_insert_libraries(session: AsyncSession, community: Community):
2022
library = Library(
2123
library_name="Python",
2224
user_email="[email protected]",
23-
releases_url="http://teste.com",
24-
logo="logo",
25+
logo="http://teste.com",
26+
version="3.12",
27+
release_date=date.today(),
28+
releases_doc_url="http://teste.com",
29+
fixed_release_url="http://teste.com",
2530
community_id=community.id,
2631
)
2732
session.add(library)
@@ -34,8 +39,11 @@ async def test_insert_libraries(session: AsyncSession, community: Community):
3439
assert found is not None
3540
assert found.library_name == "Python"
3641
assert found.user_email == "[email protected]"
37-
assert found.releases_url == "http://teste.com"
38-
assert found.logo == "logo"
42+
assert found.logo == "http://teste.com"
43+
assert found.version == "3.12"
44+
assert found.release_date == date.today()
45+
assert found.releases_doc_url == "http://teste.com"
46+
assert found.fixed_release_url == "http://teste.com"
3947
assert found.community_id == community.id
4048

4149

@@ -45,8 +53,15 @@ async def test_post_libraries_endpoint(
4553
):
4654
body = {
4755
"library_name": "Python from API",
48-
"releases_url": "http://teste.com/",
56+
"news": [
57+
{"tag": "updates", "description": "New feature"},
58+
{"tag": "bug_fix", "description": "Fixed bug"},
59+
],
4960
"logo": "http://teste.com/",
61+
"version": "3.12",
62+
"release_date": "2023-01-01",
63+
"releases_doc_url": "http://teste.com/",
64+
"fixed_release_url": "http://teste.com/",
5065
}
5166

5267
response = await async_client.post(
@@ -65,5 +80,10 @@ async def test_post_libraries_endpoint(
6580
created_library = result.first()
6681

6782
assert created_library is not None
68-
assert created_library.releases_url == body["releases_url"]
6983
assert created_library.logo == body["logo"]
84+
assert created_library.version == body["version"]
85+
assert created_library.release_date == date.fromisoformat(
86+
body["release_date"]
87+
)
88+
assert created_library.releases_doc_url == body["releases_doc_url"]
89+
assert created_library.fixed_release_url == body["fixed_release_url"]

tests/test_subscriptions.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
import pytest_asyncio
33
from httpx import AsyncClient
4-
from schemas import SubscriptionTagEnum
4+
from schemas import LibraryTagEnum
55
from services.database.models import Community, Subscription
66
from sqlmodel import select
77
from sqlmodel.ext.asyncio.session import AsyncSession
@@ -20,7 +20,7 @@ async def community(session: AsyncSession):
2020
async def test_insert_subscription(session: AsyncSession, community: Community):
2121
subscription = Subscription(
2222
23-
tags=[SubscriptionTagEnum.BUG_FIX, SubscriptionTagEnum.UPDATE],
23+
tags=[LibraryTagEnum.BUG_FIX, LibraryTagEnum.UPDATES],
2424
community_id=community.id,
2525
)
2626
session.add(subscription)
@@ -38,8 +38,8 @@ async def test_insert_subscription(session: AsyncSession, community: Community):
3838
assert found is not None
3939
assert found.email == "[email protected]"
4040
assert found.tags == [
41-
SubscriptionTagEnum.BUG_FIX,
42-
SubscriptionTagEnum.UPDATE,
41+
LibraryTagEnum.BUG_FIX,
42+
LibraryTagEnum.UPDATES,
4343
]
4444
assert found.community_id == community.id
4545

@@ -79,7 +79,7 @@ async def preset_library(async_client: AsyncClient):
7979
async def test_post_subscribe_endpoint(async_client: AsyncClient):
8080
body = {
8181
"email": "[email protected]",
82-
"tags": ["bug_fix", "update"],
82+
"tags": ["bug_fix", "updates"],
8383
"libraries_list": ["Python", "Django"],
8484
}
8585

0 commit comments

Comments
 (0)