def test_create_project(self):
     taskdb = TaskDB(':memory:')
     with self.assertRaises(AssertionError):
         taskdb._create_project('abc.abc')
     taskdb._create_project('abc')
     taskdb._list_project()
     self.assertSetEqual(taskdb.projects, set(('abc', )))
    def test_other(self):
        taskdb = TaskDB(':memory:')

        # insert
        taskdb.insert('project', 'taskid', self.sample_task)
        taskdb.insert('project', 'taskid2', self.sample_task)

        # status_count
        status = taskdb.status_count('abc')
        self.assertEqual(status, {})
        status = taskdb.status_count('project')
        self.assertEqual(status, {taskdb.FAILED: 2})

        # update & status_count
        taskdb.update('project', 'taskid', status=taskdb.ACTIVE)
        status = taskdb.status_count('project')
        self.assertEqual(status, {taskdb.ACTIVE: 1, taskdb.FAILED: 1})

        # load tasks
        taskdb.update('project', 'taskid', track={})
        tasks = list(taskdb.load_tasks(taskdb.ACTIVE))
        self.assertEqual(len(tasks), 1)
        task = tasks[0]
        self.assertEqual(task['taskid'], 'taskid')
        self.assertEqual(task['schedule'], self.sample_task['schedule'])
        self.assertEqual(task['fetch'], self.sample_task['fetch'])
        self.assertEqual(task['process'], self.sample_task['process'])
        self.assertEqual(task['track'], {})

        tasks = list(taskdb.load_tasks(taskdb.ACTIVE, project='project',
                fields=['taskid']))
        self.assertEqual(len(tasks), 1)
        self.assertEqual(tasks[0]['taskid'], 'taskid')
        self.assertNotIn('project', tasks[0])

        # get_task
        task = taskdb.get_task('project', 'taskid1', fields=['status'])
        self.assertIsNone(task)

        task = taskdb.get_task('project', 'taskid2')
        self.assertEqual(task['taskid'], 'taskid2')
        self.assertEqual(task['status'], taskdb.FAILED)
        self.assertEqual(task['schedule'], self.sample_task['schedule'])
        self.assertEqual(task['fetch'], self.sample_task['fetch'])
        self.assertEqual(task['process'], self.sample_task['process'])
        self.assertEqual(task['track'], self.sample_task['track'])

        task = taskdb.get_task('project', 'taskid', fields=['status'])
        self.assertEqual(task['status'], taskdb.ACTIVE)
        self.assertNotIn('taskid', task)