-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
67 lines (57 loc) · 2.37 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
"""Common pytest fixtures"""
from typing import Any, List, Tuple
import pytest
from django.contrib.auth import get_user_model
from movies.models import Movie
DEFAULT_ENGINE = "django.db.backends.sqlite3"
@pytest.fixture(name="fake_user_with_one_movie")
def fake_user_with_one_movie_fixture() -> Tuple[Movie, Any]:
"""pytest fixture for creating one user with one movie"""
User = get_user_model() # pylint: disable=invalid-name
default_password = "password123"
user = User(username="bob")
user.set_password(default_password)
user.save()
movie = Movie.objects.create(
author=user,
title="Harry Potter and the Deathly Hallows: Part 2",
desc="A clash between good and evil awaits as young Harry (Daniel Radcliffe)",
genre="Fantasy",
year="2011",
)
return user, movie
@pytest.fixture(name="fake_user")
def fake_user_fixture():
"""pytest fixture for creating a fake user"""
User = get_user_model() # pylint: disable=invalid-name
default_password = "password123"
user = User(username="bob")
user.set_password(default_password)
user.save()
return user
@pytest.fixture(name="fake_users_with_movies")
def fake_users_with_movies_fixture(
fake_user_with_one_movie,
) -> Tuple[List[Any], List[Movie]]:
"""pytest fixture for creating two users with one movie each"""
first_user, first_movie = fake_user_with_one_movie
# Create another user
User = get_user_model() # pylint: disable=invalid-name
default_password = "password123"
second_user = User(username="alice")
second_user.set_password(default_password)
second_user.save()
second_movie = Movie.objects.create(
author=second_user,
title="Fight Club",
desc="A depressed man (Edward Norton) suffering from insomnia "
"meets a strange soap salesman named "
"Tyler Durden (Brad Pitt) and soon finds himself living in his squalid "
"house after his perfect apartment is destroyed. The two bored men form an "
"underground club with strict rules and fight other men who are fed up with their"
" mundane lives. Their perfect partnership frays when Marla (Helena Bonham Carter),"
" a fellow support group crasher, attracts Tyler's attention.",
genre="Thriller/Drama",
year="1999",
)
return [first_user, second_user], [first_movie, second_movie]