Skip to content

Commit

Permalink
server/article: add more tests to service
Browse files Browse the repository at this point in the history
Following fix in 2e0826c
  • Loading branch information
frankie567 committed Dec 12, 2023
1 parent 264eff3 commit b2a7848
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion server/tests/article/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest_asyncio

from polar.article.service import article_service
from polar.authz.service import Subject
from polar.authz.service import Anonymous, Subject
from polar.kit.pagination import PaginationParams
from polar.kit.utils import utc_now
from polar.models import (
Expand All @@ -19,6 +19,7 @@
UserOrganization,
)
from polar.postgres import AsyncSession
from tests.fixtures.random_objects import create_user


def random_string(length: int = 32) -> str:
Expand Down Expand Up @@ -173,7 +174,19 @@ async def articles(
]


@pytest_asyncio.fixture
async def other_subscriptions(
session: AsyncSession, organization: Organization
) -> None:
for _ in range(5):
user = await create_user(session)
await create_articles_subscription(
session, user=user, organization=organization, paid_subscriber=False
)


@pytest.mark.asyncio
@pytest.mark.usefixtures("other_subscriptions")
class TestList:
async def test_no_subscription(
self, session: AsyncSession, articles: list[Article], user_second: User
Expand Down Expand Up @@ -256,7 +269,30 @@ async def test_paid_subscription(


@pytest.mark.asyncio
@pytest.mark.usefixtures("other_subscriptions")
class TestSearch:
async def test_anonymous(
self,
session: AsyncSession,
articles: list[Article],
article_public_free_published: Article,
organization: Organization,
user_second: User,
) -> None:
results, count = await article_service.search(
session,
Anonymous(),
organization_id=organization.id,
pagination=PaginationParams(1, 10),
)

assert len(results) == 1
assert count == 1

article, is_paid_subscriber = results[0]
assert article.id == article_public_free_published.id
assert is_paid_subscriber is False

async def test_no_subscription(
self,
session: AsyncSession,
Expand Down

2 comments on commit b2a7848

@vercel
Copy link

@vercel vercel bot commented on b2a7848 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-polar-sh.vercel.app
docs.polar.sh
docs-sigma-puce.vercel.app
docs-git-main-polar-sh.vercel.app

@vercel
Copy link

@vercel vercel bot commented on b2a7848 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.