Skip to content

Commit 909784e

Browse files
authored
Merge pull request #26 from PythonFloripa/feature/#12
Feature/#12
2 parents cb91920 + c5f1b6d commit 909784e

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from app.services.database.models.communities import Community
22
from app.services.database.models.libraries import Library
3+
from app.services.database.models.subscriptions import Subscription
34

4-
__all__ = ["Community", "Library"]
5+
__all__ = ["Community", "Library", "Subscription"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from typing import Optional
2+
3+
from sqlmodel import SQLModel, Field
4+
5+
6+
class Subscription(SQLModel, table=True):
7+
__tablename__ = 'subscriptions'
8+
9+
id: Optional[int] = Field(default=None, primary_key=True)
10+
email: str
11+
tags: str
12+
community_id: Optional[int] = Field(default=None, foreign_key="communities.id")

tests/test_subscriptions.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
import pytest_asyncio
3+
4+
from sqlmodel import select
5+
from sqlmodel.ext.asyncio.session import AsyncSession
6+
7+
from services.database.models import Community, Subscription
8+
9+
10+
@pytest_asyncio.fixture
11+
async def community(session: AsyncSession):
12+
community = Community(username="admin", email="[email protected]", password="123")
13+
session.add(community)
14+
await session.commit()
15+
await session.refresh(community)
16+
return community
17+
18+
19+
@pytest.mark.asyncio
20+
async def test_insert_subscription(session: AsyncSession, community: Community):
21+
subscription = Subscription(
22+
23+
tags="teste,Python",
24+
community_id=community.id,
25+
)
26+
session.add(subscription)
27+
await session.commit()
28+
29+
statement = select(Subscription).where(Subscription.email == "[email protected]")
30+
result = await session.exec(statement)
31+
found = result.first()
32+
33+
assert found is not None
34+
assert found.email == "[email protected]"
35+
assert found.tags == "teste,Python"
36+
assert found.community_id == community.id

0 commit comments

Comments
 (0)