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)
def test_duplicates(self): user = User() user.email = 'Bob' user.save() tmp = Feed() tmp.title = 'Marginal Revolution' tmp.link = 'http://feeds.feedburner.com/marginalrevolution/feed' tmp.site = 'http://marginalrevolution.com/' last_fetched = datetime.now() - timedelta(minutes=31) tmp.last_fetched = last_fetched # Fetch #1 feed = Feed.create_and_subscribe(tmp.title, tmp.link, tmp.site, user) # Fetch #2 task1 = tasks.UpdateFeedTask() result1 = task1.delay() # Force fetch #3 last_fetched = datetime.now() - timedelta(minutes=31) feed.last_fetched = last_fetched feed.save() task2 = tasks.UpdateFeedTask() result2 = task2.delay() self.assertEqual(feed.feeditems.count(), 15)
def test_duplicates(self): """Ensure that we can't create duplicate feeds using create_and_subscribe()""" user = User() user.email = "Bob" user.save() feed = Feed() feed.title = "BoingBoing" feed.link = "http://boingboing.net/atom.xml" feed.site = "http://boingboing.net" f = Feed.create_and_subscribe(feed.title, feed.link, feed.site, user) feed2 = Feed() feed2.title = "BoingBoing" feed2.link = "http://boingboing.net/atom.xml" feed2.site = "http://boingboing.net" # XXX: TODO: we need to add/test duplicate checks save() too :( f2 = Feed.create_and_subscribe(feed2.title, feed2.link, feed2.site, user) self.assertEqual(f.pk, f2.pk)
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)
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)
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)
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)
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)
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)