def test_survey_does_not_exist(self): mock_request = rf.post('/api/survey/get?session_id=' + str(self.session_id), { 'survey_id': 111 }) response = get_survey_by_id(mock_request) self.assertTrue('"error_id": 504' in response.content.decode('utf-8'))
def test_no_logged_in_user(self): mock_request = rf.post('/api/survey/get', { 'class': str(self.new_class.id) }) response = get_survey_by_id(mock_request) self.assertTrue('"error_id": 500' in response.content.decode('utf-8'))
def test_correct_data_returned(self): response = get_survey_by_id(self.request) json_obj = json.loads(response.content.decode('utf-8')) self.assertEqual(1, json_obj['data']['survey_instance']['id']) self.assertEqual(0, len(json_obj['data']['positions'])) self.assertEqual(1, len(json_obj['data']['questions']))
def test_invalid_student_for_survey(self): new_user = User.objects.create(username='******', email='*****@*****.**', first_name='test', last_name='test') new_student = Student.objects.create(user=new_user) new_session = Session.objects.create(user=new_user) mock_request = rf.post('/api/survey/get?session_id=' + str(new_session.id), { 'survey_id': self.new_survey_instance.id }) response = get_survey_by_id(mock_request) self.assertTrue('"error_id": 509' in response.content.decode('utf-8'))
def test_not_enough_POST_data(self): mock_request = rf.post('/api/survey/get?session_id=' + str(self.session_id), {}) response = get_survey_by_id(mock_request) self.assertTrue('"error_id": 503' in response.content.decode('utf-8'))
def test_wrong_request_type(self): mock_request = rf.get('/api/survey/get?session_id=' + str(self.session_id), {}) response = get_survey_by_id(mock_request) self.assertTrue('"error_id": 501' in response.content.decode('utf-8'))
def test_success_status(self): response = get_survey_by_id(self.request) json_obj = json.loads(response.content.decode('utf-8')) self.assertEqual('success', json_obj['status'])