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_subscribers(self):
        bob = User()
        bob.email = "Bob"
        bob.save()
        steve = User()
        steve.email = "Steve"
        steve.save()

        feed = Feed()
        feed.title = "Some Political Bullshit"
        feed.link = "http://bs.com/rss"
        feed.site = "http://bs.com"
        feed.save()
        feed.add_subscriber(bob)
        feed.add_subscriber(steve)

        other_feed = Feed()
        other_feed.title = "Mom's recipe blog"
        other_feed.site = "http://yourmom.com"
        other_feed.link = "http://yourmom.com/rss"
        other_feed.save()
        other_feed.add_subscriber(steve)

        self.assertEqual(feed.subscribers.count(), 2)
        self.assertEqual(other_feed.subscribers.count(), 1)
Esempio n. 4
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. 5
0
    def test_unauthorized(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.save()

        uri = '/api/0.9/feed/{0}'.format(feed.pk)
        response = self.client.get(uri, follow=True)
        self.assertEqual(response.status_code, 404)
Esempio n. 6
0
    def test_feeds_but_no_subscriptions(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.save()

        response = self.client.get('/api/0.9/feed/')
        content = json.loads(response.content)
        objects = content['objects']

        self.assertEqual(len(objects), 0)
Esempio n. 7
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)
Esempio n. 8
0
    def test_run(self):
        with open(SECURE_FILE) as f:
            secure = f.read()

        owner = User()
        owner.email = 'Alex'
        owner.save()

        other_owner = User()
        other_owner.email = 'Mike'
        other_owner.save()
        other_feed = Feed()
        other_feed.save()
        other_owner.subscribe(other_feed)

        task = tasks.SyncFromReaderAPITask()
        result = task.delay(owner, 10, '*****@*****.**', secure)

        self.assertTrue(result.successful())

        feeds = Feed.objects.all()
        # Tricky. We are subscribed to 122 feeds
        # We create another feed above, to get to 123
        # But 3 feeds in the import were "shared-with-you" so the total
        # number of feeds should be 126
        self.assertEqual(feeds.count(), 126)

        total_feeds = Feed.objects.all().count()
        owner = User.objects.get(pk=owner.pk)
        # Verify that we do not get subscribed to feeds when items are
        # 'shared-with-you'.
        self.assertEqual(owner.feeds.count(), 122)

        # Ensure create_raw() won't create a duplicate feed
        title = u'A Softer World'
        link = u'http://www.rsspect.com/rss/asw.xml'
        site = u'http://www.asofterworld.com'

        feed = Feed.objects.get(link=link)
        duplicate = Feed.create_raw(title, link, site)
        duplicate.add_subscriber(owner)
        self.assertEqual(feed.pk, duplicate.pk)

        # Testing that subscribing a second time doesn't blow up.
        duplicate2 = Feed.create_and_subscribe(title, link, site, owner)
        self.assertEqual(feed.pk, duplicate2.pk)

        tagged = UserFeedItem.objects.filter(tags__name__in=['shared-with-you'])
        self.assertEqual(len(tagged), 10)
Esempio n. 9
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. 10
0
    def test_run(self):
        feed = Feed()
        feed.link = 'http://paulhummer.org/rss'
        last_fetched = datetime.now() - timedelta(minutes=31)
        feed.last_fetched = last_fetched
        feed.save()

        task = tasks.UpdateFeedTask()
        result = task.delay()

        self.assertTrue(result.successful())

        # Re-fetch the feed
        feed = Feed.objects.get(link='http://paulhummer.org/rss')
        self.assertNotEqual(feed.last_fetched, last_fetched)
        self.assertEqual(feed.items.count(), 20)
Esempio n. 11
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. 12
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. 13
0
    def test_unsubscribe(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.save()
        feed.add_subscriber(self.user)

        #Ensure the user is subscribed.
        response = self.api_client.get('/api/0.9/feed/')
        content = json.loads(response.content)
        self.assertEqual(len(content['objects']), 1)

        response = self.api_client.delete(
            content['objects'][0]['resource_uri'])
        self.assertEqual(response.status_code, 204)

        #Ensure the feed is now deleted.
        response = self.api_client.get('/api/0.9/feed/')
        content = json.loads(response.content)
        self.assertEqual(len(content['objects']), 0)
Esempio n. 14
0
    def test_malformed(self):
        owner = User()
        owner.email = "Bob"
        owner.save()

        other_owner = User()
        other_owner.email = "Mike"
        other_owner.save()
        other_feed = Feed()
        other_feed.save()
        other_owner.subscribe(other_feed)

        # Lack of title
        title = u"rockmnkey"
        link = u"http://rockmnkey.livejournal.com/data/rss"
        site = u"http://rockmnkey.livejournal.com/"
        feed = Feed.create_and_subscribe(title, link, site, owner)

        # Duplicate entries
        title = u"Canonical Voices"
        link = u"http://voices.canonical.com/feed/atom/"
        site = u"http://voices.canonical.com/"
        feed = Feed.create_and_subscribe(title, link, site, owner)

        # Lack of atom_id
        title = u"aw's blog"
        link = u"http://aw.lackof.org/~awilliam/blog/index.rss"
        site = u"http://aw.lackof.org/~awilliam/blog/"
        feed = Feed.create_and_subscribe(title, link, site, owner)

        # Dead feed
        title = u"Clayton - MySpace Blog"
        link = u"http://blog.myspace.com/blog/rss.cfm?friendID=73367402"
        site = None
        feed = Feed.create_and_subscribe(title, link, site, owner)

        feeds = Feed.objects.all()
        self.assertEqual(feeds.count(), 5)

        total_feeds = Feed.objects.all().count()
        owner = User.objects.get(pk=owner.pk)
        self.assertEqual(owner.feeds.count(), total_feeds - 1)
Esempio n. 15
0
    def test_tagging(self):
        bob = User()
        bob.email = "Bob"
        bob.save()

        feed = Feed()
        feed.title = "Some Political Bullshit"
        feed.link = "http://bs.com/rss"
        feed.site = "http://bs.com"
        feed.save()
        feed.add_subscriber(bob)

        other_feed = Feed()
        other_feed.title = "Mom's recipe blog"
        other_feed.link = "http://yourmom.com/rss"
        other_feed.site = "http://yourmom.com"
        other_feed.save()
        other_feed.add_subscriber(bob)

        userfeed = UserFeed.objects.get(user=bob, feed=feed)
        userfeed.tags.add("politics", "mom")

        userfeed2 = UserFeed.objects.get(user=bob, feed=other_feed)
        userfeed2.tags.add("mom", "food")

        self.assertIn("mom", [tag.name for tag in userfeed.tags.all()])
        self.assertIn("politics", [tag.name for tag in userfeed.tags.all()])
        self.assertNotIn("food", [tag.name for tag in userfeed.tags.all()])

        tagged = UserFeed.objects.filter(tags__name__in=["mom"])
        self.assertEquals(len(tagged), 2)

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

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

        userfeed.tags.clear()
        self.assertEquals(len(userfeed.tags.all()), 0)
Esempio n. 16
0
    def test_basics(self):
        bob = User()
        bob.email = "Bob"
        bob.save()
        steve = User()
        steve.email = "Steve"
        steve.save()

        feed = Feed()
        feed.title = "Some Political Bullshit"
        feed.link = "http://bs.com/rss"
        feed.site = "http://bs.com"
        feed.save()

        other_feed = Feed()
        other_feed.title = "Mom's recipe blog"
        other_feed.link = "http://yourmom.com/rss"
        other_feed.site = "http://yourmom.com"
        other_feed.save()

        user_feed = UserFeed()
        user_feed.user = bob
        user_feed.feed = feed
        user_feed.save()

        user_feed2 = UserFeed()
        user_feed2.user = steve
        user_feed2.feed = feed
        user_feed2.save()

        user_feed3 = UserFeed()
        user_feed3.user = steve
        user_feed3.feed = other_feed
        user_feed3.save()

        self.assertEqual(feed.subscribers.count(), 2)
        self.assertEqual(other_feed.subscribers.count(), 1)

        feeds_for_steve = UserFeed.objects.filter(user=steve)
        self.assertEqual(len(feeds_for_steve), 2)
Esempio n. 17
0
    def test_single_resource_list(self):
        feed = Feed()
        feed.link = 'http://www.paulhummer.org/rss'
        feed.save()
        feed.add_subscriber(self.user)

        response = self.client.get('/api/0.9/feed/')
        content = json.loads(response.content)
        objects = content['objects']

        self.assertEqual(len(objects), 1)

        feed = Feed.objects.get(pk=feed.pk)
        resource = objects[0]

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

        self.assertEqual(
            sorted(resource.keys()),
            [u'description', u'id', u'items', u'link', u'resource_uri', u'title'])
Esempio n. 18
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)
Esempio n. 19
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)
Esempio n. 20
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)
Esempio n. 21
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)
Esempio n. 22
0
    def test_run(self):
        owner = User()
        owner.email = 'Bob'
        owner.save()

        other_owner = User()
        other_owner.email = 'Mike'
        other_owner.save()
        other_feed = Feed()
        other_feed.save()
        other_owner.subscribe(other_feed)

        task = tasks.EatTakeoutTask()
        result = task.delay(
            owner,
            os.path.join(TESTDATA_DIR, '*****@*****.**'))

        self.assertTrue(result.successful())

        total_feeds = Feed.objects.all().count()
        owner = User.objects.get(pk=owner.pk)
        self.assertEqual(total_feeds, 146)
        self.assertEqual(owner.feeds.count(), 122)

        starred = UserFeedItem.objects.filter(starred=True)
        self.assertEqual(len(starred), 9)

        shared_with_me = UserFeedItem.objects.filter(tags__name__in=['shared-with-you'])
        self.assertEqual(len(shared_with_me), 31)

        shared = UserFeedItem.objects.filter(tags__name__in=['shared'])
        self.assertEqual(len(shared), 1)

        # See how all the above should add up!
        imported = UserFeedItem.objects.filter(tags__name__in=['imported'])
        self.assertEqual(len(imported), 41)
Esempio n. 23
0
    def test_for_user(self):
        """Test FeedItemManager.for_user."""
        user = User()
        user.email = "*****@*****.**"
        user.save()

        feed = Feed()
        feed.link = "http://paulhummer.org/rss"
        feed.site = "http://paulhummer.org/"
        feed.save()
        user.subscribe(feed)

        other_feed = Feed()
        other_feed.link = "http://www.chizang.net/alex/blog/feed/"
        other_feed.site = "http://www.chizang.net/alex/blog/"
        other_feed.save()

        userfeeditems = FeedItem.objects.for_user(user)
        self.assertEqual(userfeeditems.count(), feed.items.count())

        other_feed.add_subscriber(user)

        userfeeditems = FeedItem.objects.for_user(user)
        self.assertEqual(userfeeditems.count(), feed.items.count() + other_feed.items.count())