Exemple #1
0
    def test_eq(self):
        feed = models.Feed(
            feed_url='http://example.com/rss.xml',
            title='Sample Feed',
            home_url='http://example.com',
            published_at=datetime.datetime.utcnow(),
            updated_at=None,
            db_updated_at=None)

        feed_entry1 = models.FeedEntry(
            id=None,
            feed=feed,
            created_at=None,
            updated_at=None,
            title='Feed Entry 1 Title',
            url='http://example.com/entry1.html',
            content='Some Entry content',
            author_name='John Doe',
            db_updated_at=None)

        feed_entry2 = models.FeedEntry(
            id=None,
            feed=feed,
            created_at=None,
            updated_at=None,
            title='Feed Entry 2 Title',
            url='http://example.com/entry2.html',
            content='Some Entry content',
            author_name='John Doe',
            db_updated_at=None)

        self.assertTrue(feed_entry1 == feed_entry1)

        self.assertFalse(feed_entry1 == feed_entry2)

        self.assertFalse(feed_entry1 == object())
Exemple #2
0
def d_entry_2_feed_entry(d_entry):
    feed_entry = models.FeedEntry(id=d_entry.get('id'))

    if 'created_parsed' in d_entry:
        time_tuple = d_entry.created_parsed

        if time_tuple is not None:
            feed_entry.created_at = _time_tuple_to_datetime(time_tuple)
        else:  # pragma: no cover
            feed_entry.created_at = None
    else:
        feed_entry.created_at = None

    if 'published_parsed' in d_entry:
        time_tuple = d_entry.published_parsed

        if time_tuple is not None:
            feed_entry.published_at = _time_tuple_to_datetime(time_tuple)
        else:  # pragma: no cover
            # field auto-filled by DB
            pass
    else:
        # field auto-filled by DB
        pass

    if 'updated_parsed' in d_entry:
        time_tuple = d_entry.updated_parsed

        if time_tuple is not None:
            feed_entry.updated_at = _time_tuple_to_datetime(time_tuple)
        else:  # pragma: no cover
            feed_entry.updated_at = None
    else:
        feed_entry.updated_at = None

    title = d_entry.get('title')
    if title is None:
        raise ValueError('title not set')

    feed_entry.title = title

    url = d_entry.get('link')
    if url is None:
        raise ValueError('url not set')

    if not validators.url(url, public=True):
        raise ValueError('url malformed')

    feed_entry.url = url

    content = None

    if content is None:
        if 'content' in d_entry:
            d_entry_content = next((dec for dec in d_entry.content if dec.type in {
                                   'text/html', 'application/xhtml+xml'}), None)
            if d_entry_content is not None:
                content = content_sanitize.sanitize_html(d_entry_content.value)
            else:
                d_entry_content = next(
                    (dec for dec in d_entry.content if dec.type == 'text/plain'), None)
                if d_entry_content is not None:
                    content = content_sanitize.sanitize_plain(
                        d_entry_content.value)

    if content is None:
        if 'summary' in d_entry:
            content = content_sanitize.sanitize(d_entry.summary)

    if content is None:
        raise ValueError('content not set')

    feed_entry.content = content

    feed_entry.author_name = d_entry.get('author')

    return feed_entry
    def test_read_mapping_generator_fn_morethanmincount(self):
        with self.settings(
                USER_UNREAD_GRACE_INTERVAL=datetime.timedelta(days=-7),
                USER_UNREAD_GRACE_MIN_COUNT=1):
            user = models.User.objects.create(email='*****@*****.**')

            feed = models.Feed.objects.create(
                feed_url='http://example.com/rss.xml',
                title='Sample Feed',
                home_url='http://example.com',
                published_at=datetime.datetime.utcnow(),
                updated_at=None,
                db_updated_at=None)

            feed_entry1 = models.FeedEntry(
                id=None,
                feed=feed,
                created_at=None,
                updated_at=None,
                title='Feed Entry 1 Title',
                url='http://example.com/entry1.html',
                content='Some Entry content',
                author_name='John Doe',
                db_updated_at=None)

            feed_entry2 = models.FeedEntry(
                id=None,
                feed=feed,
                created_at=None,
                updated_at=None,
                title='Feed Entry 2 Title',
                url='http://example.com/entry2.html',
                content='Some Entry content',
                author_name='John Doe',
                db_updated_at=None)

            feed_entry3 = models.FeedEntry(
                id=None,
                feed=feed,
                created_at=None,
                updated_at=None,
                title='Feed Entry 3 Title',
                url='http://example.com/entry3.html',
                content='Some Entry content',
                author_name='John Doe',
                db_updated_at=None)

            feed_entry4 = models.FeedEntry(
                id=None,
                feed=feed,
                created_at=None,
                updated_at=None,
                title='Feed Entry 4 Title',
                url='http://example.com/entry4.html',
                content='Some Entry content',
                author_name='John Doe',
                db_updated_at=None)

            models.FeedEntry.objects.bulk_create(
                [feed_entry1, feed_entry2, feed_entry3, feed_entry4])

            feed_entry1.published_at = user.created_at + \
                settings.USER_UNREAD_GRACE_INTERVAL + \
                datetime.timedelta(days=-1, minutes=-10)
            feed_entry1.save(update_fields=['published_at'])

            feed_entry2.published_at = user.created_at + \
                settings.USER_UNREAD_GRACE_INTERVAL + \
                datetime.timedelta(days=-1, minutes=-20)
            feed_entry2.save(update_fields=['published_at'])

            read_mappings = list(
                archived_feed_entry_util.read_mapping_generator_fn(feed, user))
            self.assertEqual(len(read_mappings), 2)