-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
67 lines (49 loc) · 1.81 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
65
66
67
from django.test import RequestFactory
import pytest
from published.constants import NEVER_AVAILABLE
from pytest_factoryboy import register
from selenium import webdriver
from apps.accounts.tests.factories import UserFactory, UserNoPasswordFactory
from apps.content.tests.factories import PageFactory
from apps.directory.tests.factories import ProfileFactory
from apps.events.tests.factories import EventFactory
from foxtail_blog.tests.factories import PostFactory
# accounts
register(UserFactory, "user")
register(UserFactory, "second_user")
register(UserFactory, "third_user")
register(UserNoPasswordFactory, "user_without_password")
# blog
register(PostFactory, "post")
register(PostFactory, "second_post")
register(PostFactory, "hidden_post", publish_status=NEVER_AVAILABLE)
# content
register(PageFactory)
# directory
register(ProfileFactory)
# events
register(EventFactory)
@pytest.fixture
def request_factory() -> RequestFactory:
return RequestFactory()
@pytest.fixture(scope='module')
def driver(request):
"""Provide a selenium webdriver instance."""
options = webdriver.ChromeOptions()
options.add_argument('headless')
browser = webdriver.Chrome(options=options)
yield browser
browser.quit()
@pytest.fixture
def authenticated_driver(db, driver, client, live_server, user, settings):
"""Return a browser instance with logged-in user session."""
settings.CSRF_COOKIE_SECURE = False
settings.SESSION_COOKIE_SECURE = False
settings.CSRF_COOKIE_NAME = 'csrftoken'
settings.SESSION_COOKIE_NAME = 'sessionid'
client.force_login(user)
cookie = client.cookies[settings.SESSION_COOKIE_NAME]
driver.get(live_server.url)
driver.add_cookie({'name': settings.SESSION_COOKIE_NAME, 'value': cookie.value, 'secure': False, 'path': '/'})
driver.refresh()
return driver