-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
110 lines (83 loc) · 2.52 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import pytest
from django.contrib.auth import get_user_model
from pytest_factoryboy import register
from rest_framework.test import APIClient
from books.tests.factories import (AuthorFactory, BookFactory, CategoryFactory,
UserFactory, ReviewFactory)
register(UserFactory)
register(AuthorFactory)
register(CategoryFactory)
register(BookFactory)
register(ReviewFactory)
User = get_user_model()
@pytest.fixture()
def api_client():
return APIClient()
@pytest.fixture()
def admin_user(api_client):
return api_client.force_authenticate(user=User(is_staff=True))
@pytest.fixture()
def normal_user(api_client):
return api_client.force_authenticate(user=User(is_active=True))
@pytest.fixture()
def create_category(db, category_factory):
create_category = category_factory.create()
return create_category
@pytest.fixture()
def create_author(db, author_factory):
create_author = author_factory.create()
return create_author
@pytest.fixture()
def create_book(db, book_factory):
create_book = book_factory.create()
return create_book
@pytest.fixture()
def book_payload(db, create_book, create_author):
author = create_author
return {
"id": create_book.id,
"author": author,
"category": create_book.category,
"title": "title",
"description": "description",
"price": create_book.price,
"publisher": "publisher",
"language": "English",
"pages": 120,
"isbn": create_book.isbn,
"cover_image": create_book.cover_image,
}
@pytest.fixture()
def invalid_book_payload(db, create_book, create_author):
author = create_author
return {
"id": create_book.id,
"author": author,
"category": create_book.category,
"title": "",
"description": "description",
"price": 32.32,
"publisher": "publisher",
"language": "English",
"pages": 120,
"isbn": create_book.isbn,
"cover_image": create_book.cover_image,
}
@pytest.fixture()
def author_payload(db):
author = {
"id": 2,
"name": "John Smith",
"pseudonym": "Johns",
"about": "about",
}
return author
@pytest.fixture()
def create_author(db, author_factory):
create_author = author_factory.create()
return create_author
@pytest.fixture()
def create_review(db, review_factory, user_factory):
user = user_factory.create(is_active=True)
create_review = review_factory.create(user=user)
return create_review