Exemplo n.º 1
0
    def test_malformed(self):
        """Test nasty feeds that we've discovered in the wild"""
        owner = User()
        owner.email = "Bob"
        owner.save()

        # Really long titles.
        title = u"minimal linux"
        link = u"http://minimallinux.com/rss"
        site = u"http://minimallinux.com/"
        feed = Feed.create_and_subscribe(title, link, site, owner)

        # This feed is dead, so we don't expect any items downloaded.
        userfeeditems = FeedItem.objects.for_user(owner)
        self.assertEqual(userfeeditems.count(), 0)

        # Discovered while trying to import from google reader.
        # >>> len(e.title)
        # 857
        item = FeedItem()
        item.feed = feed
        item.title = u"This isn't a question but more of a submission for your \"enough\" poll-type thing.<br>\r\n<br>\r\nI would go with Arch as my main distro. It\u2019s the simplest and easiest to setup of any distro I\u2019ve used.<br>\r\n<br>\r\nMy window manager of choice would be dwm. Amazingly simple and very customizable.<br>\r\n<br>\r\nI would use vim for any text editing I would need to do (which mostly involves programming)<br>\r\n<br>\r\nI would be able to get away with using feh as my image viewer, since I never really need to do any image editing.<br>\r\n<br>\r\nChromium, of course.<br>\r\n<br>\r\nI would use dmenu as my app launcher. Another suckless creation, very simple and very fast.<br>\r\n<br>\r\nDropbox for file syncing.<br>\r\n<br>\r\nPidgin (haven't looked that much for something simpler) for AIM.<br>\r\n<br>\r\nI would also need a few programming related things such as ruby, gcc, make, etc."
        item.link = u"http://minimallinux.com/post/7031884799"
        item.description = u"<p>Nice\u2014good stuff here. I really dig dmenu.</p>"
        item.published = datetime.utcfromtimestamp(1309319839)
        item.atom_id = ""
        item.reader_guid = u"tag:google.com,2005:reader/item/022fe5bb1abdb67a"
        item.guid = item.calculate_guid()
        item.save()

        userfeeditems = FeedItem.objects.for_user(owner)
        self.assertEqual(userfeeditems.count(), 1)
Exemplo n.º 2
0
    def test_endpoint_paging(self):
        '''Page out more than 20 items.'''
        # Test data
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        for i in xrange(0, 50):
            item = FeedItem()
            item.feed = feed
            item.title = 'Feed title {0}'.format(i)
            item.link = 'http://www.paulhummer.org/rss/{0}'.format(i)
            item.guid = 'http://www.paulhummer.org/rss/{0}'.format(i)
            item.published = datetime.now()
            item.save()

        # Actual test
        result = self.api_client.get('/api/0.9.5/item/')
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(content.keys(), ['meta', 'objects'])
        self.assertEqual(
            content['meta'].keys(),
            ['previous', 'total_count', 'offset', 'limit', 'next'])
        self.assertEqual(content['meta']['previous'], None)
        self.assertEqual(content['meta']['total_count'], 50)
        self.assertEqual(content['meta']['offset'], 0)
        self.assertEqual(content['meta']['limit'], 20)
        self.assertEqual(
            content['meta']['next'].split('?')[1],
            'limit=20&offset=20')
        self.assertEqual(len(content['objects']), 20)
Exemplo n.º 3
0
    def test_endpoint_by_id(self):
        '''Get a specific feed item.'''
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()
        userfeeditem = UserFeedItem.objects.get(user=self.user, item=item)
        userfeeditem.tags.add('hipster', 'douche')
        userfeeditem.save()

        result = self.api_client.get('/api/0.9.5/item/')
        content = json.loads(result.content)
        result = self.api_client.get(content['objects'][0]['resource_uri'])
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(
            sorted(content.keys()),
            ['description', 'feed', 'feed_id', 'feed_tags', 'feed_title',
             'id', 'link', 'published', 'read', 'resource_uri', 'starred',
             'tags', 'title'])
        self.assertEqual(content['description'], item.description)
        self.assertEqual(content['link'], item.link)
        self.assertEqual(
            dateutil.parser.parse(content['published']),
            item.published)
        self.assertEqual(content['title'], item.title)
        self.assertEqual(content['feed'], '/api/0.9.5/feed/1/')
        self.assertEqual(content['tags'], ['hipster', 'douche'])
Exemplo n.º 4
0
    def test_endpoint_single_item(self):
        '''The root feed endpoint returns a list of items.'''
        # Test data
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()

        # Actual test
        result = self.api_client.get('/api/0.9.5/item/')
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(content.keys(), ['meta', 'objects'])
        self.assertEqual(
            content['meta'].keys(),
            ['previous', 'total_count', 'offset', 'limit', 'next'])
        self.assertEqual(content['meta']['previous'], None)
        self.assertEqual(content['meta']['total_count'], 1)
        self.assertEqual(content['meta']['offset'], 0)
        self.assertEqual(content['meta']['limit'], 20)
        self.assertEqual(content['meta']['next'], None)
