-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
71 lines (54 loc) · 1.89 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
68
69
70
71
import pytest
from django.contrib.auth import get_user_model
from pytest_factoryboy import register
from shop_account.tests.factory import UserFactory
from shop_products.tests.factory import ProductsFactory, CategoriesFactory
from selenium import webdriver
User = get_user_model()
# method 2 (better class based option)
register(UserFactory) # can be accessed user_factory
register(ProductsFactory) # can be accessed products_factory
register(CategoriesFactory) # can be accessed categories_factory
@pytest.fixture
def create_product_factory_boy(db, products_factory):
return products_factory.create()
@pytest.fixture
def create_category_factory_boy(db, categories_factory):
return categories_factory.create()
@pytest.fixture
def factory_boy_superuser(user_factory):
return user_factory.build()
# method 1
@pytest.fixture
def user_model_factory(db):
def create_user(
username: str,
password: str = 'abc',
is_staff: bool = False,
is_superuser: bool = False,
first_name: str = 'firstName',
last_name: str = 'lastName',
email: str = '[email protected]',
):
return User.objects.create_user(
username=username,
password=password,
is_staff=is_staff,
is_superuser=is_superuser,
first_name=first_name,
last_name=last_name,
email=email,
)
return create_user
@pytest.fixture
def create_superuser(db, user_model_factory):
return user_model_factory(username='aabc', password='123', email='[email protected]', is_superuser=True)
@pytest.fixture
def create_staff_user(db, user_model_factory):
return user_model_factory(username='aabc', password='123', email='[email protected]', is_staff=True)
@pytest.fixture(scope='class')
def chrome_setup(request):
browser = webdriver.Chrome()
request.cls.browser = browser
yield
browser.quit()