Exemple #1
0
    def test_edit_parent_folder_missingparent(self):
        '''
        Test editing parent to a non-existing Folder.
        '''
        from frostmark import db_base, user_data
        from frostmark.db import get_session
        from frostmark.models import Folder
        from frostmark.editor import Editor

        data = dirname(abspath(user_data.__file__))
        self.assertNotIn(db_base.DB_NAME, listdir(data))

        item = {'id': 321, 'folder_name': 'child'}
        session = get_session()
        try:
            session.add(Folder(**item))
            session.commit()
        finally:
            session.close()

        with self.assertRaises(Exception):
            Editor.change_parent_folder(folder_id=item['id'], parent_id=2**31)

        self.assertIn(db_base.DB_NAME, listdir(data))
        remove(join(data, db_base.DB_NAME))
Exemple #2
0
    def test_edit_parent_folder(self):
        '''
        Test editing a parent folder of a Folder.
        '''
        from frostmark import db_base, user_data
        from frostmark.db import get_session
        from frostmark.models import Folder
        from frostmark.editor import Editor

        data = dirname(abspath(user_data.__file__))
        self.assertNotIn(db_base.DB_NAME, listdir(data))

        items = [{
            'id': 321,
            'folder_name': 'old parent'
        }, {
            'id': 666,
            'folder_name': 'child',
            'parent_folder_id': 321
        }, {
            'id': 123,
            'folder_name': 'new parent'
        }]
        session = get_session()
        try:
            for item in items:
                session.add(Folder(**item))
            session.commit()

            for item in items:
                self.assertEqual(
                    session.query(Folder).filter(
                        Folder.folder_name == item['folder_name']).first().id,
                    item['id'])

            self.assertEqual(
                session.query(Folder).filter(
                    Folder.id == items[1]['id']).first().parent_folder_id,
                items[0]['id'])

            Editor.change_parent_folder(folder_id=items[1]['id'],
                                        parent_id=items[2]['id'])

            self.assertEqual(
                session.query(Folder).filter(
                    Folder.id == items[1]['id']).first().parent_folder_id,
                items[2]['id'])

        finally:
            session.close()

        self.assertIn(db_base.DB_NAME, listdir(data))
        remove(join(data, db_base.DB_NAME))
Exemple #3
0
            'arg_values'][0])))

PARSER.console_parser.add_argument(
    '-cpf',
    '--change-parent-folder',
    help='change parent for a folder',
    required=False,
    nargs=2,
    metavar=('FOLDER_ID', 'PARENT_ID'),

    # pylint: disable=unnecessary-lambda
    action=lambda *args, **kwargs: ExecuteAction(
        *args,
        **kwargs,
        func=lambda *args, **kwargs: Editor.change_parent_folder(
            folder_id=int(kwargs['arg_values'][0]),
            parent_id=int(kwargs['arg_values'][1]))))

PARSER.console_parser.add_argument(
    '-cpb',
    '--change-parent-bookmark',
    help='change parent for a bookmark',
    required=False,
    nargs=2,
    metavar=('BOOKMARK_ID', 'PARENT_ID'),

    # pylint: disable=unnecessary-lambda
    action=lambda *args, **kwargs: ExecuteAction(
        *args,
        **kwargs,
        func=lambda *args, **kwargs: Editor.change_parent_bookmark(