def test_refreshing_others_feed(self): user2 = User(username="******", password="******") user2.save() new_feed = Feed(title="another feed", url="http://anotherfeed.com", user=user2) new_feed.save() response = self.client.post("/api/feeds/{0}/refresh/".format(new_feed.id),format="json") self.assertEqual(response.status_code, 403)
def test_get_feed_not_owned_by_user_fails(self): user2 = User(username="******", email="*****@*****.**", password="******") user2.save() new_feed = Feed(title="another feed", url="http://anotherfeed.com", user=user2) new_feed.save() response = self.client.get("/api/feeds/{0}/".format(new_feed.id), format='json') self.assertEqual(response.status_code, 403)
def test_view_ajax_updateFeed(self): """ Update partial feed """ httpd = FeedParserTestServer(1) httpd.start() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_2.rss' tempRss = Feed(name="Temp", url=rssUrl) tempRss.save() response = self.client.get('/updateFeed/1/', HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(len(response.context['FeedList']), 1)
def test_view_ajax_updateFeed(self): """ Update partial feed """ httpd = FeedParserTestServer(1) httpd.start() rssUrl = 'http://localhost:8097/src/reader/test_rss/test_2.rss' tempRss = Feed(name="Temp", url=rssUrl) tempRss.save() response = self.client.get('/updateFeed/1/', HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(len(response.context['FeedList']), 1) #print response.content
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 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'))
class FeedViewSetTest(TestCase): # TODO: use local feeds not online def setUp(self): self.url = '/api/feeds/' # create user self.user = User(username="******", email="*****@*****.**", password="******") self.user.save() # Sample feed self.feed = Feed(title="Ars Technica", url="http://arstechnica.com/rss", user=self.user) self.feed.save() # setup request client self.client = APIClient() self.client.force_authenticate(user=self.user, token=self.user.auth_token) self.list_view = FeedViewSet.as_view({ 'get': 'list', 'post': 'create' }) self.detail_view = FeedViewSet.as_view({ 'put': 'update', 'delete': 'destroy', 'get': 'retrieve' }) def test_post_feed_when_authenticated_succeeds(self): response = self.client.post( self.url, { "url": "http://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml" }, format='json') self.assertEqual(response.status_code, 201) def test_get_feeds_of_another_user_fails(self): response = self.client.get(self.url, {'user_id': 2}, format='json') self.assertEqual(response.status_code, 403) def test_get_feed_owned_by_user_succeeds(self): response = self.client.get('/api/feeds/1/', format='json') self.assertEqual(response.status_code, 200) def test_get_feed_not_owned_by_user_fails(self): user2 = User(username="******", email="*****@*****.**", password="******") user2.save() new_feed = Feed(title="another feed", url="http://anotherfeed.com", user=user2) new_feed.save() response = self.client.get("/api/feeds/{0}/".format(new_feed.id), format='json') self.assertEqual(response.status_code, 403) def test_refreshing_own_feed(self): #TODO Add better test response = self.client.post("/api/feeds/1/refresh/", format="json") self.assertEqual(response.status_code, 201) def test_refreshing_others_feed(self): user2 = User(username="******", password="******") user2.save() new_feed = Feed(title="another feed", url="http://anotherfeed.com", user=user2) new_feed.save() response = self.client.post("/api/feeds/{0}/refresh/".format(new_feed.id),format="json") self.assertEqual(response.status_code, 403) def test_marking_own_feed_as_read(self): response = self.client.post("/api/feeds/{0}/mark_as_read/".format(self.feed.id), format="json") self.assertEqual(response.status_code, 200)