Ejemplo n.º 1
0
    def test_articles_with_enclosure_and_fetched_content(self, truncated_cnt,
                                                         get_vector):
        self._clean_objs()
        get_vector.return_value = None
        truncated_cnt.return_value = {'type': 'fetched',
                                      'title': 'holy grail',
                                      'content': 'blue, no read, aaah',
                                      'link': 'https://monthy.python/brian'}
        feed = FeedController().read().first()
        FeedController().update({'id': feed.id},
                                {'truncated_content': True,
                                 'cluster_enabled': True})
        UserController().update({'id': feed.user_id},
                                {'cluster_enabled': True})

        builder = ClassicArticleBuilder(feed, self.entry_w_enclosure, {})
        self.assertIsNone(builder.article.get('article_type'))
        raw_articles = list(builder.enhance())
        self.assertEqual(2, len(raw_articles))
        self.assertEqual('audio', raw_articles[1]['article_type'].value)
        articles = []
        for raw_article in raw_articles:
            articles.append(
                ArticleController(feed.user_id).create(**raw_article))
        ClusterController(feed.user_id).clusterize_pending_articles()
        a1 = ArticleController().get(id=articles[0].id)
        a2 = ArticleController().get(id=articles[1].id)
        self.assertEqual(a1.cluster_id, a2.cluster_id)
        cluster = ClusterController().get(id=a1.cluster_id)
        self.assertEqual(2, cluster.content['v'])
        self.assertEqual(1, len(cluster.content['contents']))
        self.assertEqual('fetched', cluster.content['contents'][0]['type'])
Ejemplo n.º 2
0
 def test_image_content(self):
     resp = self.response2
     resp.headers['content-type'] = 'image/png'
     self.head_patch.return_value = resp
     article = ClassicArticleBuilder(Feed(id=1, user_id=1),
                                     self.entry2).enhance()
     self.assertEqual(ArticleType.image, article['article_type'])
Ejemplo n.º 3
0
 def test_missing_title(self):
     self.head_patch.return_value = self.get_response('http:')
     article = ClassicArticleBuilder(Feed(id=1, user_id=1),
                                     self.entry).enhance()
     self.assertEqual('http://www.pariszigzag.fr/?p=56413',
                      article['entry_id'])
     self.assertEqual('http:' + self.response_url, article['link'])
     self.assertEqual(1, article['user_id'])
     self.assertEqual(1, article['feed_id'])
Ejemplo n.º 4
0
 def test_image_content(self):
     entry, resp = self.entry2, self.response2
     resp.headers['content-type'] = 'image/png'
     entry.pop('links')
     entry['link'] = resp.url = 'https://domain.tld/to-img.png'
     self.head_patch.return_value = resp
     articles = list(
         ClassicArticleBuilder(Feed(id=1, user_id=1), entry, {}).enhance())
     self.assertEqual(1, len(articles))
     article = articles[0]
     self.assertEqual(ArticleType.image, article['article_type'])
Ejemplo n.º 5
0
 def test_articles_with_enclosure(self):
     self._clean_objs()
     feed = FeedController().read().first()
     UserController().update({'id': feed.user_id},
                             {'cluster_enabled': True})
     builder = ClassicArticleBuilder(feed, self.entry_w_enclosure, {})
     self.assertIsNone(builder.article.get('article_type'))
     raw_articles = list(builder.enhance())
     self.assertEqual(2, len(raw_articles))
     self.assertEqual('audio', raw_articles[1]['article_type'].value)
     articles = []
     for raw_article in raw_articles:
         articles.append(
             ArticleController(feed.user_id).create(**raw_article))
     ClusterController(feed.user_id).clusterize_pending_articles()
     a1 = ArticleController().get(id=articles[0].id)
     a2 = ArticleController().get(id=articles[1].id)
     cluster = ClusterController().get(id=a1.cluster_id)
     self.assertEqual(a1.cluster_id, a2.cluster_id)
     self.assertEqual(2, cluster.content['v'])
     self.assertEqual(0, len(cluster.content['contents']))
Ejemplo n.º 6
0
    def test_embedded_content(self):
        self.head_patch.return_value = self.response2
        article = ClassicArticleBuilder(Feed(id=1, user_id=1),
                                        self.entry2).enhance()

        self.assertEqual('yt:video:scbrjaqM3Oc', article['entry_id'])
        self.assertEqual(self.response2.url, article['link'])
        self.assertEqual(
            "Ceci n'est pas Old Boy - Owlboy (suite) - "
            "Benzaie Live", article['title'])
        self.assertEqual(1, article['user_id'])
        self.assertEqual(ArticleType.embedded, article['article_type'])
        self.assertEqual(1, article['feed_id'])
Ejemplo n.º 7
0
    def test_missing_scheme(self):
        response = self.get_response('http:')
        self.head_patch.side_effect = [
            MissingSchema, MissingSchema, MissingSchema, response
        ]
        entry = self.entry
        entry['link'] = entry['link'][5:]  # removing scheme, for testing

        article = ClassicArticleBuilder(Feed(id=1, user_id=1), entry).enhance()

        self.assertEqual(4, self.head_patch.call_count)
        self.assertEqual(response.url, self.head_patch.call_args[0][0])
        self.assertEqual('http://www.pariszigzag.fr/?p=56413',
                         article['entry_id'])
        self.assertEqual(response.url, article['link'])
        self.assertEqual(1, article['user_id'])
        self.assertEqual(1, article['feed_id'])
Ejemplo n.º 8
0
    def test_missing_scheme(self):
        response = self.get_response('http:')
        self.head_patch.side_effect = [
            MissingSchema, MissingSchema, MissingSchema, response
        ]
        self.jarr_get_patch.return_value = response
        entry = self.entry
        entry['link'] = entry['link'][5:]

        article = ClassicArticleBuilder(Feed(id=1, user_id=1), entry).enhance()

        self.assertEqual(4, self.head_patch.call_count)
        self.assertEqual(response.url, self.head_patch.call_args[0][0])
        self.assertEqual('http://www.pariszigzag.fr/?p=56413',
                         article['entry_id'])
        self.assertEqual(response.url, article['link'])
        self.assertEqual('Les plus belles boulangeries de Paris',
                         article['title'])
        self.assertEqual(1, article['user_id'])
        self.assertEqual(1, article['feed_id'])