Esempio n. 1
0
	def test_find_sources(self):
		'''
		find_sources should return the sources that matches the given query
		'''
		#Valid query
		response = dajaxice_get(self.client, 'newsreader', 'find_sources', {'query': 'hindu'})
		self.assertEqual(json.loads(response.content), {'names': [self.sources[1].name, self.sources[2].name]})

		#Invalid query
		response = dajaxice_get(self.client, 'newsreader', 'find_sources', {'query': 'Habababa'})
		self.assertEqual(json.loads(response.content), {'names': []})

		#Empty query
		response = dajaxice_get(self.client, 'newsreader', 'find_sources', {'query': ''})
		self.assertEqual(json.loads(response.content), {'names': []})
Esempio n. 2
0
	def test_get_sources(self):
		'''
		get_sources must return the sources associated with a particular tab. If the tab id is invalid, results must be empty
		'''
		#Empty list must be returned for anonymous user
		response = dajaxice_get(self.client, 'newsreader', 'get_sources', {'tab_id': self.tabs[0].id})
		self.assertEqual(json.loads(response.content), {'sources': []})

		#Valid query must return the sources associated with the tab
		self.client.login(email=self.user_email, password=self.user_pass)
		response = dajaxice_get(self.client, 'newsreader', 'get_sources', {'tab_id': self.tabs[0].id})
		self.assertEqual(json.loads(response.content), {'sources': [self.sources[0].name, self.sources[1].name, self.sources[2].name]})

		#Invalid tab id must return empty list
		response = dajaxice_get(self.client, 'newsreader', 'get_sources', {'tab_id': 100})
		self.assertEqual(json.loads(response.content), {'sources': []})

		#Tab with empty sources
		response = dajaxice_get(self.client, 'newsreader', 'get_sources', {'tab_id': self.tabs[2].id})
		self.assertEqual(json.loads(response.content), {'sources': []})