-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
63 lines (49 loc) · 1.23 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
from random import randint
from unittest.mock import ANY
from django.contrib.auth.models import AnonymousUser, User
from django.contrib.sessions.middleware import SessionMiddleware
from model_bakery import baker
from pytest import fixture
from backend.brands.models import Brand
from backend.products.models import Product
@fixture
def user(db):
"""
A authenticated user.
"""
username = "username"
password = "password"
user = baker.make(
User,
username=username,
first_name="Test",
last_name="User",
email=f"{username}@email.com",
)
user.set_password(password)
user.save()
return user
@fixture
def brands(db):
"""
Return a list with a lot of brands.
"""
return baker.make(Brand, _quantity=64)
@fixture
def products(db, brands):
"""
Return a list with a lot of products.
"""
return baker.make(Product, types=Product.Types.values, brand=brands[randint(1, len(brands))], _quantity=512)
@fixture
def anonymous_user(db):
"""
A instance of AnonymousUser.
"""
return AnonymousUser()
@fixture
def session_middleware():
"""
A mock instance of SessionMiddleware.
"""
return SessionMiddleware(get_response=ANY)