예제 #1
0
    def feed(self, feed_title, title, content, url, published=None, summary=None,
             enclosure=None, media_thumbnail=None):
        feed = FeedGenerator()
        feed.title(feed_title)
        feed.description(faker.sentence())
        feed.link({'href': WP_FEED_URL})

        entry = feed.add_entry()
        entry.title(title)
        entry.link({'href': url})
        entry.author(name=faker.name())
        entry.content(content, type="cdata")
        if summary:
            entry.description(summary)
        if enclosure:
            entry.enclosure(url=enclosure['url'],
                            type=enclosure['type'],
                            length=str(faker.pyint()))
        if media_thumbnail:
            feed.load_extension('media')
            entry.media.thumbnail({'url': media_thumbnail})
        tz = pytz.timezone(faker.timezone())
        published = published or faker.date_time(tzinfo=tz)
        entry.published(published)
        entry.updated(faker.date_time_between(start_date=published, tzinfo=tz))

        return feed.rss_str().decode('utf8')
예제 #2
0
    def feed(self,
             feed_title,
             title,
             content,
             url,
             published=None,
             summary=None,
             enclosure=None,
             media_thumbnail=None):
        feed = FeedGenerator()
        feed.title(feed_title)
        feed.description(faker.sentence())
        feed.link({'href': WP_FEED_URL})

        entry = feed.add_entry()
        entry.title(title)
        entry.link({'href': url})
        entry.author(name=faker.name())
        entry.content(content, type="cdata")
        if summary:
            entry.description(summary)
        if enclosure:
            entry.enclosure(url=enclosure['url'],
                            type=enclosure['type'],
                            length=str(faker.pyint()))
        if media_thumbnail:
            feed.load_extension('media')
            entry.media.thumbnail({'url': media_thumbnail})
        tz = pytz.timezone(faker.timezone())
        published = published or faker.date_time(tzinfo=tz)
        entry.published(published)
        entry.updated(faker.date_time_between(start_date=published, tzinfo=tz))

        return feed.rss_str().decode('utf8')
예제 #3
0
 def feed(self, feed_title, title, content, url, published=None, summary=None,
          enclosure=None, media_thumbnail=None):
     feed = AtomFeed(feed_title, feed_url=WP_FEED_URL)
     tz = pytz.timezone(faker.timezone())
     published = published or faker.date_time(tzinfo=tz)
     kwargs = {
         'content_type': 'html',
         'author': faker.name(),
         'url': url,
         'updated': faker.date_time_between(start_date=published, tzinfo=tz),
         'published': published
     }
     if summary:
         kwargs['summary'] = summary
     if enclosure:
         kwargs['links'] = [{
             'type': enclosure['type'],
             'href': enclosure['url'],
             'rel': 'enclosure',
             'length': faker.pyint(),
         }]
     feed.add(title, content, **kwargs)
     out = feed.to_string()
     if media_thumbnail:
         el = '<media:thumbnail url="{0}" />'.format(media_thumbnail)
         out = out.replace('<feed', '<feed xmlns:media="http://search.yahoo.com/mrss/"')
         out = out.replace('</entry>', '{0}</entry>'.format(el))
     return out
예제 #4
0
    def test_blogpost_with_first_image_as_thumbnail_as_src_set(self, blogpost, tpl):
        title = faker.sentence()
        post_url = faker.uri()
        image_url = faker.image_url()
        summary = faker.sentence()
        tz = pytz.timezone(faker.timezone())
        publish_date = faker.date_time(tzinfo=tz)
        srcset = ', '.join(
            ' '.join((faker.image_url(width=w), '{0}w'.format(w)))
            for w in ('1200', '1024', '300')
        )
        sizes = "(max-width: 1200px) 100vw, 1200px"
        content = tpl.format(image_url, srcset, sizes)

        feed = self.feed('Some blog', title, content, post_url,
                         published=publish_date,
                         summary=summary)

        post = blogpost(feed)

        assert post['title'] == title
        assert post['link'] == post_url
        assert post['summary'] == summary
        assert_equal_dates(post['date'], publish_date)
        assert post['image_url'] == image_url
        assert post['srcset'] == srcset
        assert post['sizes'] == sizes
예제 #5
0
    def test_blogpost_with_thumbnail_as_enclosure(self, blogpost, mime):
        title = faker.sentence()
        post_url = faker.uri()
        image_url = faker.image_url()
        tz = pytz.timezone(faker.timezone())
        publish_date = faker.date_time(tzinfo=tz)
        content = faker.sentence()
        html_content = '<div>{0}</div>'.format(content)
        feed = self.feed('Some blog',
                         title,
                         html_content,
                         post_url,
                         published=publish_date,
                         enclosure={
                             'type': mime,
                             'url': image_url
                         })

        post = blogpost(feed)

        assert post['title'] == title
        assert post['link'] == post_url
        assert post['summary'] == content
        assert_equal_dates(post['date'], publish_date)
        assert post['image_url'] == image_url
        assert 'srcset' not in post
        assert 'sizes' not in post
