]> rtime.felk.cvut.cz Git - hubacji1/coffee-getter.git/blobdiff - ut/test_db.py
Add top drinks ut
[hubacji1/coffee-getter.git] / ut / test_db.py
index f059c2ba0a1184a7662360e9c0b776d26f976012..505855d3be58a530077e2b70c42b277fb07ba0a6 100644 (file)
@@ -26,6 +26,7 @@ ord integer not null default 999
 );
 
 insert or ignore into flavors values
+("tea", 7),
 ("espresso", 2),
 ("espresso lungo", 3),
 ("cappuccino", 1),
@@ -52,9 +53,9 @@ insert or ignore into days values
 ;
     """)
     cur.executescript("""
-INSERT INTO users VALUES('1111','tester');
-INSERT INTO users VALUES('2222','newer');
-INSERT INTO users VALUES('3333','clone');
+INSERT OR IGNORE INTO users VALUES('1111','tester');
+INSERT OR IGNORE INTO users VALUES('2222','newer');
+INSERT OR IGNORE INTO users VALUES('3333','clone');
 INSERT INTO coffees (id, flavor, time) VALUES
 ('1111', 'espresso lungo', datetime('now', 'localtime', '-99 seconds')),
 ('1111', 'Club-Mate 0,5 l', datetime('now', 'localtime', '-99 seconds')),
@@ -62,6 +63,7 @@ INSERT INTO coffees (id, flavor, time) VALUES
 ('1111', 'espresso lungo', datetime('now', 'localtime', '-95 second')),
 ('1111', 'Club-Mate 0,5 l', datetime('now', 'localtime', '-95 second')),
 ('1111', 'Club-Mate 0,33 l', datetime('now', 'localtime', '-95 second')),
+('1111', 'tea', datetime('now', 'localtime', '-95 second')),
 ('1111', 'espresso lungo', datetime('now', 'localtime', '-90 second')),
 ('1111', 'Club-Mate 0,5 l', datetime('now', 'localtime', '-90 second')),
 ('1111', 'Club-Mate 0,33 l', datetime('now', 'localtime', '-90 second')),
@@ -74,6 +76,8 @@ INSERT INTO coffees (id, flavor, time) VALUES
 ('2222', 'Club-Mate 0,33 l', datetime('now', 'localtime', '-95 second')),
 ('3333', 'espresso lungo', datetime('now', 'localtime', '-99 seconds')),
 ('3333', 'Club-Mate 0,33 l', datetime('now', 'localtime', '-99 seconds')),
+('3333', 'tea', datetime('now', 'localtime', '-99 second')),
+('3333', 'tea', datetime('now', 'localtime', '-95 second')),
 ('3333', 'espresso lungo', datetime('now', 'localtime', '-95 second')),
 ('3333', 'Club-Mate 0,5 l', datetime('now', 'localtime', '-95 second')),
 ('3333', 'Club-Mate 0,33 l', datetime('now', 'localtime', '-95 second'));
@@ -104,6 +108,23 @@ class FailCoffeeDb(TestCase):
     def test_db_path_not_set(self):
         self.assertRaises(FileNotSetError, Db)
 
+class TopDrinks(TestCase):
+    def setUp(self):
+        create_test_db(TESTDB_FILENAME)
+        self.db = Db(TESTDB_FILENAME)
+
+    def tearDown(self):
+        delete_test_db(TESTDB_FILENAME)
+
+    def test_top_drinks(self):
+        top = self.db.get_top_drinks()
+        assert top == [
+            ("espresso lungo", 8),
+            ("Club-Mate 0,33 l", 8),
+            ("Club-Mate 0,5 l", 5),
+            ("tea", 3),
+        ]
+
 class TopMateDrinkers(TestCase):
     def test_test_top_mate_drinkers(self):
         create_test_db(TESTDB_FILENAME)
@@ -163,6 +184,21 @@ class TopMateDrinkers(TestCase):
             topsorted
         )
 
+class TopTeaDrinkers(TestCase):
+    def setUp(self):
+        create_test_db(TESTDB_FILENAME)
+        self.db = Db(TESTDB_FILENAME)
+
+    def tearDown(self):
+        delete_test_db(TESTDB_FILENAME)
+
+    def test_top_tea_drinkers(self):
+        top = self.db.get_top_tea_drinkers()
+        assert top == [
+            ("clone", 2),
+            ("tester", 1),
+        ]
+
 class DrunkSum(TestCase):
     tdy = datetime.now()
     tdy += timedelta(days=1)
@@ -261,7 +297,7 @@ class DrunkSum(TestCase):
             )
             self.assertEqual(drunk, {
                 "tester": [4, 4],
-                "newer": [2],
+                "newer": [0, 2],
                 "clone": [1, 2],
             })
         finally: