-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
34 lines (25 loc) · 905 Bytes
/
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
import pytest
from pytest_factoryboy import register
from django.test import RequestFactory
from django.contrib.sessions.middleware import SessionMiddleware
from django.contrib.auth.middleware import AuthenticationMiddleware
from core_apps.users.tests.factories import UserFactory
register(UserFactory)
@pytest.fixture
def normal_user(db, user_factory):
new_user = user_factory.create()
return new_user
@pytest.fixture
def super_user(db, user_factory):
new_user = user_factory.create(is_superuser=True, is_staff=True)
return new_user
@pytest.fixture
def mock_request():
factory = RequestFactory()
request = factory.get("/")
middleware = SessionMiddleware(lambda req: None)
middleware.process_request(request)
request.session.save()
auth_middleware = AuthenticationMiddleware(lambda req: None)
auth_middleware.process_request(request)
return request