예제 #6
0
    def test_blogpost_with_first_image_as_thumbnail_as_src_set(
            self, blogpost, tpl):
        title = faker.sentence()
        post_url = faker.uri()
        image_url = faker.image_url()
        summary = faker.sentence()
        tz = pytz.timezone(faker.timezone())
        publish_date = faker.date_time(tzinfo=tz)
        srcset = ', '.join(' '.join((faker.image_url(width=w),
                                     '{0}w'.format(w)))
                           for w in ('1200', '1024', '300'))
        sizes = "(max-width: 1200px) 100vw, 1200px"
        content = tpl.format(image_url, srcset, sizes)

        feed = self.feed('Some blog',
                         title,
                         content,
                         post_url,
                         published=publish_date,
                         summary=summary)

        post = blogpost(feed)

        assert post['title'] == title
        assert post['link'] == post_url
        assert post['summary'] == summary
        assert_equal_dates(post['date'], publish_date)
        assert post['image_url'] == image_url
        assert post['srcset'] == srcset
        assert post['sizes'] == sizes
예제 #7
0
    def test_blogpost_with_first_image_as_thumbnail_and_summary(
            self, blogpost):
        title = faker.sentence()
        post_url = faker.uri()
        image_url = faker.image_url()
        summary = faker.sentence()
        tz = pytz.timezone(faker.timezone())
        publish_date = faker.date_time(tzinfo=tz)
        content = '<p><img class="whatever" src="{0}" /> Whatever whatever</p>'.format(
            image_url)
        feed = self.feed('Some blog',
                         title,
                         content,
                         post_url,
                         published=publish_date,
                         summary=summary)

        post = blogpost(feed)

        assert post['title'] == title
        assert post['link'] == post_url
        assert post['summary'] == summary
        assert_equal_dates(post['date'], publish_date)
        assert post['image_url'] == image_url
        assert 'srcset' not in post
        assert 'sizes' not in post
예제 #8
0
 def feed(self, feed_title, title, content, url, published=None, summary=None,
          enclosure=None, media_thumbnail=None):
     feed = AtomFeed(feed_title, feed_url=WP_FEED_URL)
     tz = pytz.timezone(faker.timezone())
     published = published or faker.date_time(tzinfo=tz)
     kwargs = {
         'content_type': 'html',
         'author': faker.name(),
         'url': url,
         'updated': faker.date_time_between(start_date=published, tzinfo=tz),
         'published': published
     }
     if summary:
         kwargs['summary'] = summary
     if enclosure:
         kwargs['links'] = [{
             'type': enclosure['type'],
             'href': enclosure['url'],
             'rel': 'enclosure',
             'length': faker.pyint(),
         }]
     feed.add(title, content, **kwargs)
     out = feed.to_string()
     if media_thumbnail:
         el = '<media:thumbnail url="{0}" />'.format(media_thumbnail)
         out = out.replace('<feed', '<feed xmlns:media="http://search.yahoo.com/mrss/"')
         out = out.replace('</entry>', '{0}</entry>'.format(el))
     return out
예제 #9
0
    def test_basic_blogpost(self, blogpost):
        title = faker.sentence()
        post_url = faker.uri()
        tz = pytz.timezone(faker.timezone())
        publish_date = faker.date_time(tzinfo=tz)
        content = faker.sentence()
        html_content = '<div>{0}</div>'.format(content)
        feed = self.feed('Some blog', title, html_content, post_url,
                         published=publish_date)

        post = blogpost(feed)

        assert post['title'] == title
        assert post['link'] == post_url
        assert post['summary'] == content
        assert_equal_dates(post['date'], publish_date)
        assert 'image_url' not in post
        assert 'srcset' not in post
        assert 'sizes' not in post
예제 #10
0
    def test_basic_blogpost(self, blogpost):
        title = faker.sentence()
        post_url = faker.uri()
        tz = pytz.timezone(faker.timezone())
        publish_date = faker.date_time(tzinfo=tz)
        content = faker.sentence()
        html_content = '<div>{0}</div>'.format(content)
        feed = self.feed('Some blog', title, html_content, post_url,
                         published=publish_date)

        post = blogpost(feed)

        assert post['title'] == title
        assert post['link'] == post_url
        assert post['summary'] == content
        assert_equal_dates(post['date'], publish_date)
        assert 'image_url' not in post
        assert 'srcset' not in post
        assert 'sizes' not in post
예제 #11
0
    def test_blogpost_with_first_image_as_thumbnail(self, blogpost):
        title = faker.sentence()
        post_url = faker.uri()
        image_url = faker.image_url()
        summary = faker.sentence()
        tz = pytz.timezone(faker.timezone())
        publish_date = faker.date_time(tzinfo=tz)
        content = '<p><img class="whatever" src="{0}" /> {1}</p>'.format(image_url, summary)
        feed = self.feed('Some blog', title, content, post_url,
                         published=publish_date)

        post = blogpost(feed)

        assert post['title'] == title
        assert post['link'] == post_url
        assert post['summary'] == summary
        assert_equal_dates(post['date'], publish_date)
        assert post['image_url'] == image_url
        assert 'srcset' not in post
        assert 'sizes' not in post
예제 #12
0
    def test_blogpost_with_thumbnail_as_enclosure(self, blogpost, mime):
        title = faker.sentence()
        post_url = faker.uri()
        image_url = faker.image_url()
        tz = pytz.timezone(faker.timezone())
        publish_date = faker.date_time(tzinfo=tz)
        content = faker.sentence()
        html_content = '<div>{0}</div>'.format(content)
        feed = self.feed('Some blog', title, html_content, post_url,
                         published=publish_date,
                         enclosure={'type': mime, 'url': image_url})

        post = blogpost(feed)

        assert post['title'] == title
        assert post['link'] == post_url
        assert post['summary'] == content
        assert_equal_dates(post['date'], publish_date)
        assert post['image_url'] == image_url
        assert 'srcset' not in post
        assert 'sizes' not in post