Fakultas Ilmu Komputer UI

test_vacancies.py 55.7 KB
Newer Older
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
1001
                                             close_time=datetime.today(), max_accepted_applicants=3)
1002

1003
        new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=datetime.fromtimestamp(0),
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
1004
1005
                                              description="lalala", requirements="requirements",
                                              close_time=datetime.today(), max_accepted_applicants=3)
1006
1007
1008
1009
1010
1011
1012
1013

        new_user3 = User.objects.create_user('dummy.student', 'dummy.student@company.com', 'lalala123')
        new_student = Student.objects.create(user=new_user3, npm=1234123412)

        return new_user3, new_vacancy, new_vacancy2, new_student

    def test_number_of_content_response_object_given_id_auth(self):
        new_user3, new_vacancy, new_vacancy2, new_student = self.generateObject()
1014

1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
        self.client.force_authenticate(new_user3)

        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
        Application.objects.create(student=new_student, vacancy=new_vacancy2, cover_letter="asdasdasd")

        url = '/api/acceptoffer/' + str(new_student.pk) + '/vacancy/' + str(new_vacancy.pk) + '/'

        response = self.client.patch(url, format='json')
        body = json.loads(response.content)

        status_response = []
        for app in body:
1027
            status_response.append(app['status'])
1028
1029
1030
1031
1032
1033
1034
1035

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(len(body) >= 2)
        self.assertFalse(len(body) == 0)
        self.assertTrue('new' in status_response)
        self.assertTrue('aborted' in status_response)

    def test_student_not_exist_given_auth(self):
1036
        new_user3, new_vacancy, new_vacancy2, new_student = self.generateObject()
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048

        self.client.force_authenticate(new_user3)

        user4 = User.objects.create_user('student_user_4', 'student_user_4@company.com', 'lalala123')
        other_student = Student.objects.create(user=user4, npm=1098765432)

        Application.objects.create(student=other_student, vacancy=new_vacancy, cover_letter="asdasdasd")
        Application.objects.create(student=other_student, vacancy=new_vacancy2, cover_letter="asdasdasd")

        url = '/api/acceptoffer/' + str(new_student.pk) + '/vacancy/' + str(new_vacancy.pk) + '/'

        response = self.client.patch(url, format='json')
1049
        body = json.loads(response.content)
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertTrue(len(body) == 0)

    def test_type_error_if_input_null(self):
        new_user3, new_vacancy, new_vacancy2, new_student = self.generateObject()

        self.client.force_authenticate(new_user3)

        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
        Application.objects.create(student=new_student, vacancy=new_vacancy2, cover_letter="asdasdasd")

        with self.assertRaises(TypeError):
1063
            '/api/acceptoffer/' + None + '/vacancy/' + str(new_vacancy.pk) + '/'
1064

1065
        with self.assertRaises(TypeError):
1066
            '/api/acceptoffer/' + str(new_student.pk) + '/vacancy/' + None + '/'
1067

1068
1069
    def test_if_requester_is_not_authenticated(self):
        new_user3, new_vacancy, new_vacancy2, new_student = self.generateObject()
1070

1071
1072
1073
1074
1075
1076
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
        Application.objects.create(student=new_student, vacancy=new_vacancy2, cover_letter="asdasdasd")

        url = '/api/acceptoffer/' + str(new_student.pk) + '/vacancy/' + str(new_vacancy.pk) + '/'

        response = self.client.patch(url, format='json')
1077

1078
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
For faster browsing, not all history is shown. View entire blame