Beispiel #1
0
class FolderTest(unittest.TestCase):
    def setUp(self):
        session = mo.set_up_connection(DRIVER_NAME, CONNECTIONSTRING)
        self.serv = AppService(session)

    def test_create_folder(self):
        folder = self.serv.create_folder(user=TEST_USER, name=TEST_RANDOM_STR)
        self.assertEqual(folder.user, TEST_USER)
        self.assertEqual(folder.name, TEST_RANDOM_STR)

    def test_update_folder(self):
        folder1 = self.serv.create_folder(user=TEST_USER, name='folder1')

        self.serv.update_folder(user=TEST_USER,
                                folder_id=folder1.id,
                                name='newfoldername')

        self.assertEqual(folder1.name, 'newfoldername')

    def test_get_folder(self):
        folder = self.serv.create_folder(user=TEST_USER, name=TEST_NAME)
        folder_copy = self.serv.get_folder(user=TEST_USER, folder_id=folder.id)
        self.assertEqual(folder, folder_copy)

        with self.assertRaises(ex.ObjectNotFound):
            self.serv.get_folder(user=TEST_USER, folder_id=TEST_RANDOM_INT)

    def test_delete_folder(self):
        folder = self.serv.create_folder(user=TEST_USER, name='randomstr')
        self.serv.delete_folder(user=TEST_USER, folder_id=folder.id)
        with self.assertRaises(ex.ObjectNotFound):
            self.serv.get_folder(user=TEST_USER, folder_id=folder.id)

    def test_populate_folder(self):
        folder = self.serv.create_folder(user=TEST_USER, name='rand')
        self.assertEqual(len(folder.tasks), 0)
        task = self.serv.create_task(user=TEST_USER, name=TEST_NAME)
        self.serv.populate_folder(user=TEST_USER,
                                  folder_id=folder.id,
                                  task_id=task.id)
        self.assertEqual(len(folder.tasks), 1)

        with self.assertWarns(ex.RedundancyAction):
            self.serv.populate_folder(user=TEST_USER,
                                      folder_id=folder.id,
                                      task_id=task.id)

        self.serv.unpopulate_folder(user=TEST_USER,
                                    folder_id=folder.id,
                                    task_id=task.id)

        self.assertEqual(len(folder.tasks), 0)

        with self.assertRaises(ValueError):
            self.serv.unpopulate_folder(user=TEST_USER,
                                        folder_id=folder.id,
                                        task_id=task.id)
Beispiel #2
0
def folder_show_handler(service: AppService, namespace):

    if namespace.show_type == 'id':
        folder = service.get_folder(user=namespace.user,
                                    folder_id=namespace.folder_id)
        print(folder)
        if folder and namespace.tasks:
            print_collection(folder.tasks,
                             mes1='Folder tasks:',
                             mes2='Folder is empty')

    elif namespace.show_type == 'all':
        folders = service.get_all_folders(user=namespace.user)
        if folders and namespace.tasks:
            for folder in folders:
                print(folder)
                print_collection(folder.tasks,
                                 mes1='Folder tasks:',
                                 mes2='Folder is empty')
        else:
            print_collection(folders,
                             mes1='Your folders:',
                             mes2='You dont have folders')