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)
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