def test_read_functions(self): """ check read functions for an entry """ httpd = FeedParserTestServer(1) httpd.start() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_2.rss' tempRss = Feed(name="Temp", url=rssUrl) tempRss.fetch() self.assertEqual(tempRss.unread(), 1) entry = FeedEntry.objects.all()[0] entry.markRead() self.assertEqual(tempRss.unread(), 0)
def test_view_ajax_getFeed(self): """ Get Full Feed """ httpd = FeedParserTestServer(1) httpd.start() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_2.rss' tempRss = Feed(name="Temp", url=rssUrl) tempRss.fetch() tempRss.save() response = self.client.get('/getFeed/1/', HTTP_X_REQUESTED_WITH='XMLHttpRequest') #print response.content self.assertEqual(len(response.context['FeedList']), 1)
def test_changed_update(self): """Update and check for new entries""" httpd = FeedParserTestServer(2) httpd.start() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_1.rss' tempRss = Feed(name="Craig's List Free", url=rssUrl) tempRss.fetch() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_1_update.rss' tempRss = Feed(url=rssUrl) tempRss.save() newEntry = tempRss.fetch() tempFeedList = FeedEntry.objects.all() self.assertEqual(len(tempFeedList), 105) self.assertEqual(len(newEntry), 5)
def test_view_ajax_mark_read(self): """ Test view for mark server """ httpd = FeedParserTestServer(1) httpd.start() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_2.rss' tempRss = Feed(name="Temp", url=rssUrl) tempRss.fetch() response = self.client.get('/markRead/1/', HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, 200) self.assertEqual(tempRss.unread(), 0) # bad request response = self.client.get('/markRead/10/', HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, 500)
def test_double_update(self): """Check for no changes to model when rss is not changed""" httpd = FeedParserTestServer(2) httpd.start() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_1.rss' tempRss = Feed(name="Craig's List Free", url=rssUrl) newEntry = tempRss.fetch() tempFeedList = FeedEntry.objects.all() self.assertEqual(len(tempFeedList), 100) self.assertEqual(len(newEntry), 100) tempFeedList = FeedEntry.objects.get(link='http://columbus.craigslist.org/zip/1326047327.html') self.assertEqual(tempFeedList.title, 'at the curb: dresser and small table (Royal Dornoch Cir. Delaware 43015)') newEntry = tempRss.fetch() tempFeedList = FeedEntry.objects.all() self.assertEqual(len(tempFeedList), 100) tempFeedList = FeedEntry.objects.get(link='http://columbus.craigslist.org/zip/1326047327.html') self.assertEqual(len(newEntry), 0)
def test_double_update(self): """Check for no changes to model when rss is not changed""" httpd = FeedParserTestServer(2) httpd.start() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_1.rss' tempRss = Feed(name="Craig's List Free", url=rssUrl) newEntry = tempRss.fetch() tempFeedList = FeedEntry.objects.all() self.assertEqual(len(tempFeedList), 100) self.assertEqual(len(newEntry), 100) tempFeedList = FeedEntry.objects.get( link='http://columbus.craigslist.org/zip/1326047327.html') self.assertEqual( tempFeedList.title, 'at the curb: dresser and small table (Royal Dornoch Cir. Delaware 43015)' ) newEntry = tempRss.fetch() tempFeedList = FeedEntry.objects.all() self.assertEqual(len(tempFeedList), 100) tempFeedList = FeedEntry.objects.get( link='http://columbus.craigslist.org/zip/1326047327.html') self.assertEqual(len(newEntry), 0)
def add_feed(request): user = request.user if not request.POST: ##todo fixme respond correctly return None feed_url = request.POST['url'] try: feed = Feed.objects.get(url=feed_url) except Feed.DoesNotExist: feed = Feed() feed.url = feed_url feed.save() try: category_slug=request.POST['category'] base_category = Category.objects.get(category_slug=category_slug) category = UserCategory.objects.get(category=base_category,user=user) except: default_category = Category.objects.get(category_slug=DEFAULT_CATEGORY_SLUG) category = UserCategory.objects.get(category=default_category,user=user) category.feeds.add(feed) category.save() feed.fetch() return HttpResponseRedirect(reverse('my_entries'))