Esempio n. 1
0
    def test_resource_put_read(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.save()
        feed.update()
        feed.add_subscriber(self.user)

        response = self.client.get('/api/0.9/item/')
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        objects = content['objects']
        resource = objects[0]

        response = self.client.get(resource['resource_uri'])
        self.assertEqual(response.status_code, 200)

        resource = json.loads(response.content)

        self.assertEqual(resource['read'], False)

        resource['read'] = True

        self.client.put(
            resource['resource_uri'],
            data=json.dumps(resource),
            content_type='application/json')

        response = self.client.get(resource['resource_uri'])
        resource = json.loads(response.content)
        self.assertEqual(resource['read'], True)
Esempio n. 2
0
    def test_dates(self):
        links = [
            "http://theworstthingever.com/index.rdf",
            "http://news.ycombinator.com/rss",
            "http://aw.lackof.org/~awilliam/blog/index.rss",
            "http://adeem.me/blog/feed/rss/",
            "http://lusars.net/~mhunter/rss.xml",
            "http://feeds.feedburner.com/Manbabies",
            "http://www.365portraits.com/rss.php",
            "http://iphonedevelopmentbits.com/feed/rss",
            "http://blog.myspace.com/blog/rss.cfm?friendID=4470742",
        ]

        for link in links:
            feed = Feed()
            feed.link = link
            feed.save()
            feed.update()
            first_update = feed.items.count()

            # Pause a few seconds, so when we fetch again, utcnow() in the
            # model will be a different time (and therefore potentially a
            # different GUID)
            time.sleep(3)
            feed.update()
            second_update = feed.items.count()

            # Ensure that fetching feeds with missing or malformed dates
            # do not result in different GUIDs (they should resolve to
            # the same GUID).
            self.assertEqual(first_update, second_update)
Esempio n. 3
0
    def test_resource_read(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.save()
        feed.update()
        feed.add_subscriber(self.user)

        response = self.client.get('/api/0.9/item/')
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        objects = content['objects']
        resource = objects[0]

        response = self.client.get(resource['resource_uri'])
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)

        resource_id = resource['resource_uri'].split('/')[-2]
        item = FeedItem.objects.get(pk=resource_id)
        useritem = UserFeedItem.objects.get(user=self.user, item=item)

        self.assertEqual(resource['read'], False)

        useritem.read = True
        useritem.save()

        response = self.client.get(resource['resource_uri'])
        resource = json.loads(response.content)

        self.assertEqual(resource['read'], True)
Esempio n. 4
0
    def test_update(self):
        user = User()
        user.email = "Bob"
        user.save()

        feed = Feed()
        feed.link = "http://paulhummer.org/rss"
        feed.save()
        feed.update()

        # Re-fetch the feed
        feed = Feed.objects.get(pk=feed.pk)

        self.assertEqual(feed.items.count(), 20)
        self.assertEqual(feed.title, "Dapper as...")
        self.assertTrue(feed.description.startswith("Bike rider"))
Esempio n. 5
0
    def test_unauthorized(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.save()
        self.user.subscribe(feed)

        #Create another feed that the user isn't subscribed to.
        unused_feed = Feed()
        unused_feed.link = 'http://xkcd.com/atom.xml'
        unused_feed.site = 'http://xkcd.com/'
        unused_feed.save()
        unused_feed.update()
        feeditem_id = unused_feed.items.all()[0].pk

        response = self.client.get(
            '/api/0.9/item/{0}'.format(feeditem_id),
            follow=True)
        self.assertEqual(response.status_code, 404)
Esempio n. 6
0
    def test_single_resource(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.site = 'http://www.paulhummer.org/'
        feed.save()
        feed.update()
        self.user.subscribe(feed)

        #Create another feed that the user isn't subscribed to.
        unused_feed = Feed()
        unused_feed.link = 'http://www.chizang.net/alex/blog/feed/'
        unused_feed.site = 'http://www.chizang.net/alex/blog/'
        unused_feed.save()
        unused_feed.update()

        response = self.client.get('/api/0.9/item/')
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        objects = content['objects']
        resource = objects[0]

        response = self.client.get(resource['resource_uri'])
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)

        resource_id = resource['resource_uri'].split('/')[-2]
        item = FeedItem.objects.get(pk=resource_id)
        useritem = UserFeedItem.objects.get(user=self.user, item=item)

        self.assertEqual(resource['description'], item.description)
        self.assertEqual(resource['link'], item.link)
        self.assertEqual(resource['read'], useritem.read)
        self.assertEqual(resource['title'], item.title)

        feed_id = int(resource['feed']['id'])
        self.assertEqual(feed_id, item.feed.pk)

        self.assertEqual(
            sorted(resource.keys()),
            [u'description', u'feed', u'id', u'link', u'published', u'read',
             u'resource_uri', u'title'])
Esempio n. 7
0
    def test_single_resource_list(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.site = 'http://www.paulhummer.org/'
        feed.save()
        feed.update()
        self.user.subscribe(feed)

        response = self.client.get('/api/0.9/item/')
        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content)
        objects = content['objects']

        self.assertEqual(len(objects), 20)

        resource = objects[0]
        resource_id = resource['resource_uri'].split('/')[-2]
        item = FeedItem.objects.get(pk=resource_id)

        self.assertEqual(resource['description'], item.description)
        self.assertEqual(resource['title'], item.title)
        self.assertEqual(resource['link'], item.link)