-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
65 lines (46 loc) · 1.54 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
import factory
import pytest
from pytest_factoryboy import register
from board.models.board import Notice
from users.models import User
from users.tests.factories import FakeUserFactory, StaticUserFactory
register(StaticUserFactory)
register(FakeUserFactory)
# help to use session scope with fixture of db and django_db
# @pytest.fixture(scope='session')
# def django_db_setup(django_db_setup, django_db_blocker):
# pass
@pytest.fixture(scope="function")
def static_user(db, static_user_factory) -> object:
# user = static_user_factory.build()
user = static_user_factory.create()
return user
@pytest.fixture(scope="function")
def user(client: object) -> object:
# Create a user
User.objects.create_user(
username="testuser",
password="password",
)
client.login(username="testuser", password="password")
return client
@pytest.fixture(scope="function")
def staff(client: object) -> object:
# Create a user
User.objects.create_user(
username="testuser",
password="password",
is_staff=True,
)
client.login(username="testuser", password="password")
return client
class ContentFactory(factory.django.DjangoModelFactory):
class Meta:
model = Notice
title = factory.Faker("sentence")
content = factory.Faker("paragraph")
@pytest.fixture(scope="function")
def create_content(static_user) -> object:
# Create a content fixture for app A that depends on the `create_user` fixture
content = ContentFactory(author=static_user)
return content