From 8cae8e715ca61edf7f57e87b048228001dcc8549 Mon Sep 17 00:00:00 2001 From: Andrew Sergienko Date: Sun, 30 Apr 2023 18:31:29 +0300 Subject: [PATCH 1/4] added sync version of database URL --- src/database.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/database.py b/src/database.py index b83c5db..7ab566b 100644 --- a/src/database.py +++ b/src/database.py @@ -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 для підлключення до БД @@ -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: From 3abbb1527b99fd5da704c6db73fc6976159adcf2 Mon Sep 17 00:00:00 2001 From: Andrew Sergienko Date: Sun, 30 Apr 2023 18:31:55 +0300 Subject: [PATCH 2/4] added playwright tests --- requirements.txt | Bin 3146 -> 3218 bytes tests_playwright/__init__.py | 0 tests_playwright/test_auth.py | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 tests_playwright/__init__.py create mode 100644 tests_playwright/test_auth.py diff --git a/requirements.txt b/requirements.txt index a26ea1b2679999a000068a7cf0335ba02c8680b4..3c6432bdfb22ece898d1d0630321aa4e07d31996 100644 GIT binary patch delta 80 zcmX>lF-dZR7mo)QLn1>CLn=cqLlQ$KLo!1hgDrz0gB}nY07+v8E`|c2d?G_7Lpehc UP(?aJ215y4l`(@6SS=R=0ELMS%m4rY delta 7 OcmbOvc}ik~7Y_gnodT2q diff --git a/tests_playwright/__init__.py b/tests_playwright/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests_playwright/test_auth.py b/tests_playwright/test_auth.py new file mode 100644 index 0000000..dc5fdd4 --- /dev/null +++ b/tests_playwright/test_auth.py @@ -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 From bd0014db8adac79b033ad49ba46a135046f5e5e1 Mon Sep 17 00:00:00 2001 From: Andrew Sergienko Date: Sun, 30 Apr 2023 18:33:00 +0300 Subject: [PATCH 3/4] change pytest command in GitHub Action script --- .github/workflows/python-app.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 3d86958..90667b7 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -50,4 +50,4 @@ jobs: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Test with pytest run: | - pytest + pytest tests From 5f6c627b75bf7cd3a90df33aba7907a74bc34141 Mon Sep 17 00:00:00 2001 From: Andrew Sergienko Date: Sun, 30 Apr 2023 18:36:31 +0300 Subject: [PATCH 4/4] changed greenlet version from 2.0.2 to 2.0.1 --- requirements.txt | Bin 3218 -> 3218 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index 3c6432bdfb22ece898d1d0630321aa4e07d31996..11cc0783516737d11c8163482fc59970e75b11e4 100644 GIT binary patch delta 14 VcmbOvIZ1Lu4GW{;=2{j}4ge!`1PTBE delta 14 VcmbOvIZ1Lu4GW{u=2{j}4ge#11PcHF