def test_no_user(self): """ Test: No user in session. Expected result: Error returned. """ request = self.factory.get('/doesnt/matter') request.session = {} json_ret = json.loads(ajax.create_feed(request, True, True, 15, [])) self.assertEqual(json_ret["feed_url"], "", "Url not empty.") self.assertEqual(json_ret["error"], "You need to be authorized to call this.", "Wrong error returned.")
def test_create_feed(self): """ Test: User exists and everything goes ok. Expected result: No exceptions are raised """ request = self.factory.get('/doesnt/matter') request.session = {"cur_user" : self.user.id} json_ret = json.loads(ajax.create_feed(request, True, True, 15, [])) self.assertNotEqual(json_ret["feed_url"], "", "Url is empty.") self.assertNotEqual(json_ret["feed_summary"], "", "Summary is empty.") self.assertTrue("assigned only to me" in json_ret["feed_summary"], "Summary is wrong.")
def test_exception(self): """ Test: logic.create_feed raises exception. Expected result: Error returned. """ request = self.factory.get('/doesnt/matter') request.session = {"cur_user" : self.user.id} original_create_feed = ajax.logic.create_feed ajax.logic.create_feed = raise_exception json_ret = json.loads(ajax.create_feed(request, True, True, 15, [])) ajax.logic.create_feed = original_create_feed self.assertEqual(json_ret["feed_url"], "", "Url not empty.") self.assertTrue(EXCEPTION_STRING in json_ret["error"], "Wrong error returned.")