def test_no_logged_in_user(self): mock_request = rf.post('/api/survey/open_surveys', { 'class': str(self.new_class.id) }) response = get_all_open_survey_instances(mock_request) self.assertTrue('"error_id": 500' in response.content.decode('utf-8'))
def test_correct_closed_surveys(self): SurveyResponse.objects.create(survey_entry=self.new_question_instance, response='Test Response') response = get_all_open_survey_instances(self.request) json_obj = json.loads(response.content.decode('utf-8')) self.assertEqual(0, len(json_obj['data']))
def test_correct_open_surveys(self): response = get_all_open_survey_instances(self.request) json_obj = json.loads(response.content.decode('utf-8')) self.assertEqual(1, len(json_obj['data'])) self.assertEqual(self.new_survey.id, json_obj['data'][0]['survey']) self.assertEqual(self.new_survey_instance.id, json_obj['data'][0]['id']) self.assertEqual(timezone.now().date().strftime('%Y-%m-%d'), json_obj['data'][0]['date_generated'])
def test_wrong_request_type(self): mock_request = rf.get('/api/survey/open_surveys?session_id=' + str(self.session_id), {}) response = get_all_open_survey_instances(mock_request) self.assertTrue('"error_id": 501' in response.content.decode('utf-8'))
def test_success_status(self): response = get_all_open_survey_instances(self.request) json_obj = json.loads(response.content.decode('utf-8')) self.assertEqual('success', json_obj['status'])