-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
64 lines (43 loc) · 1.33 KB
/
test.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
'''
Database structure is as follows:
users(id, name, email, password_hash, created_at, plevel)
quotes(id, author, year, quote, likes)
reports(id, user_id, quote_id, reason, details, status)
logs(id, user_id, action, message)
likes(user_id, quote_id)
comments(user_id, quote_id, comment)
'''
from quotebook.utils import db, um, qm
from hashlib import sha256
dbm = db
um = um
qm = qm
dbm.reset_db()
# Check all tables are queried correctly
print(dbm.query('SELECT * FROM quotes'))
# Insert data into the users table
for i in ['Alice', 'Bob', 'Charlie']:
um.create_user(i, f"{i}@email.com", sha256('password_hash'.encode()).hexdigest())
# change the email of user with id 1
um.update_user(1, email='new_email@email.com')
# delete the user with id 2
um.delete_user(2)
# create a new user
um.create_user('David', 'david@email.com', sha256('password_hash'.encode()).hexdigest())
# print the user with id 3
print(um.get_user(3))
# Check the data was inserted correctly
print(dbm.query('SELECT * FROM users'))
# add a quote
for i in range(10):
qm.create_quote(f'Author {i}', f'Quote {i}')
# list all quotes
print(qm.search(""))
# like a quote
qm.like_quote(1, 1)
# update a quote
qm.update_quote(2, author='New Author', quote='New Quote 1')
# delete a quote
qm.delete_quote(3)
# search for quotes with "1" in them
print(qm.search('1'))