);
insert or ignore into flavors values
+("tea", 7),
("espresso", 2),
("espresso lungo", 3),
("cappuccino", 1),
;
""")
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')),
('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')),
('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'));
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)
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)
])
finally:
delete_test_db(TESTDB_FILENAME)
+
+ def test_all_mate_list(self):
+ create_test_db(TESTDB_FILENAME)
+ try:
+ db = Db(TESTDB_FILENAME)
+ drunk = db.getDrunkList(
+ "Club-Mate 0,5 l;Club-Mate 0,33 l",
+ self.lwstr,
+ self.tdystr
+ )
+ self.assertEqual(drunk, {
+ "tester": [4, 4],
+ "newer": [0, 2],
+ "clone": [1, 2],
+ })
+ finally:
+ delete_test_db(TESTDB_FILENAME)