forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tables.py
More file actions
69 lines (49 loc) · 1.8 KB
/
test_tables.py
File metadata and controls
69 lines (49 loc) · 1.8 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
import asyncio
from unittest import TestCase
from piccolo.apps.user.tables import BaseUser
class TestCreateUserTable(TestCase):
def test_create_user_table(self):
"""
Make sure the table can be created.
"""
exception = None
try:
BaseUser.create_table().run_sync()
except Exception as e:
exception = e
else:
BaseUser.alter().drop_table().run_sync()
if exception:
raise exception
self.assertFalse(exception)
class TestHashPassword(TestCase):
def test_hash_password(self):
pass
class TestLogin(TestCase):
def setUp(self):
BaseUser.create_table().run_sync()
def tearDown(self):
BaseUser.alter().drop_table().run_sync()
def test_login(self):
username = "bob"
password = "Bob123$$$"
email = "bob@bob.com"
user = BaseUser(username=username, password=password, email=email)
save_query = user.save()
save_query.run_sync()
authenticated = asyncio.run(BaseUser.login(username, password))
self.assertTrue(authenticated is not None)
authenticated = asyncio.run(BaseUser.login(username, "blablabla"))
self.assertTrue(not authenticated)
def test_update_password(self):
username = "bob"
password = "Bob123$$$"
email = "bob@bob.com"
user = BaseUser(username=username, password=password, email=email)
user.save().run_sync()
authenticated = BaseUser.login_sync(username, password)
self.assertTrue(authenticated is not None)
new_password = "XXX111"
BaseUser.update_password_sync(username, new_password)
authenticated = BaseUser.login_sync(username, new_password)
self.assertTrue(authenticated is not None)