Пример #1
0
class ListDBTests(unittest.TestCase):

    def setUp(self):

        localmode_test_config = """
[pda]
database-path = /tmp/.pdateststore
"""

        cfg = PdaConfig(io.StringIO(u(localmode_test_config)))
        self.db = GithubIssues(cfg)

        # populate local data store with some data
        self.tl = [str(self.db.add_task('test summary 1', 'todo', 'week', 'must')),
                   str(self.db.add_task('test summary 2', 'tolearn', 'month', 'high')),
                   str(self.db.add_task('test summary 3', 'toread', 'day', 'urgmust'))]

    def tearDown(self):

        if os.path.exists(self.db.local_dbpath):
            os.remove(self.db.local_dbpath)

        del self.db

    def testAddTask(self):

        # initially the local data store should have 3 tasks
        self.assertTrue(len(self.db.shelf) == 3)

        # check tasks existence
        self.assertTrue(self.tl[0] in self.db.shelf)
        self.assertTrue(self.tl[1] in self.db.shelf)
        self.assertTrue(self.tl[2] in self.db.shelf)

        # check data integrity
        self.assertTrue(self.db.shelf[self.tl[0]]['summary'] == 'test summary 1')
        self.assertTrue(self.db.shelf[self.tl[1]]['type'] == 'tolearn')
        self.assertTrue(self.db.shelf[self.tl[1]]['milestone'] == 'month')
        self.assertTrue(self.db.shelf[self.tl[2]]['milestone'] == 'day')
        self.assertTrue(self.db.shelf[self.tl[2]]['priority'] == 'urgmust')
        self.assertFalse('CMDS_HISTORY' in self.db.shelf)

    def testRemoveTask(self):

        # initially the local data store should have 3 tasks
        self.assertTrue(len(self.db.shelf) == 3)

        # remove task 1
        self.db.remove_task(int(self.tl[0]))
        self.assertFalse(self.tl[0] in self.db.shelf)
        self.assertTrue(len(self.db.shelf) == 2)

        # remove non-existing task (task id = -1) and suppress output of remove_task
        with patch('sys.stdout', new=MockDevice()) as fake_out:
            self.db.remove_task(-1)

        self.assertTrue(len(self.db.shelf) == 2)
        self.assertFalse('CMDS_HISTORY' in self.db.shelf)

    def testFinishTasks(self):

        # initially the local data store should have 3 tasks
        self.assertTrue(len(self.db.shelf) == 3)

        # remove first two tasks
        self.db.finish_tasks([int(self.tl[0]), int(self.tl[1])])
        self.assertFalse(self.tl[0] in self.db.shelf)
        self.assertFalse(self.tl[1] in self.db.shelf)
        self.assertTrue(self.tl[2] in self.db.shelf)

        self.assertTrue(len(self.db.shelf) == 1)
        self.assertFalse('CMDS_HISTORY' in self.db.shelf)

    def testRemoveAllTasks(self):

        # initially the local data store should have 3 tasks
        self.assertTrue(len(self.db.shelf) == 3)

        # remove all tasks
        self.db.remove_all_tasks()

        # verified they are indeed removed
        self.assertTrue(len(self.db.shelf) == 0)
        self.assertFalse('CMDS_HISTORY' in self.db.shelf)
        self.assertFalse(self.tl[0] in self.db.shelf)

    def testEditTask(self):

        # initially the local data store should have 3 tasks
        self.assertTrue(len(self.db.shelf) == 3)

        # edit the first and the third task
        self.db.edit_task(self.tl[0], 
                          new_summary='test summary 4',
                          new_tasktype='totest',
                          new_milestone='season')
        self.db.edit_task(self.tl[2], 
                          new_priority='low')

        # check data integrity
        self.assertTrue(len(self.db.shelf) == 3)

        self.assertTrue(self.db.shelf[self.tl[0]]['summary']   == 'test summary 4')
        self.assertTrue(self.db.shelf[self.tl[0]]['type']      == 'totest')
        self.assertTrue(self.db.shelf[self.tl[0]]['milestone'] == 'season')
        self.assertTrue(self.db.shelf[self.tl[0]]['priority']  == 'must')

        self.assertTrue(self.db.shelf[self.tl[2]]['type']     == 'toread')
        self.assertTrue(self.db.shelf[self.tl[2]]['priority'] == 'low')

        self.assertTrue(self.db.shelf[self.tl[1]]['summary'] == 'test summary 2')

        self.assertFalse('CMDS_HISTORY' in self.db.shelf)