-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import pytest | ||
from fastapi import Response | ||
|
||
from frontik.app import FrontikApplication | ||
from frontik.handler import PageHandler, get_current_handler | ||
from frontik.routing import plain_router | ||
from frontik.testing import FrontikTestBase | ||
|
||
|
||
@plain_router.get('/cookies', cls=PageHandler) | ||
async def cookies_page(handler: PageHandler = get_current_handler()) -> None: | ||
handler.set_cookie('key1', 'val1') | ||
handler.set_cookie('key2', 'val2') | ||
|
||
|
||
@plain_router.get('/asgi_cookies') | ||
async def asgi_cookies_page(response: Response) -> None: | ||
response.set_cookie('key1', 'val1') | ||
response.set_cookie('key2', 'val2') | ||
|
||
|
||
class TestFrontikTesting(FrontikTestBase): | ||
@pytest.fixture(scope='class') | ||
def frontik_app(self) -> FrontikApplication: | ||
return FrontikApplication() | ||
|
||
async def test_cookies(self): | ||
response = await self.fetch('/cookies') | ||
|
||
assert response.status_code == 200 | ||
assert response.headers.getall('Set-Cookie') == ['key1=val1; Path=/', 'key2=val2; Path=/'] | ||
|
||
async def test_asgi_cookies(self): | ||
response = await self.fetch('/asgi_cookies') | ||
|
||
assert response.status_code == 200 | ||
assert response.headers.getall('Set-Cookie') == [ | ||
'key1=val1; Path=/; SameSite=lax', | ||
'key2=val2; Path=/; SameSite=lax', | ||
] |