def test_regular_user(self): request = self.factory.post('', self.data, content_type='application/json') request.user = self.user response = get_analytics_answer_dist(request) self.assertEquals(response.content, self.zendesk_response)
def test_staff_and_url(self, mock_client, mock_process_analytics): mock_client.return_value.modules.return_value.answer_distribution.return_value = [{}] factory = self.factory request = factory.post('', self.data, content_type='application/json') request.user = self.staff mock_process_analytics.return_value = [{'dummy': 'dummy'}] response = get_analytics_answer_dist(request) self.assertEquals(response, [{'dummy': 'dummy'}])
def test_no_url_no_zendesk(self): request = self.factory.post('', self.data, content_type='application/json') request.user = self.instructor response = get_analytics_answer_dist(request) self.assertEquals(response.content, 'A problem has occurred retrieving the data.')
def test_timeout_error(self, mock_client): mock_client.return_value.modules.return_value.answer_distribution.side_effect = TimeoutError factory = self.factory request = factory.post('', self.data, content_type='application/json') request.user = self.instructor response = get_analytics_answer_dist(request) self.assertEquals(response.status_code, 500) self.assertEquals(response.content, self.zendesk_response)
def test_not_found_error(self, mock_client): mock_client.return_value.modules.return_value.answer_distribution.side_effect = NotFoundError factory = self.factory request = factory.post('', self.data, content_type='application/json') request.user = self.instructor response = get_analytics_answer_dist(request) self.assertEquals(response.status_code, 404) self.assertEquals(response.content, 'There are no student answers for this problem yet; please try again later.')
def test_staff_and_url(self, mock_client, mock_process_analytics): mock_client.return_value.modules.return_value.answer_distribution.return_value = [ {} ] factory = self.factory request = factory.post('', self.data, content_type='application/json') request.user = self.staff mock_process_analytics.return_value = [{'dummy': 'dummy'}] response = get_analytics_answer_dist(request) self.assertEquals(response, [{'dummy': 'dummy'}])
def test_not_found_error(self, mock_client): mock_client.return_value.modules.return_value.answer_distribution.side_effect = NotFoundError factory = self.factory request = factory.post('', self.data, content_type='application/json') request.user = self.instructor response = get_analytics_answer_dist(request) self.assertEquals(response.status_code, 404) self.assertEquals( response.content, 'There are no student answers for this problem yet; please try again later.' )