-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_models.py
49 lines (36 loc) · 1.44 KB
/
test_models.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
"""
Tests for the database models.
"""
from datetime import datetime
def test_new_quote(new_quote):
"""Test the creation of a new quote.
GIVEN a Quote model
WHEN a new Quote is created
THEN check the quote_text, author_name, author_image and tags fields are defined correctly
"""
assert new_quote.quote_text == "Quote."
assert new_quote.author_name == "Author"
assert new_quote.author_image == "https://www.goodreads.com/quotes/tag/books"
assert "test-tag" in new_quote.tags
def test_new_user(new_user):
"""Test the creation of a new user.
GIVEN a User model
WHEN a new User is created
THEN check the username, email, password, active and roles fields are defined correctly
"""
assert new_user.username == "user"
assert new_user.email == "[email protected]"
assert new_user.password != "user"
assert new_user.active is True
assert "basic" in new_user.roles
def test_new_token(new_user, new_access_token):
"""Test the creation of a new token.
GIVEN a TokenBlacklist model
WHEN a new access token is created
THEN check the jti, token_type, user, revoked and expires fields are defined correctly
"""
assert new_access_token.jti == "jti_example"
assert new_access_token.token_type == "access"
assert new_access_token.user.id == new_user.id
assert new_access_token.revoked is False
assert new_access_token.expires == datetime.fromtimestamp(1608057500)