Skip to content

Commit

Permalink
Merge pull request #28 from AndrewSergienko/playwright_tests
Browse files Browse the repository at this point in the history
Playwright tests
  • Loading branch information
andiserg authored Apr 30, 2023
2 parents 767ada5 + 5f6c627 commit b0cfd86
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest
pytest tests
Binary file modified requirements.txt
Binary file not shown.
8 changes: 6 additions & 2 deletions src/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from src.app.adapters.orm import create_tables, start_mappers


def _get_url(test: bool = False) -> str:
def _get_url(test: bool = False, async_: bool = True) -> str:
"""
:param test: Якщо True, то підставляє назву тестової бази в URL
:return: URL для підлключення до БД
Expand All @@ -21,7 +21,11 @@ def _get_url(test: bool = False) -> str:
os.getenv("DB_PASSWORD"),
os.getenv("DB_HOST"),
)
return f"postgresql+asyncpg://{db_user}:{db_password}@{db_host}/{db_name}"
return (
f"postgresql+asyncpg://{db_user}:{db_password}@{db_host}/{db_name}"
if async_
else f"postgresql+psycopg2://{db_user}:{db_password}@{db_host}/{db_name}"
)


class Database:
Expand Down
Empty file added tests_playwright/__init__.py
Empty file.
78 changes: 78 additions & 0 deletions tests_playwright/test_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import re
import time

from playwright.sync_api import Page
from sqlalchemy import create_engine, text

from src.database import _get_url


def delete_user():
engine = create_engine(_get_url(async_=False))
with engine.connect() as connection:
user_id = connection.execute(
text("SELECT id FROM public.users WHERE email = 'test';")
).first()
user_id = user_id[0] if user_id else None
if user_id:
connection.execute(
text(f"DELETE FROM public.operations WHERE user_id = {user_id};")
)
connection.execute(text("DELETE FROM public.users WHERE email = 'test';"))
connection.commit()


def login(page):
page.get_by_role("button", name="Sign In").click()
page.get_by_placeholder("email").fill("test")
page.get_by_placeholder("password").click()
page.get_by_placeholder("password").fill("test")
page.get_by_role("button", name="Login").click()


def test_auth(page: Page) -> None:
delete_user()
page.goto("http://127.0.0.1:3000/")
page.get_by_role("button", name="Sign Up").click()
page.get_by_placeholder("email").fill("test")
page.get_by_placeholder("password", exact=True).click()
page.get_by_placeholder("password", exact=True).fill("test")
page.get_by_placeholder("confirm password").click()
page.get_by_placeholder("confirm password").fill("test")
page.get_by_role("button", name="Register").click()
login(page)
assert page.get_by_role("button", name="Додати").is_enabled()


def test_add_operation(page: Page) -> None:
page.goto("http://127.0.0.1:3000/")
login(page)
page.get_by_role("button", name="Додати").click()
page.get_by_placeholder("сума").fill("100")
page.get_by_placeholder("опис").fill("test")
page.locator("svg").click()
time.sleep(0.3)
page.get_by_text("Ветеринарні послуги", exact=True).last.click()
page.get_by_role("button", name="Додати").click()
time.sleep(0.3)
assert (
page.get_by_text(
re.compile("-100 ₴testВетеринарні послугиручний спосіб")
).count()
> 0
)


def test_add_old_operation(page: Page) -> None:
page.goto("http://127.0.0.1:3000/")
login(page)
page.get_by_role("button", name="Додати").click()
page.get_by_placeholder("сума").fill("100")
page.get_by_placeholder("опис").fill("test")
page.get_by_placeholder("час").fill("2023-04-25T05:15")
page.locator("svg").click()
time.sleep(0.3)
page.get_by_text("Продукти", exact=True).click()
page.get_by_role("button", name="Додати").click()
page.get_by_placeholder("dashboard-time").fill("2023-04-25")
assert page.get_by_text("-100 ₴testПродуктиручний спосіб05:15").count() == 1

0 comments on commit b0cfd86

Please sign in to comment.