forked from soeirosantos/bookmarkery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
57 lines (37 loc) · 1.74 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
import unittest
import tornado.database
from bookmarks import Labels, Bookmarks
class IntegrationTest(unittest.TestCase):
def setUp(self):
self.conn = tornado.database.Connection(
host="/opt/lampp/var/mysql/mysql.sock", database="bookmarkery_db_test",
user="root", password="")
def tearDown(self):
self.conn.execute("truncate table labels")
self.conn.execute("truncate table bookmarks")
def get_labels(self):
return Labels(self.conn)
def get_bookmarks(self):
return Bookmarks(self.conn)
def test_get_or_insert_label(self):
first_label_name = "Python"
result_label = self.get_labels().get_or_insert(first_label_name)
assert first_label_name == result_label.name
total_before_insert = self.get_labels().count()
another_result_label = self.get_labels().get_or_insert(first_label_name)
total_after_insert = self.get_labels().count()
the_same_total = total_before_insert == total_after_insert
the_same_label = result_label.id == another_result_label.id
assert the_same_total and the_same_label
def test_delete_label(self):
label_name = "Trip"
result_label = self.get_labels().get_or_insert(label_name)
removed_id = self.get_labels().delete(result_label.id)
label = self.get_labels().get_by_id(removed_id)
assert label == None
def test_insert_plain_bookmark(self):
bookmark = {"name":"Tornado", "url":"http://tornadoweb.org", "description":"site oficial Tornado", "labels": ""}
rowid = self.get_bookmarks().insert(bookmark)
assert rowid != None and rowid > 0
if __name__ == "__main__":
unittest.main()