Exemplo n.º 5
0
    def test_tagging(self):
        user = User()
        user.email = "Bob"
        user.save()

        feed = Feed()
        feed.title = "BoingBoing"
        feed.link = "http://boingboing.net"
        feed.save()
        feed.add_subscriber(user)

        item = FeedItem()
        item.title = "Octopus v. Platypus"
        item.description = "A fight to the death."
        item.link = item.guid = "http://www.example.com/rss/post"
        item.published = datetime.now()
        item.feed = feed
        item.save()

        item2 = FeedItem()
        item2.title = "Cute bunny rabbit video"
        item2.description = "They die at the end."
        item2.link = item.guid = "http://www.example.com/rss/post"
        item2.published = datetime.now()
        item2.feed = feed
        item2.save()

        userfeeditem = UserFeedItem.objects.get(user=user, item=item)
        userfeeditem.tags.add("cute", "platypus")

        userfeeditem2 = UserFeedItem.objects.get(user=user, item=item2)
        userfeeditem2.tags.add("bunny", "cute")

        self.assertIn("cute", [tag.name for tag in userfeeditem.tags.all()])
        self.assertIn("platypus", [tag.name for tag in userfeeditem.tags.all()])
        self.assertNotIn("bunny", [tag.name for tag in userfeeditem.tags.all()])

        tagged = UserFeedItem.objects.filter(tags__name__in=["cute"])

        self.assertEquals(len(tagged), 2)

        userfeeditem.tags.set("test")
        self.assertEquals(len(userfeeditem.tags.all()), 1)
        self.assertNotIn("cute", [tag.name for tag in userfeeditem.tags.all()])

        # API claims we can do this safely without raising an exception
        userfeeditem.tags.remove("cute")

        userfeeditem.tags.clear()
        self.assertEquals(len(userfeeditem.tags.all()), 0)
Exemplo n.º 6
0
    def test_endpoint_only_owned(self):
        '''Don't return items where UserFeedItem.user is not the user.'''
        # Test data
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()

        mike = User.objects.create_user(
            'mike', '*****@*****.**', password='******')
        mike.save()
        feed = Feed.create_and_subscribe(
            'Gothamist', 'http://feeds.gothamistllc.com/gothamist05', None, mike)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title'
        item.link = 'http://www.gothamist.com/rss/1'
        item.guid = 'http://www.gothamist.com/rss/1'
        item.published = datetime.now()
        item.save()

        # Actual test
        result = self.api_client.get('/api/0.9.5/item/')
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(content.keys(), ['meta', 'objects'])
        self.assertEqual(
            content['meta'].keys(),
            ['previous', 'total_count', 'offset', 'limit', 'next'])
        self.assertEqual(content['meta']['previous'], None)
        self.assertEqual(content['meta']['total_count'], 1)
        self.assertEqual(content['meta']['offset'], 0)
        self.assertEqual(content['meta']['limit'], 20)
        self.assertEqual(content['meta']['next'], None)
Exemplo n.º 7
0
    def test_add_subscriber(self):
        user = User()
        user.email = "Bob"
        user.save()

        feed = Feed()
        feed.title = "BoingBoing"
        feed.link = "http://boingboing.net"
        feed.save()

        item = FeedItem()
        item.title = "Octopus v. Platypus"
        item.description = "A fight to the death."
        item.link = item.guid = "http://www.example.com/rss/post"
        item.published = datetime.now()
        item.feed = feed
        item.save()

        # Note carefully... we can safely call add_subscriber at any
        # point after User and Feed creation and be confident that we'll
        # never create duplicate UserFeedItem join table entries.
        #
        # All existing items *before* add_subscriber are added to user
        # during add_subscriber time
        #
        # All new items *after* subscription are added to user during
        # FeedItem post_save() signal
        feed.add_subscriber(user)

        item2 = FeedItem()
        item2.title = "Cute bunny rabbit video"
        item2.description = "They die at the end."
        item2.link = item.guid = "http://www.example.com/rss/post"
        item2.published = datetime.now()
        item2.feed = feed
        item2.save()

        self.assertEqual(feed.subscribers.count(), 1)
        self.assertEqual(user.feeditems.count(), 2)
