Exemplo n.º 1
0
def entry_list_add(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name, session=session)
        except NoResultFound:
            console('Could not find entry list with name `{}`, creating'.format(options.list_name))
            entry_list = EntryListList(name=options.list_name)
            session.add(entry_list)
        session.merge(entry_list)
        session.commit()
        title = options.entry_title
        entry = {'title': options.entry_title, 'url': options.url}
        db_entry = get_entry_by_title(list_id=entry_list.id, title=title, session=session)
        if db_entry:
            console("Entry with the title `{}` already exist with list `{}`. Will replace identifiers if given".format(
                title, entry_list.name))
            output = 'Successfully updated entry `{}` to entry list `{}` '.format(title, entry_list.name)
        else:
            console("Adding entry with title `{}` to list `{}`".format(title, entry_list.name))
            db_entry = EntryListEntry(entry=entry, entry_list_id=entry_list.id)
            session.add(db_entry)
            output = 'Successfully added entry `{}` to entry list `{}` '.format(title, entry_list.name)
        if options.attributes:
            console('Adding attributes to entry `{}`'.format(title))
            for identifier in options.attributes:
                for k, v in identifier.items():
                    entry[k] = v
            db_entry.entry = entry
        console(output)
Exemplo n.º 2
0
    def test_entry_list_sorting(self, api_client):
        base_entry_1 = dict(title='test_title_1', original_url='url_c')
        base_entry_2 = dict(title='test_title_2', original_url='url_b')
        base_entry_3 = dict(title='test_title_3', original_url='url_a')

        with Session() as session:
            entry_list = EntryListList(name='test list')
            session.add(entry_list)

            e1 = Entry(base_entry_1)
            e2 = Entry(base_entry_2)
            e3 = Entry(base_entry_3)

            entry_list.entries.append(EntryListEntry(e1, entry_list.id))
            entry_list.entries.append(EntryListEntry(e2, entry_list.id))
            entry_list.entries.append(EntryListEntry(e3, entry_list.id))

        # Sort by title
        rsp = api_client.get('/entry_list/1/entries/?sort_by=title')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        data = json.loads(rsp.get_data(as_text=True))

        assert data[0]['title'] == 'test_title_3'

        rsp = api_client.get('/entry_list/1/entries/?sort_by=title&order=asc')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        data = json.loads(rsp.get_data(as_text=True))

        assert data[0]['title'] == 'test_title_1'

        # Sort by original url
        rsp = api_client.get('/entry_list/1/entries/?sort_by=original_url')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        data = json.loads(rsp.get_data(as_text=True))

        assert data[0]['original_url'] == 'url_c'

        rsp = api_client.get(
            '/entry_list/1/entries/?sort_by=original_url&order=asc')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        data = json.loads(rsp.get_data(as_text=True))

        assert data[0]['original_url'] == 'url_a'

        # Combine sorting and pagination
        rsp = api_client.get(
            '/entry_list/1/entries/?sort_by=title&per_page=2&page=2')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        data = json.loads(rsp.get_data(as_text=True))

        assert data[0]['title'] == 'test_title_1'
Exemplo n.º 3
0
def entry_list_add(options):
    with Session() as session:
        try:
            entry_list = get_list_by_exact_name(options.list_name,
                                                session=session)
        except NoResultFound:
            console(
                'Could not find entry list with name `{}`, creating'.format(
                    options.list_name))
            entry_list = EntryListList(name=options.list_name)
            session.add(entry_list)
        session.merge(entry_list)

        title = options.entry_title
        entry = {
            'title': options.entry_title,
            'original_url': options.original_url
        }
        db_entry = get_entry_by_title(list_id=entry_list.id,
                                      title=title,
                                      session=session)
        if db_entry:
            console(
                "Entry with the title `{}` already exist with list `{}`. Will replace identifiers if given"
                .format(title, entry_list.name))
            output = 'Successfully updated entry `{}` to entry list `{}` '.format(
                title, entry_list.name)
        else:
            console("Adding entry with title `{}` to list `{}`".format(
                title, entry_list.name))
            db_entry = EntryListEntry(entry=entry, entry_list_id=entry_list.id)
            session.add(db_entry)
            output = 'Successfully added entry `{}` to entry list `{}` '.format(
                title, entry_list.name)
        if options.identifiers:
            output = 'Successfully updated entry `{}` to entry list `{}` '.format(
                title, entry_list.name)
            identifiers = [
                parse_identifier(identifier)
                for identifier in options.identifiers if options.identifiers
            ]
            console('Adding identifiers to entry `{}`'.format(title))
            for identifier in identifiers:
                for k, v in identifier.items():
                    entry[k] = v
            db_entry.entry = entry
        console(output)
Exemplo n.º 4
0
    def test_entry_list_pagination(self, api_client, link_headers):
        base_entry = dict(title='test_title_', original_url='url_')
        number_of_entries = 200

        with Session() as session:
            entry_list = EntryListList(name='test list')
            session.add(entry_list)

            for i in range(number_of_entries):
                entry = copy.deepcopy(base_entry)
                for k, v in entry.items():
                    entry[k] = v + str(i)
                e = Entry(entry)
                entry_list.entries.append(EntryListEntry(e, entry_list.id))

        # Default values
        rsp = api_client.get('/entry_list/1/entries/')
        assert rsp.status_code == 200, 'Response code is %s' % rsp.status_code
        data = json.loads(rsp.get_data(as_text=True))

        assert len(data) == 50
        assert int(rsp.headers['total-count']) == 200
        assert int(rsp.headers['count']) == 50

        links = link_headers(rsp)
        assert links['last']['page'] == 4
        assert links['next']['page'] == 2

        # Change page size
        rsp = api_client.get('/entry_list/1/entries/?per_page=100')
        assert rsp.status_code == 200
        data = json.loads(rsp.get_data(as_text=True))

        assert len(data) == 100
        assert int(rsp.headers['total-count']) == 200
        assert int(rsp.headers['count']) == 100

        links = link_headers(rsp)
        assert links['last']['page'] == 2
        assert links['next']['page'] == 2

        # Get different page
        rsp = api_client.get('/entry_list/1/entries/?page=2')
        assert rsp.status_code == 200
        data = json.loads(rsp.get_data(as_text=True))

        assert len(data) == 50
        assert int(rsp.headers['total-count']) == 200
        assert int(rsp.headers['count']) == 50

        links = link_headers(rsp)
        assert links['last']['page'] == 4
        assert links['next']['page'] == 3
        assert links['prev']['page'] == 1
Exemplo n.º 5
0
    def test_entry_list_with_next_series_episodes(self, execute_task):
        entry = Entry()
        entry['title'] = 'foo.s01e01.720p.hdtv-flexget'
        entry['url'] = ''

        with Session() as session:
            entry_list = EntryListList()
            entry_list.name = 'series list'
            session.add(entry_list)
            session.commit()

            db_entry = EntryListEntry(entry, entry_list.id)
            entry_list.entries.append(db_entry)

        task = execute_task('entry_list_with_series')
        assert task.find_entry('accepted', title='foo.s01e01.720p.hdtv-flexget')
Exemplo n.º 6
0
    def test_entry_list_search(self, execute_task):
        entry = Entry()
        entry['title'] = 'test title'
        entry['url'] = ''

        with Session() as session:
            entry_list = EntryListList()
            entry_list.name = 'Test list'
            session.add(entry_list)
            session.commit()

            db_entry = EntryListEntry(entry, entry_list.id)
            entry_list.entries.append(db_entry)

        task = execute_task('entry_list_discover')
        assert len(task.entries) > 0
        assert task.find_entry(title='test title')