Exemplo n.º 1
0
    def test_fetch(self):
        """Test whether a list of entries is returned"""

        http_requests = configure_http_server()

        # Test fetch entries from feed
        rss = RSS(RSS_FEED_URL)
        entries = [entry for entry in rss.fetch()]
        self.assertEqual(len(entries), 30)
        self.assertEqual(len(http_requests), 1)

        # Test metadata
        expected = [('98572defb3a652afbfdfe96517edefb88a22dcfa', 1481044620.0,
                     'Connect 2016 Developer Workshop'),
                    ('e3b0d7463fca0c47d82debc3ddc37d8906f77548', 1480955040.0,
                     'Create a URL Shortener with Node.js and Couchbase using N1QL'),
                    ('28bca39353ff0825f53b157b69da319e2f49ab4d', 1480886040.0,
                     'ELT processing with Couchbase and N1QL')]

        for x in range(len(expected)):
            entry = entries[x]
            self.assertEqual(entry['origin'], 'http://example.com/rss')
            self.assertEqual(entry['uuid'], expected[x][0])
            self.assertEqual(entry['updated_on'], expected[x][1])
            self.assertEqual(entry['category'], 'entry')
            self.assertEqual(entry['tag'], 'http://example.com/rss')
            self.assertEqual(entry['data']['title'], expected[x][2])
Exemplo n.º 2
0
    def test_search_fields(self):
        """Test whether the search_fields is properly set"""

        configure_http_server()

        rss = RSS(RSS_FEED_URL)
        entries = [entry for entry in rss.fetch()]

        for entry in entries:
            self.assertEqual(rss.metadata_id(entry['data']),
                             entry['search_fields']['item_id'])
Exemplo n.º 3
0
    def test_fetch_empty(self):
        """Test whether it works when no entries are fetched"""

        body = """
        <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <rss version="2.0">
        </rss>
        """
        httpretty.register_uri(httpretty.GET,
                               RSS_FEED_URL,
                               body=body, status=200)

        rss = RSS(RSS_FEED_URL)
        entries = [entry for entry in rss.fetch()]

        self.assertEqual(len(entries), 0)
Exemplo n.º 4
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        http_requests = configure_http_server()

        # First, we fetch the entries from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        rss = RSS(RSS_FEED_URL, cache=cache)

        entries = [entry for entry in rss.fetch()]
        self.assertEqual(len(http_requests), 1)

        # Now, we get the entries from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cached_entries = [entry for entry in rss.fetch_from_cache()]
        self.assertEqual(len(cached_entries), len(entries))
        self.assertEqual(len(http_requests), 1)  # no more requests done