Exemplo n.º 8
0
    def test_basics(self):
        user = User()
        user.email = "Bob"
        user.save()

        feed = Feed()
        feed.title = "BoingBoing"
        feed.link = "http://boingboing.net"
        feed.save()
        feed.add_subscriber(user)

        item = FeedItem()
        item.title = "Octopus v. Platypus"
        item.description = "A fight to the death."
        item.link = item.guid = "http://www.example.com/rss/post"
        item.published = datetime.now()
        item.feed = feed
        item.save()

        # Saving an item in a feed should automatically result in
        # subscribed users seeing all those new items.
        self.assertEqual(user.feeditems.count(), 1)
Exemplo n.º 9
0
    def test_user_subscribe(self):
        '''Test the syntactic sugar monkeypatch for User.subscribe.'''
        user = User()
        user.email = 'Bob'
        user.save()

        feed = Feed()
        feed.title = 'BoingBoing'
        feed.link = 'http://boingboing.net'
        feed.save()

        unused = Feed()
        unused.title = 'xkcd'
        unused.save()

        item = FeedItem()
        item.title = 'Octopus v. Platypus'
        item.description = 'A fight to the death.'
        item.link = item.guid = 'http://www.example.com/rss/post'
        item.published = datetime.now()
        item.feed = feed
        item.save()

        item2 = FeedItem()
        item2.title = 'Cute bunny rabbit video'
        item2.description = 'They die at the end.'
        item2.link = item.guid = 'http://www.example.com/rss/post'
        item2.published = datetime.now()
        item2.feed = feed
        item2.save()

        user.subscribe(feed)

        self.assertEqual(user.feeds.count(), 1)
        self.assertEqual(user.feeditems.count(), 2)
        self.assertEqual(user.feeds[0].title, feed.title)

        # Testing we are using order_by() in User.feeditems() monkeypatch
        self.assertEqual(user.feeditems[0].title, item.title)
Exemplo n.º 10
0
    def test_put_starred(self):
        '''We can set 'starred' via the API.'''
        # Test data
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title -_-'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()
        useritem = UserFeedItem.objects.get(user=self.user, item=item, feed=feed)
        endpoint = '/api/0.9.5/item/{0}/'.format(useritem.pk)
        resource = json.loads(self.api_client.get(endpoint).content)
        resource['starred'] = True

        # Actual test
        result = self.api_client.put(
            endpoint, format='json', data=resource)
        self.assertEqual(result.status_code, 204)

        new_resource = json.loads(self.api_client.get(endpoint).content)
        self.assertEqual(new_resource['starred'], True)
Exemplo n.º 11
0
    def test_lookup_by_starred(self):
        '''Only return the unread items.'''
        # Test data
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()

        item2 = FeedItem()
        item2.feed = feed
        item2.title = 'Feed title 2'
        item2.link = 'http://www.paulhummer.org/rss/2'
        item2.guid = 'http://www.paulhummer.org/rss/2'
        item2.published = datetime.now()
        item2.save()

        item3 = FeedItem()
        item3.feed = feed
        item3.title = 'Feed title 3'
        item3.link = 'http://www.paulhummer.org/rss/3'
        item3.guid = 'http://www.paulhummer.org/rss/3'
        item3.published = datetime.now()
        item3.save()

        userfeeditem = UserFeedItem.objects.get(
            user=self.user, feed=feed, item=item)
        userfeeditem.starred = True
        userfeeditem.save()

        userfeeditem2 = UserFeedItem.objects.get(
            user=self.user, feed=feed, item=item2)
        userfeeditem2.starred = True
        userfeeditem2.save()

        # Actual test
        result = self.api_client.get(
            '/api/0.9.5/item/?starred=True')
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(len(content['objects']), 2)

        result = self.api_client.get(
            '/api/0.9.5/item/?starred=False')
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(len(content['objects']), 1)
Exemplo n.º 12
0
    def test_lookup_by_unread_and_feed(self):
        '''Only return the unread items by feed.'''
        # Test data
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()

        item2 = FeedItem()
        item2.feed = feed
        item2.title = 'Feed title 2'
        item2.link = 'http://www.paulhummer.org/rss/2'
        item2.guid = 'http://www.paulhummer.org/rss/2'
        item2.published = datetime.now()
        item2.save()

        userfeed = UserFeed.objects.get(user=self.user, feed=feed)

        userfeeditem = UserFeedItem.objects.get(
            user=self.user, feed=feed, item=item)
        userfeeditem.read = True
        userfeeditem.save()

        mike = User.objects.create_user(
            'mike', '*****@*****.**', password='******')
        mike.save()
        feed2 = Feed.create_and_subscribe(
            'Gothamist', 'http://feeds.gothamistllc.com/gothamist05-', None, mike)
        item4 = FeedItem()
        item4.feed = feed2
        item4.title = 'Feed title'
        item4.link = 'http://www.gothamist.com/rss/1'
        item4.guid = 'http://www.gothamist.com/rss/1'
        item4.published = datetime.now()
        item4.save()

        # Actual test
        result = self.api_client.get(
            '/api/0.9.5/item/?read=False&feed={0}'.format(userfeed.pk))
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(len(content['objects']), 1)
Exemplo n.º 13
0
    def test_sort_published(self):
        '''We can sort by 'published'.'''
        # Test data
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed 1'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()

        item = FeedItem()
        item.feed = feed
        item.title = 'Feed 2'
        item.link = 'http://www.paulhummer.org/rss/2'
        item.guid = 'http://www.paulhummer.org/rss/2'
        item.published = datetime.now() - timedelta(days=-1)
        item.save()

        item = FeedItem()
        item.feed = feed
        item.title = 'Feed 3'
        item.link = 'http://www.paulhummer.org/rss/3'
        item.guid = 'http://www.paulhummer.org/rss/3'
        item.published = datetime.now() - timedelta(days=-2)
        item.save()

        # Actual test
        result = self.api_client.get('/api/0.9.5/item/?order_by=-published')
        self.assertEqual(result.status_code, 200)

        content = json.loads(result.content)
        self.assertEqual(
            [item['title'] for item in content['objects']],
            ['Feed 3', 'Feed 2', 'Feed 1'])

        result = self.api_client.get('/api/0.9.5/item/?order_by=published')
        self.assertEqual(result.status_code, 200)

        content = json.loads(result.content)
        self.assertEqual(
            [item['title'] for item in content['objects']],
            ['Feed 1', 'Feed 2', 'Feed 3'])
