From bc8679a597a8112f94537475b8bcbd5af66edae0 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Wed, 7 Feb 2024 12:34:59 -0500 Subject: [PATCH] chore: put login fixture in a dedicated conftest --- umap/tests/integration/conftest.py | 18 ++++++++++++++++++ umap/tests/integration/test_dashboard.py | 22 +--------------------- umap/tests/integration/test_owned_map.py | 17 ----------------- 3 files changed, 19 insertions(+), 38 deletions(-) create mode 100644 umap/tests/integration/conftest.py diff --git a/umap/tests/integration/conftest.py b/umap/tests/integration/conftest.py new file mode 100644 index 00000000..2b4ddca1 --- /dev/null +++ b/umap/tests/integration/conftest.py @@ -0,0 +1,18 @@ +import pytest + + +@pytest.fixture +def login(context, settings, live_server): + def do_login(user): + # TODO use storage state to do login only once per session + # https://playwright.dev/python/docs/auth + settings.ENABLE_ACCOUNT_LOGIN = True + page = context.new_page() + page.goto(f"{live_server.url}/en/") + page.locator(".login").click() + page.get_by_placeholder("Username").fill(user.username) + page.get_by_placeholder("Password").fill("123123") + page.locator('#login_form input[type="submit"]').click() + return page + + return do_login diff --git a/umap/tests/integration/test_dashboard.py b/umap/tests/integration/test_dashboard.py index 26d68295..2698e0a3 100644 --- a/umap/tests/integration/test_dashboard.py +++ b/umap/tests/integration/test_dashboard.py @@ -1,5 +1,3 @@ -from time import sleep - import pytest from playwright.sync_api import expect @@ -8,30 +6,12 @@ from umap.models import Map pytestmark = pytest.mark.django_db -@pytest.fixture -def login(context, settings, live_server): - def do_login(user): - # TODO use storage state to do login only once per session - # https://playwright.dev/python/docs/auth - settings.ENABLE_ACCOUNT_LOGIN = True - page = context.new_page() - page.goto(f"{live_server.url}/en/") - page.locator(".login").click() - page.get_by_placeholder("Username").fill(user.username) - page.get_by_placeholder("Password").fill("123123") - page.locator('#login_form input[type="submit"]').click() - sleep(1) # Time for ajax login POST to proceed - return page - - return do_login - - def test_owner_can_delete_map_after_confirmation(map, live_server, login): page = login(map.owner) page.goto(f"{live_server.url}/en/me") delete_button = page.get_by_title("Delete") expect(delete_button).to_be_visible() page.on("dialog", lambda dialog: dialog.accept()) - with page.expect_response(f"/map/{map.pk}/update/delete/"): + with page.expect_response(f"/en/map/{map.pk}/update/delete/"): delete_button.click() assert Map.objects.all().count() == 0 diff --git a/umap/tests/integration/test_owned_map.py b/umap/tests/integration/test_owned_map.py index a0767560..f6b84584 100644 --- a/umap/tests/integration/test_owned_map.py +++ b/umap/tests/integration/test_owned_map.py @@ -8,23 +8,6 @@ from umap.models import DataLayer, Map pytestmark = pytest.mark.django_db -@pytest.fixture -def login(context, settings, live_server): - def do_login(user): - # TODO use storage state to do login only once per session - # https://playwright.dev/python/docs/auth - settings.ENABLE_ACCOUNT_LOGIN = True - page = context.new_page() - page.goto(f"{live_server.url}/en/") - page.locator(".login").click() - page.get_by_placeholder("Username").fill(user.username) - page.get_by_placeholder("Password").fill("123123") - page.locator('#login_form input[type="submit"]').click() - return page - - return do_login - - def test_map_update_with_owner(map, live_server, login): page = login(map.owner) page.goto(f"{live_server.url}{map.get_absolute_url()}")