Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/test_db_story.py
blob: 08a8e71e05a82d973b16e3fd5309c64b45d49f5a (plain)
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
# python import - http://docs.python.org/library/unittest.html
import os, sys, unittest

# add lib path to current python path
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

# atoidejouer import
from atoidejouer.db import story
from atoidejouer.tools import storage


class TestDBStory(unittest.TestCase):

    def setUp(self):
        story.DB()

    def tearDown(self):
        story.DB()._del(all=True)

    def test_all(self):
        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', 0, 1, 'helo.png')
        story.DB().add(key)
        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', 0, 2, 'hola.png')
        story.DB().add(key)
        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', 0, 1, 'helo.png')
        story.DB().add(key)
        all = [r for r in story.DB().get(story.Key(name='helo'))]
        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])

    def test_update(self):
        key = story.Key(None, 'helo', 'image', 0, 1, 'helo.png')
        story.DB().add(key)
        all = [r for r in story.DB().all()]
        key = story.Key(id=all[0].id, name='hola', layer=2, media='hola.png')
        story.DB().update(key)
        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', 0, 2, 'hola.png')
        self.assertEqual(all[0], exp_key, "not the same row: %s" % all[0])

def suite():
    suite = unittest.TestSuite()
    suite.addTest(TestDBStory('test_all'))
    suite.addTest(TestDBStory('test_add'))
    suite.addTest(TestDBStory('test_get'))
    suite.addTest(TestDBStory('test_update'))
    return suite


if __name__ == '__main__':
    unittest.TextTestRunner(verbosity=1).run(suite())