Example #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)
Example #2
0
def folder_handler(service: AppService, namespace):
    if namespace.action == 'create':
        folder = service.create_folder(user=namespace.user,
                                       name=namespace.name)
        print('Created folder:')
        print(folder)

    elif namespace.action == 'show':
        folder_show_handler(service, namespace)

    elif namespace.action == 'edit':
        if namespace.name:
            folder = service.update_folder(folder_id=namespace.folder_id,
                                           user=namespace.user,
                                           name=namespace.name)
            print(f'Folder has been updated. New folder name = {folder.name}')
        else:
            print('Nothing to update')

    elif namespace.action == 'populate':

        service.populate_folder(user=namespace.user,
                                folder_id=namespace.folder_id,
                                task_id=namespace.task_id)
        print(
            f'Folder with ID={namespace.folder_id} has been populated with task ID={namespace.task_id}'
        )

    elif namespace.action == 'unpopulate':

        service.unpopulate_folder(user=namespace.user,
                                  folder_id=namespace.folder_id,
                                  task_id=namespace.task_id)
        print(f'Task(ID={namespace.task_id}) no longer in this folder')

    elif namespace.action == 'delete':
        service.delete_folder(user=namespace.user,
                              folder_id=namespace.folder_id)
        print(f'Folder(ID={namespace.folder_id}) has been deleted')