Fakultas Ilmu Komputer UI

test_vacancies.py 57.1 KB
Newer Older
1001
1002
1003
        new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
1004

1005
1006
        new_user2 = User.objects.create_user('dummy.company2', 'dummy.company2@company.com', 'lalala123')
        new_company2 = Company.objects.create(user=new_user2, description="lalala", status=Company.VERIFIED, logo=None,
1007
                                              address=None)
1008
1009

        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
1010
                                             description="lalala", requirements= "requirements", close_time=datetime.today(), max_accepted_applicants=3)
1011

1012
        new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=datetime.fromtimestamp(0),
1013
                                             description="lalala", requirements= "requirements", close_time=datetime.today(), max_accepted_applicants=3)
1014
1015
1016
1017
1018
1019
1020

        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):
1021

1022
        new_user3, new_vacancy, new_vacancy2, new_student = self.generateObject()
1023

1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
        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:
1036
            status_response.append(app['status'])
1037
1038
1039
1040
1041
1042
1043
1044

        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):
1045
        new_user3, new_vacancy, new_vacancy2, new_student = self.generateObject()
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057

        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')
1058
        body = json.loads(response.content)
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072

        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):
            url = '/api/acceptoffer/' + None + '/vacancy/' + str(new_vacancy.pk) + '/'
1073

1074
1075
        with self.assertRaises(TypeError):
            url = '/api/acceptoffer/' + str(new_student.pk) + '/vacancy/' + None + '/'
1076

1077
1078
    def test_if_requester_is_not_authenticated(self):
        new_user3, new_vacancy, new_vacancy2, new_student = self.generateObject()
1079

1080
1081
1082
1083
1084
1085
        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')
1086
        body = json.loads(response.content)
1087
1088

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