-
Notifications
You must be signed in to change notification settings - Fork 0
/
database_test.py
71 lines (59 loc) · 3.15 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
import unittest
from Place import Place
from Stage import Stage
from database import Database
class DatabaseTestCase(unittest.TestCase):
def setUp(self) -> None:
self.db = Database()
self.db.reset_user(1)
self.db.reset_user(2)
def test_adding(self):
self.assertFalse(self.db.has_user(1))
self.db.set_user_stage(1, Stage.START)
self.db.add_place(1, Place("Good restaurant", 65.13, 66.14))
self.assertTrue(self.db.has_user(1))
def test_places(self):
self.db.add_place(1, Place("Good restaurant", 65.13, 66.14))
self.db.add_place(1, Place("Very Good restaurant", 62.12, 66.14))
places = self.db.get_places(1)
self.assertIn(Place("Good restaurant", 65.13, 66.14), places)
self.assertIn(Place("Very Good restaurant", 62.12, 66.14), places)
self.assertEqual(self.db.get_place_by_name(1, "Good restaurant"),
Place("Good restaurant", 65.13, 66.14))
def test_removing_user(self):
self.db.set_user_stage(1, Stage.START)
self.db.add_place(1, Place("Good restaurant", 65.13, 66.14))
self.db.add_place(1, Place("Very Good restaurant", 62.12, 66.14))
self.assertTrue(self.db.has_user(1))
self.db.reset_user(1)
self.assertFalse(self.db.has_user(1))
def test_removing_place(self):
self.db.add_place(1, Place("Good restaurant", 65.13, 66.14))
self.db.add_place(1, Place("Very Good restaurant", 62.12, 66.14))
self.db.add_place(2, Place("Very Good restaurant", 62.12, 66.14))
self.db.remove_place(1, Place("Very Good restaurant", 62.12, 66.14))
places = self.db.get_places(1)
self.assertIn(Place("Good restaurant", 65.13, 66.14), places)
self.assertNotIn(Place("Very Good restaurant", 62.12, 66.14), places)
self.assertIn(Place("Very Good restaurant", 62.12, 66.14), self.db.get_places(2))
def test_staging(self):
self.db.set_user_stage(1, Stage.START)
self.db.set_user_stage(2, Stage.START)
self.assertEqual(self.db.get_user_stage(1), Stage.START)
self.assertEqual(self.db.get_user_stage(1), Stage.START)
self.db.set_user_stage(1, Stage.ADDING_PLACE_NAME)
self.assertEqual(self.db.get_user_stage(1), Stage.ADDING_PLACE_NAME)
self.assertEqual(self.db.get_user_stage(2), Stage.START)
self.db.set_user_stage(1, Stage.ADDING_PLACE_LOCATION)
self.assertEqual(self.db.get_user_stage(1), Stage.ADDING_PLACE_LOCATION)
def test_staging_names(self):
self.db.set_staged_place_name(1, "My favourite restaurant")
self.assertEqual(self.db.get_staged_place_name(1), "My favourite restaurant")
self.db.set_staged_place_name(2, "My very favourite restaurant")
self.assertEqual(self.db.get_staged_place_name(2), "My very favourite restaurant")
self.assertEqual(self.db.get_staged_place_name(1), "My favourite restaurant")
self.db.clean_staged_place_name(1)
self.assertEqual(self.db.get_staged_place_name(2), "My very favourite restaurant")
self.assertIsNone(self.db.get_staged_place_name(1))
if __name__ == '__main__':
unittest.main()