-
Notifications
You must be signed in to change notification settings - Fork 1
/
database_test.py
75 lines (54 loc) · 2.93 KB
/
database_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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import unittest
from database import Database
class DatabaseTest(unittest.TestCase):
def setUp(self):
self.Database = Database("testing_db")
self.db = self.Database.db
self.Database.start_connection()
def test_valid_table(self):
tables = self.db.get_tables()
self.assertEqual(sorted(tables), ['resume'])
cols_res = self.db.get_columns('resume')
self.assertTrue(len(cols_res) == 3)
def test_push_resume(self):
resume = "imgur.com/iamaresume"
self.assertTrue(self.Database.push_resume("Nik", resume).is_success)
self.assertEqual(self.Database.Resume.select().count(), 1)
self.assertEqual(self.Database.Resume.get(self.Database.Resume.id == 1).resume, resume)
self.assertEqual(self.Database.Resume.get(self.Database.Resume.id == 1).user_id, "Nik")
self.assertTrue(self.Database.push_resume("Gopher", resume).is_success)
self.assertEqual(self.Database.Resume.select().count(), 2)
self.assertFalse(self.Database.push_resume("Gopher", resume).is_success)
self.assertEqual(self.Database.Resume.select().count(), 2)
# Testing this post integrity error
self.assertTrue(self.Database.push_resume("iNirvana", resume).is_success)
self.assertEqual(self.Database.Resume.select().count(), 3)
def test_pop_resume(self):
first_resume = "imgur.com/iamaresume"
second_resume = "imgur.com/iamalsoaresume"
self.assertTrue(self.Database.push_resume("Nik", first_resume).is_success)
self.assertTrue(self.Database.push_resume("Gopher", second_resume).is_success)
self.assertEqual(self.Database.Resume.select().count(), 2)
result1 = self.Database.pop_resume()
self.assertEqual(self.Database.Resume.select().count(), 1)
result2 = self.Database.pop_resume()
self.assertEqual(self.Database.Resume.select().count(), 0)
self.assertTrue(result1.is_success)
self.assertTrue(result2.is_success)
self.assertEqual(result1.data, ("Nik", first_resume))
self.assertEqual(result2.data, ("Gopher", second_resume))
def test_delete_resume(self):
resume = "imgur.com/iamaresume"
self.assertTrue(self.Database.push_resume("Nik", resume).is_success)
self.assertTrue(self.Database.push_resume("Gopher", resume).is_success)
self.assertTrue(self.Database.push_resume("iNirvana", resume).is_success)
self.assertEqual(self.Database.Resume.select().count(), 3)
self.assertTrue(self.Database.delete_resume("Gopher").is_success)
self.assertEqual(self.Database.Resume.select().count(), 2)
self.assertFalse(self.Database.delete_resume("Gopher").is_success)
self.assertEqual(self.Database.Resume.select().count(), 2)
def tearDown(self):
self.db.drop_tables([self.Database.Resume], safe=True)
self.db.close()
if __name__ == '__main__':
unittest.main()