def test_get_article(self): #Test with anonymous user response = dajaxice_get(self.client, 'feeds', 'get_article', {'tab_id': self.tabs[2].id, 'article_no': 1}) self.assertEqual(json.loads(response.content), {'success': False, 'article': None}) #Test with logged in user, valid tab self.client.login(email='*****@*****.**', password='******') response = dajaxice_get(self.client, 'feeds', 'get_article', {'tab_id': self.tabs[2].id, 'article_no': 1}) self.assertEqual(json.loads(response.content).get('success'), True) self.assertIsInstance(json.loads(response.content).get('article'), dict) #Try retreiving the next article response = dajaxice_get(self.client, 'feeds', 'get_article', {'tab_id': self.tabs[2].id, 'article_no': 2}) self.assertEqual(json.loads(response.content).get('success'), True) self.assertIsInstance(json.loads(response.content).get('article'), dict)
def test_get_tags(self): ''' get_tags must return a list of tags matching the query ''' #Valid query response = dajaxice_get(self.client, 'tags', 'get_tags', {'query': 'nat'}) self.assertEqual(json.loads(response.content)['tags'], [self.tags[3]]) #Invalid query response = dajaxice_get(self.client, 'tags', 'get_tags', {'query': 'Habababa'}) self.assertEqual(json.loads(response.content)['tags'], []) #Empty query should return empty list response = dajaxice_get(self.client, 'tags', 'get_tags', {'query': ''}) self.assertEqual(json.loads(response.content)['tags'], [])
def test_get_tab_tags(self): ''' get_tab_tags must return the tags associated with a tab ''' #Anonymous user response = dajaxice_get(self.client, 'tags', 'get_tab_tags', {'tab_id': self.tabs[0].id}) self.assertEqual(json.loads(response.content)['tags'], []) #Logged in user self.client.login(email=self.user_email, password=self.user_pass) response = dajaxice_get(self.client, 'tags', 'get_tab_tags', {'tab_id': self.tabs[0].id}) self.assertEqual(json.loads(response.content)['tags'], self.tags) #Invalid tab id response = dajaxice_get(self.client, 'tags', 'get_tab_tags', {'tab_id': 100}) self.assertEquals(json.loads(response.content)['tags'], [])