chore: put login fixture in a dedicated conftest
This commit is contained in:
parent
2af7705d4c
commit
bc8679a597
3 changed files with 19 additions and 38 deletions
18
umap/tests/integration/conftest.py
Normal file
18
umap/tests/integration/conftest.py
Normal file
|
@ -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
|
|
@ -1,5 +1,3 @@
|
||||||
from time import sleep
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from playwright.sync_api import expect
|
from playwright.sync_api import expect
|
||||||
|
|
||||||
|
@ -8,30 +6,12 @@ from umap.models import Map
|
||||||
pytestmark = pytest.mark.django_db
|
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):
|
def test_owner_can_delete_map_after_confirmation(map, live_server, login):
|
||||||
page = login(map.owner)
|
page = login(map.owner)
|
||||||
page.goto(f"{live_server.url}/en/me")
|
page.goto(f"{live_server.url}/en/me")
|
||||||
delete_button = page.get_by_title("Delete")
|
delete_button = page.get_by_title("Delete")
|
||||||
expect(delete_button).to_be_visible()
|
expect(delete_button).to_be_visible()
|
||||||
page.on("dialog", lambda dialog: dialog.accept())
|
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()
|
delete_button.click()
|
||||||
assert Map.objects.all().count() == 0
|
assert Map.objects.all().count() == 0
|
||||||
|
|
|
@ -8,23 +8,6 @@ from umap.models import DataLayer, Map
|
||||||
pytestmark = pytest.mark.django_db
|
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):
|
def test_map_update_with_owner(map, live_server, login):
|
||||||
page = login(map.owner)
|
page = login(map.owner)
|
||||||
page.goto(f"{live_server.url}{map.get_absolute_url()}")
|
page.goto(f"{live_server.url}{map.get_absolute_url()}")
|
||||||
|
|
Loading…
Reference in a new issue