-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
64 lines (47 loc) · 2.02 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from unittest.mock import patch
import pytest
from django.contrib.auth import get_user_model
from playwright.sync_api import expect
from core.models import Agent, Structure, Contact
from model_bakery import baker
User = get_user_model()
@pytest.fixture
def page(page):
timeout = 4_000
page.set_default_navigation_timeout(timeout)
page.set_default_timeout(timeout)
yield page
@pytest.fixture(autouse=True)
def set_django_allow_async_unsafe():
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
@pytest.fixture(autouse=True)
def mocked_authentification_user(db):
user = baker.make(get_user_model(), email="[email protected]")
user.is_active = True
user.save()
structure = baker.make(Structure, niveau2="Structure Test", libelle="Structure Test")
Contact.objects.create(structure=structure, email="[email protected]")
agent = Agent.objects.create(user=user, prenom="John", nom="Doe", structure=structure, structure_complete="AC/DC")
Contact.objects.create(agent=agent, email="[email protected]")
def mocked(self, request):
request.user = user
return self.get_response(request)
with patch("seves.middlewares.LoginRequiredMiddleware.__call__", mocked):
yield user
@pytest.fixture
def choice_js_fill(db, page):
def _choice_js_fill(page, locator, fill_content, exact_name):
page.query_selector(locator).click()
page.wait_for_selector("input:focus", state="visible", timeout=2_000)
page.locator("*:focus").fill(fill_content)
page.get_by_role("option", name=exact_name, exact=True).click()
return _choice_js_fill
@pytest.fixture
def choice_js_cant_pick(db, page):
def _choice_js_cant_pick(page, locator, fill_content, exact_name):
page.query_selector(locator).click()
page.wait_for_selector("input:focus", state="visible", timeout=2_000)
page.locator("*:focus").fill(fill_content)
expect(page.get_by_role("option", name=exact_name, exact=True)).not_to_be_visible()
return _choice_js_cant_pick