-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathconftest.py
More file actions
99 lines (67 loc) · 2.35 KB
/
conftest.py
File metadata and controls
99 lines (67 loc) · 2.35 KB
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
import pytest
import uuid
from tokens.models import TokenCategory
from tokens.models import TokenFind
from tokens.models import Token
@pytest.fixture
def token_category_factory(db):
"""Fixture for returning a factory function."""
def create_token_category(persist=False, **kwargs) -> TokenCategory:
"""Create a TokenCategory instance. Saves to DB if persist=True."""
defaults = {
"name": "token-category",
"description": "token category description",
}
defaults.update(**kwargs)
category = TokenCategory(**defaults)
if persist:
category.save()
return category
return create_token_category
@pytest.fixture
def token_category(token_category_factory) -> TokenCategory:
"""Fixture for a single TokenCategory"""
return token_category_factory(persist=True)
@pytest.fixture
def token_factory(db, camp, token_category):
"""Fixture for returning a factory function."""
def create_token(persist=False, **kwargs) -> Token:
"""Create a Token instance. Saves to DB if persist=True."""
defaults = {
"category": token_category,
"camp": camp,
"token": str(uuid.uuid4()).replace('-', ''),
"hint": "token-hint",
"description": "token description",
"active": True,
"valid_when": None,
}
defaults.update(**kwargs)
token = Token(**defaults)
if persist:
token.save()
return token
return create_token
@pytest.fixture
def token(token_factory) -> Token:
"""Fixture for returning a single active token"""
return token_factory(persist=True)
@pytest.fixture
def token_find_factory(db, token, users):
"""Fixture for returning a factory function."""
def create_token_find(persist=False, **kwargs) -> TokenFind:
"""Create a TokenFind instance. Saves to DB if persist=True."""
defaults = {
"token": token,
"user": users[0],
}
defaults.update(**kwargs)
token_find = TokenFind(**defaults)
if persist:
token_find.save()
return token_find
return create_token_find
@pytest.fixture
def token_find(token_find_factory) -> TokenFind:
"""Fixture for returning a single token find."""
return token_find_factory(persist=True)