diff options
Diffstat (limited to 'tests/test_db_story.py')
-rw-r--r-- | tests/test_db_story.py | 105 |
1 files changed, 93 insertions, 12 deletions
diff --git a/tests/test_db_story.py b/tests/test_db_story.py index 941372d..66f46fc 100644 --- a/tests/test_db_story.py +++ b/tests/test_db_story.py @@ -18,28 +18,28 @@ class TestDBStory(unittest.TestCase): story.DB()._del(all=True) def test_all(self): - all = [r for r in story.DB().all()] + all = [r for r in story.DB()._all()] self.assertEqual(len(all), 0, "should not have row! found: %s" % len(all)) def test_add(self): # second row - key = story.Key(None, 'helo', 'image', 'helo.png') + key = story.Key(None, 'helo.png', 'image/png', '12345') story.DB().add(key) - all = [r for r in story.DB().all()] + all = [r for r in story.DB()._all()] self.assertEqual(len(all), 1, "should have 1 row! found: %s" % len(all)) self.assertEqual(all[0], key, "not the same row: %s" % all[0]) # second row - key = story.Key(None, 'hola', 'image', 'hola.png') + key = story.Key(None, 'hola.png', 'image/png', '67890') story.DB().add(key) - all = [r for r in story.DB().all()] + all = [r for r in story.DB()._all()] self.assertEqual(len(all), 2, "should have 1 row! found: %s" % len(all)) self.assertEqual(all[1], key, "not the same row: %s" % all[1]) def test_get(self): - key = story.Key(None, 'helo', 'image', 'helo.png') + key = story.Key(None, 'helo.png', 'image/png', '12345') story.DB().add(key) all = [r for r in story.DB().get(story.Key(name='helo'))] self.assertEqual(len(all), 1, @@ -47,16 +47,96 @@ class TestDBStory(unittest.TestCase): self.assertEqual(all[0], key, "not the same row: %s" % all[0]) def test_update(self): - key = story.Key(None, 'helo', 'image', 'helo.png', layer=1) + key = story.Key(None, 'helo.png', 'image/png', '12345', layer=1) story.DB().add(key) - all = [r for r in story.DB().all()] - key = story.Key(id=all[0].id, name='hola', media='hola.png', layer=2) + all = [r for r in story.DB()._all()] + key = story.Key(id=all[0].id, title='hola.png', timestamp='12345', layer=2) story.DB().update(key) - all = [r for r in story.DB().all()] + all = [r for r in story.DB()._all()] self.assertEqual(len(all), 1, "should have 1 row! found: %s" % len(all)) - exp_key = story.Key(None, 'hola', 'image', 'hola.png', layer=2) - self.assertEqual(all[0], exp_key, "not the same row: %s" % all[0]) + # NOTE: title, mime_type and timestamp can not be changed + exp_key = story.Key(None, 'helo.png', 'image/png', '12345', layer=2) + self.assertEqual(all[0], exp_key, + "not the same row\n`%s`\ninstead of\n`%s`" % (all[0], exp_key)) + + def test_duration(self): + story.DB().add(story.Key(title='helo', mime_type='img', timestamp='12345', time=0)) + story.DB().add(story.Key(title='helo', mime_type='img', timestamp='12345', time=4)) + story.DB().add(story.Key(title='helo', mime_type='img', timestamp='12345', time=5)) + story.DB().add(story.Key(title='helo', mime_type='img', timestamp='12345', time=6)) + _all = [r for r in story.DB()._all()] + # duration update +2 + # print '+2 ...' + _all[0].update_duration(2) + _all = [r for r in story.DB()._all()] + self.assertEqual(len(_all), 6, + "should have 6 rows! found: %s" % _all) + self.assertEqual(_all[4].time, 1) + self.assertEqual(_all[5].time, 2) + self.assertEqual(_all[4].duration, 1) + self.assertEqual(_all[5].duration, 0) + self.assertEqual(_all[1].duration, 2, _all[1]) + self.assertEqual(_all[2].duration, 1, _all[2]) + self.assertEqual(_all[3].duration, 0, _all[3]) + # duration update +3 + # print '+3 ...' + _all[0].update_duration(3) + _all = [r for r in story.DB()._all()] + self.assertEqual(len(_all), 7, + "should have 7 rows! found: %s" % len(_all)) + self.assertEqual(_all[4].time, 1) + self.assertEqual(_all[5].time, 2) + self.assertEqual(_all[6].time, 3) + self.assertEqual(_all[4].duration, 2) + self.assertEqual(_all[5].duration, 1) + self.assertEqual(_all[6].duration, 0) + self.assertEqual(_all[1].duration, 2) + self.assertEqual(_all[2].duration, 1) + self.assertEqual(_all[3].duration, 0) + # duration update +5 + # print '+5 ...' + _all[0].update_duration(5) + _all = [r for r in story.DB()._all()] + self.assertEqual(len(_all), 7, + "should have 7 rows! found: %s" % len(_all)) + self.assertEqual(_all[4].time, 1) + self.assertEqual(_all[5].time, 2) + self.assertEqual(_all[6].time, 3) + self.assertEqual(_all[1].time, 4) + self.assertEqual(_all[2].time, 5) + self.assertEqual(_all[3].time, 6) + self.assertEqual(_all[4].duration, 4) + self.assertEqual(_all[5].duration, 3) + self.assertEqual(_all[6].duration, 2) + self.assertEqual(_all[1].duration, 1) + self.assertEqual(_all[2].duration, 0) + self.assertEqual(_all[3].duration, 0) + # duration update +3 again + # print '+3 again ...' + _all[0].update_duration(3) + _all = [r for r in story.DB()._all()] + self.assertEqual(len(_all), 5, + "should have 5 rows! found: %s" % _all) + self.assertEqual(_all[2].time, 1) + self.assertEqual(_all[3].time, 2) + self.assertEqual(_all[4].time, 3) + self.assertEqual(_all[1].time, 6) + self.assertEqual(_all[2].duration, 2) + self.assertEqual(_all[3].duration, 1) + self.assertEqual(_all[4].duration, 0) + self.assertEqual(_all[1].duration, 0) + # duration update +0 back + # print '+0 back ...' + _all[0].update_duration(0) + _all = [r for r in story.DB()._all()] + self.assertEqual(len(_all), 2, + "should have 4 rows! found: %s" % len(_all)) + self.assertEqual(_all[0].time, 0) + self.assertEqual(_all[1].time, 6) + self.assertEqual(_all[0].duration, 0) + self.assertEqual(_all[1].duration, 0) + def suite(): suite = unittest.TestSuite() @@ -64,6 +144,7 @@ def suite(): suite.addTest(TestDBStory('test_add')) suite.addTest(TestDBStory('test_get')) suite.addTest(TestDBStory('test_update')) + suite.addTest(TestDBStory('test_duration')) return suite |