Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
0
def _new_user_item(user, feed, entry):
    try:
        item = FeedItem.objects.get(reader_guid=entry.id)
    except ObjectDoesNotExist:
        tmp = FeedItem()
        tmp.feed = feed
        tmp.title = entry.title
        tmp.link = entry.url
        tmp.atom_id = ''

        tmp.description = entry.content
        tmp.reader_guid = entry.id
        tmp.published = datetime.utcfromtimestamp(entry.time)
        tmp.guid = tmp.calculate_guid()

        item = FeedItem._get_or_create(tmp)

    try:
        user_item = item.userfeeditem(user)
    except ObjectDoesNotExist:
        # Nasty. The above only works if a user is actually
        # subscribed to a feed. However, it can be the case
        # where we're trying to import Google Reader, and we're
        # processing items that have been shared with us. In
        # this case, we probably won't be subscribed to the
        # feed, and more, we probably don't want to subscribe to
        # the feed. So manually create a UserFeedItem so the
        # Item can be accessed by the User. We can pull it out
        # of the db later by searching for the 'shared-with-you'
        # tag.
        user_item = UserFeedItem()
        user_item.item = item
        user_item.user = user
        user_item.feed = feed
        user_item.save()

    user_item.read = entry.read
    user_item.starred = entry.starred
    for t in entry.tags:
        user_item.tags.add(t)
    user_item.save()

    return user_item
Exemplo n.º 6
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)