def test_remove_source(self): ''' remove_source must delete the source from the tab. Invalid requests must be ignored ''' #Anonymous user test response = dajaxice_post(self.client, 'newsreader', 'remove_source', {'tab_id': self.tabs[0].id, 'source_name': self.sources[0].name}) self.assertFalse(json.loads(response.content)['success']) #Logged in user self.client.login(email=self.user_email, password=self.user_pass) response = dajaxice_post(self.client, 'newsreader', 'remove_source', {'tab_id': self.tabs[0].id, 'source_name': self.sources[0].name}) self.assertTrue(json.loads(response.content)['success']) self.assertEqual(self.tabs[0].get_sources(), [self.sources[1], self.sources[2]]) #Invalid tab id response = dajaxice_post(self.client, 'newsreader', 'remove_source', {'tab_id': 100, 'source_name': self.sources[0].name}) self.assertFalse(json.loads(response.content)['success']) #Invalid source name response = dajaxice_post(self.client, 'newsreader', 'remove_source', {'tab_id': self.tabs[0].id, 'source_name': 'Habababa'}) self.assertFalse(json.loads(response.content)['success']) #Dis-associated source response = dajaxice_post(self.client, 'newsreader', 'remove_source', {'tab_id': self.tabs[0].id, 'source_name': self.sources[0].name}) self.assertFalse(json.loads(response.content)['success'])
def test_delete_tab(self): ''' delete_tab must delete a valid tab. ''' #Anonymous user test response = dajaxice_post(self.client, 'newsreader', 'delete_tab', {'tab_id': self.tabs[0].id}) self.assertFalse(json.loads(response.content)['success']) #Logged in user self.client.login(email=self.user_email, password=self.user_pass) response = dajaxice_post(self.client, 'newsreader', 'delete_tab', {'tab_id': self.tabs[0].id}) self.assertTrue(json.loads(response.content)['success']) #Invalid tab id response = dajaxice_post(self.client, 'newsreader', 'delete_tab', {'tab_id': 100}) self.assertFalse(json.loads(response.content)['success'])
def test_change_source_position(self): ''' change_source_position must change the position of the source ''' #Anonymous user test response = dajaxice_post(self.client, 'newsreader', 'change_source_position', {'tab_id': self.tabs[0].id, 'source_name': self.sources[0].name, 'position': 2}) self.assertFalse(json.loads(response.content)['success']) #Logged in user self.client.login(email=self.user_email, password=self.user_pass) response = dajaxice_post(self.client, 'newsreader', 'change_source_position', {'tab_id': self.tabs[0].id, 'source_name': self.sources[0].name, 'position': 2}) self.assertTrue(json.loads(response.content)['success']) self.assertEqual(self.tabs[0].get_sources(), [self.sources[1], self.sources[0], self.sources[2]]) #Invalid tab id response = dajaxice_post(self.client, 'newsreader', 'change_source_position', {'tab_id': 100, 'source_name': self.sources[0].name, 'position': 2}) self.assertFalse(json.loads(response.content)['success']) #Invalid source name response = dajaxice_post(self.client, 'newsreader', 'change_source_position', {'tab_id': self.tabs[0].id, 'source_name': 'Habababa', 'position': 1}) self.assertFalse(json.loads(response.content)['success']) #Dis-associated source response = dajaxice_post(self.client, 'newsreader', 'change_source_position', {'tab_id': self.tabs[0].id, 'source_name': self.sources[4].name, 'position': 1}) self.assertFalse(json.loads(response.content)['success']) #Invalid position response = dajaxice_post(self.client, 'newsreader', 'change_source_position', {'tab_id': self.tabs[0].id, 'source_name': self.sources[0].name, 'position': 0}) self.assertFalse(json.loads(response.content)['success']) response = dajaxice_post(self.client, 'newsreader', 'change_source_position', {'tab_id': self.tabs[0].id, 'source_name': self.sources[0].name, 'position': 100}) self.assertFalse(json.loads(response.content)['success'])
def test_resend_confirmation_mail(self): ''' resend_confirmation_mail must resend the email address verification mail to a logged in user's email address ''' #Anonymous user response = dajaxice_post(self.client, 'newsreader', 'resend_confirmation_mail', {}) self.assertFalse(json.loads(response.content)['success']) #Inactive user self.client.login(email=self.user_email, password=self.user_pass) response = dajaxice_post(self.client, 'newsreader', 'resend_confirmation_mail', {}) self.assertTrue(json.loads(response.content)['success']) #Active user self.user.verified = True self.user.save() response = dajaxice_post(self.client, 'newsreader', 'resend_confirmation_mail', {}) self.assertFalse(json.loads(response.content)['success'])
def test_add_source(self): ''' add_source must associate the tab with the source. If the source is already associated with the tab, no error must be thrown ''' #Anonymous user must not be able to add anything response = dajaxice_post(self.client, 'newsreader', 'add_source', {'tab_id': self.tabs[2].id, 'source_name': self.sources[0].name}) self.assertFalse(json.loads(response.content)['success']) #Logged in user must be able to associate a valid tab with a valid source self.client.login(email=self.user_email, password=self.user_pass) response = dajaxice_post(self.client, 'newsreader', 'add_source', {'tab_id': self.tabs[2].id, 'source_name': self.sources[0].name}) self.assertTrue(json.loads(response.content)['success']) self.assertEqual(self.tabs[2].get_sources(), [self.sources[0]]) #Invalid tab must not be associated with a source response = dajaxice_post(self.client, 'newsreader', 'add_source', {'tab_id': 100, 'source_name': self.sources[1].name}) self.assertFalse(json.loads(response.content)['success']) #Invalid source should not be associated with the tab response = dajaxice_post(self.client, 'newsreader', 'add_source', {'tab_id': self.tabs[2].id, 'source_name': 'Habababa'}) self.assertFalse(json.loads(response.content)['success'])
def test_change_tab_position(self): ''' change_tab_position changes the order of the tabs. Invalid requests must be ignored ''' #Anonymous user test response = dajaxice_post(self.client, 'newsreader', 'change_tab_position', {'tab_id': self.tabs[0].id, 'position': 2}) self.assertFalse(json.loads(response.content)['success']) #Logged in user self.client.login(email=self.user_email, password=self.user_pass) response = dajaxice_post(self.client, 'newsreader', 'change_tab_position', {'tab_id': self.tabs[0].id, 'position': 2}) self.assertTrue(json.loads(response.content)['success']) self.assertTrue(get_object_or_none(Tab, pk=self.tabs[0].id).order, 2) #Invalid tab id response = dajaxice_post(self.client, 'newsreader', 'change_tab_position', {'tab_id': 100, 'position': 2}) self.assertFalse(json.loads(response.content)['success']) #Invalid position response = dajaxice_post(self.client, 'newsreader', 'change_tab_position', {'tab_id': self.tabs[0].id, 'position': 0}) self.assertFalse(json.loads(response.content)['success']) response = dajaxice_post(self.client, 'newsreader', 'change_tab_position', {'tab_id': self.tabs[0].id, 'position': 100}) self.assertFalse(json.loads(response.content)['success'])