Exemplo n.º 14
0
    def test_lookup_by_feed_id(self):
        '''Filter items by feed.id.'''
        # Test data
        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)
        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()

        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title 2'
        item.link = 'http://www.paulhummer.org/rss/2'
        item.guid = 'http://www.paulhummer.org/rss/2'
        item.published = datetime.now()
        item.save()

        feed2 = Feed.create_and_subscribe(
            'Gothamist', 'http://feeds.gothamistllc.com/gothamist05', None,
            self.user)
        item2 = FeedItem()
        item2.feed = feed2
        item2.title = 'Feed title'
        item2.link = 'http://www.gothamist.com/rss/1'
        item2.guid = 'http://www.gothamist.com/rss/1'
        item2.published = datetime.now()
        item2.save()

        userfeed = UserFeed.objects.get(user=self.user, feed=feed)

        # Actual test
        result = self.api_client.get(
            '/api/0.9.5/item/?feed={0}'.format(userfeed.pk))
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(len(content['objects']), 2)
Exemplo n.º 15
0
    def test_lookup_by_feed_id_withoffset(self):
        '''Filter items by feed.id.

        A bug existed where a lookup by id would return items for a different
        feed. This occurs if Feed.pk and UserFeed.pk were not the same, which
        isn't normally the case in test data.
        '''
        # Test data
        deadfeed = Feed.create_raw(
            'Dead Feed 1', 'http://example.com/dead1.rss',
            'http://example.com/dead1.html')
        deadfeed2 = Feed.create_raw(
            'Dead Feed 2', 'http://example.com/dead2.rss',
            'http://example.com/dead2.html')

        feed = Feed.create_and_subscribe(
            'Paul Hummer', 'http://www.paulhummer.org/rss', None, self.user)

        # Let's make sure they don't share ids
        userfeed = UserFeed.objects.get(user=self.user, feed=feed)
        self.assertNotEqual(feed.pk, userfeed.pk)

        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title'
        item.link = 'http://www.paulhummer.org/rss/1'
        item.guid = 'http://www.paulhummer.org/rss/1'
        item.published = datetime.now()
        item.save()

        item = FeedItem()
        item.feed = feed
        item.title = 'Feed title 2'
        item.link = 'http://www.paulhummer.org/rss/2'
        item.guid = 'http://www.paulhummer.org/rss/2'
        item.published = datetime.now()
        item.save()

        deadfeed3 = Feed.create_raw(
            'Dead Feed 3', 'http://example.com/dead3.rss',
            'http://example.com/dead3.html')

        feed2 = Feed.create_and_subscribe(
            'Gothamist', 'http://feeds.gothamistllc.com/gothamist05', None,
            self.user)
        item2 = FeedItem()
        item2.feed = feed2
        item2.title = 'Feed title'
        item2.link = 'http://www.gothamist.com/rss/1'
        item2.guid = 'http://www.gothamist.com/rss/1'
        item2.published = datetime.now()
        item2.save()

        userfeed = UserFeed.objects.get(user=self.user, feed=feed)

        # Actual test
        result = self.api_client.get(
            '/api/0.9.5/item/?feed={0}'.format(userfeed.pk))
        self.assertEqual(200, result.status_code)

        content = json.loads(result.content)
        self.assertEqual(len(content['objects']), 2)