Beispiel #1
0
    def test_correct_addition(self):
        response = add_responses_to_survey(self.request)
        json_obj = json.loads(response.content.decode('utf-8'))

        self.assertEqual('bad id', json_obj['data']['111'])
        self.assertEqual('created', json_obj['data']['1'])
        self.assertEqual('updated', json_obj['data']['2'])
Beispiel #2
0
    def test_not_enough_POST_data(self):
        mock_request = rf.post('/api/survey/respond?session_id=' + str(self.session_id), {
            1: 'test response',
            2: 'test update again',
            111: 'test bad id'
        })
        response = add_responses_to_survey(mock_request)

        self.assertTrue('"error_id": 503' in response.content.decode('utf-8'))
Beispiel #3
0
    def test_survey_does_not_exist(self):
        mock_request = rf.post('/api/survey/respond?session_id=' + str(self.session_id), {
            'survey_id': 111,
            1: 'test response',
            2: 'test update again',
            111: 'test bad id'
        })
        response = add_responses_to_survey(mock_request)

        self.assertTrue('"error_id": 504' in response.content.decode('utf-8'))
Beispiel #4
0
    def test_no_logged_in_user(self):
        mock_request = rf.post('/api/survey/respond', {
            'survey_id': self.new_survey_instance.id,
            1: 'test response',
            2: 'test update again',
            111: 'test bad id'
        })
        response = add_responses_to_survey(mock_request)

        self.assertTrue('"error_id": 500' in response.content.decode('utf-8'))
Beispiel #5
0
    def test_wrong_request_type(self):
        mock_request = rf.get('/api/survey/respond?session_id=' + str(self.session_id), {
            'survey_id': self.new_survey_instance.id,
            1: 'test response',
            2: 'test update again',
            111: 'test bad id'
        })
        response = add_responses_to_survey(mock_request)

        self.assertTrue('"error_id": 501' in response.content.decode('utf-8'))
Beispiel #6
0
    def test_student_does_not_belong_to_student(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/respond?session_id=' + str(new_session.id), {
            'survey_id': self.new_survey_instance.id,
            1: 'test response',
            2: 'test update again',
            111: 'test bad id'
        })
        response = add_responses_to_survey(mock_request)

        self.assertTrue('"error_id": 509' in response.content.decode('utf-8'))
Beispiel #7
0
    def test_success_status(self):
        response = add_responses_to_survey(self.request)
        json_obj = json.loads(response.content.decode('utf-8'))

        self.assertEqual('success', json_obj['status'])