Fakultas Ilmu Komputer UI

test_vacancies.py 23.6 KB
Newer Older
1
from datetime import datetime
2
from django.utils import timezone
3

4
5
6
7
import requests_mock
from django.contrib.auth.models import User
from rest_framework import status
from rest_framework.test import APITestCase
8

9
from core.models.accounts import Company, Student, Supervisor
10
from core.models.vacancies import Vacancy, Application
11
12


13
class ApplicationTests(APITestCase):
14
15
    @requests_mock.Mocker()
    def test_application_list(self, m):
Hafiyyan's avatar
Hafiyyan committed
16
        m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'}, status_code=200)
17
18
19
20
21
22
23
24
        m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
            "username": "dummy.mahasiswa",
            "nama": "Dummy Mahasiswa",
            "state": 1,
            "kode_org": "01.00.12.01:mahasiswa",
            "kodeidentitas": "1234567890",
            "nama_role": "mahasiswa"
        }, status_code=200)
Hafiyyan's avatar
Hafiyyan committed
25
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
26
27
28
29
30
31
32
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)
33
34
35

        url = '/api/login/'

Zamil Majdy's avatar
Zamil Majdy committed
36
37
        response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
                                    format='json')
38
39
        student_id = response.data.get('student').get('id')

Joshua Casey's avatar
Joshua Casey committed
40
        url = '/api/students/' + str(student_id) + '/applied-vacancies/'
41
42
43
44
45
46
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

    @requests_mock.Mocker()
    def test_application_create_and_delete(self, m):
Hafiyyan's avatar
Hafiyyan committed
47
        m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'}, status_code=200)
48
49
50
51
52
53
54
55
        m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
            "username": "dummy.mahasiswa",
            "nama": "Dummy Mahasiswa",
            "state": 1,
            "kode_org": "01.00.12.01:mahasiswa",
            "kodeidentitas": "1234567890",
            "nama_role": "mahasiswa"
        }, status_code=200)
Hafiyyan's avatar
Hafiyyan committed
56
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
57
58
59
60
61
62
63
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)
64
65
66
67
68
69
70
71

        url = '/api/login/'

        response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
                                    format='json')
        student_id = response.data.get('student').get('id')

        new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
72
73
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
74
75
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
76

Joshua Casey's avatar
Joshua Casey committed
77
        url = '/api/students/' + str(student_id) + '/applied-vacancies/'
Zamil Majdy's avatar
Zamil Majdy committed
78
79
        response = self.client.post(url, {'vacancy_id': new_vacancy.pk, 'cover_letter': 'this is a cover letter.'},
                                    format='json')
80
81
        self.assertEqual(response.status_code, status.HTTP_200_OK)

Joshua Casey's avatar
Joshua Casey committed
82
        url = '/api/students/' + str(student_id) + '/applied-vacancies/' + str(new_vacancy.pk) + '/'
83
84
85
86
        response = self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)


87
class BookmarkApplicationTests(APITestCase):
88
89
    @requests_mock.Mocker()
    def test_application_list(self, m):
Hafiyyan's avatar
Hafiyyan committed
90
        m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'}, status_code=200)
91
92
93
94
95
96
97
98
        m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
            "username": "dummy.mahasiswa",
            "nama": "Dummy Mahasiswa",
            "state": 1,
            "kode_org": "01.00.12.01:mahasiswa",
            "kodeidentitas": "1234567890",
            "nama_role": "mahasiswa"
        }, status_code=200)
Hafiyyan's avatar
Hafiyyan committed
99
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
100
101
102
103
104
105
106
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)
107
108
109

        url = '/api/login/'

Zamil Majdy's avatar
Zamil Majdy committed
110
111
        response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
                                    format='json')
112
113
114
115
116
117
118
119
120
        student_id = response.data.get('student').get('id')

        url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/'
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

    @requests_mock.Mocker()
    def test_application_create_and_delete(self, m):
Hafiyyan's avatar
Hafiyyan committed
121
        m.get('https://akun.cs.ui.ac.id/oauth/token/verify/?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={"username": 'dummy.mahasiswa', "role": 'mahasiswa', "identity_number": '1234567890'}, status_code=200)
122
123
124
125
126
127
128
129
        m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
            "username": "dummy.mahasiswa",
            "nama": "Dummy Mahasiswa",
            "state": 1,
            "kode_org": "01.00.12.01:mahasiswa",
            "kodeidentitas": "1234567890",
            "nama_role": "mahasiswa"
        }, status_code=200)
Hafiyyan's avatar
Hafiyyan committed
130
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
131
132
133
134
135
136
137
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)
138
139
140
141
142
143
144

        url = '/api/login/'

        response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
                                    format='json')
        student_id = response.data.get('student').get('id')

145
        new_user = User.objects.create_user('dummy.company2', 'dummy.compan2y@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
146
147
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
148
149
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
150
151

        url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/'
Zamil Majdy's avatar
Zamil Majdy committed
152
        response = self.client.post(url, {'vacancy_id': new_vacancy.pk}, format='json')
153
154
155
156
157
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/' + str(new_vacancy.pk) + '/'
        response = self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
158

159

160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
class VacancyTest(APITestCase):
    def test_verified_vacancy_list(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        self.client.force_authenticate(user=superuser)

        url = '/api/vacancies/'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_unverified_vacancy_list(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        self.client.force_authenticate(user=superuser)

        url = '/api/vacancies/?verified=false'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_fail_on_unverified_user_vacancy_list(self):
        url = '/api/vacancies/'
        response = self.client.post(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
181
182


183
class CompanyListsTests(APITestCase):
184
    def test_company_vacancy_list(self):
185
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
186
187
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
188

189
190
191
192
        self.client.force_authenticate(new_user)

        url = '/api/companies/' + str(new_company.pk) + '/vacancies/'
        response = self.client.get(url, format='json')
193
194
        self.assertEqual(response.status_code, status.HTTP_200_OK)

195
196
    def test_company_vacancy_list_unauthorized(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
197
198
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
199
200

        new_user2 = User.objects.create_user('dummy.companyzxc', 'dummy.companyzxc@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
201
202
203
        new_company2 = Company.objects.create(user=new_user2, description="lalalaasdsad", status=Company.VERIFIED,
                                              logo=None,
                                              address=None)
204
205
206
207
208
209
210
211

        self.client.force_authenticate(new_user2)

        url = '/api/companies/' + str(new_company.pk) + '/vacancies/'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_company_application_list(self):
212
        new_user = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
213
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
214
215
                                             address=None)

216
217
218
219
220
221
        self.client.force_authenticate(new_user)

        url = '/api/companies/' + str(new_company.pk) + '/applications/'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

222
223
224
225
226
227
228
229
230
231
232
    def test_company_application_list_with_status(self):
        new_user = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

        self.client.force_authenticate(new_user)

        url = '/api/companies/' + str(new_company.pk) + '/applications/?status=0'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
    def test_company_application_list_unauthorized(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

        new_user2 = User.objects.create_user('dummy.companyzxc', 'dummy.companyzxc@company.com', 'lalala123')
        new_company2 = Company.objects.create(user=new_user2, description="lalalaasdsad", status=Company.VERIFIED,
                                              logo=None,
                                              address=None)

        self.client.force_authenticate(new_user2)

        url = '/api/companies/' + str(new_company.pk) + '/applications/'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_company_application_list_by_vacancy(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

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

257
258
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
259
260
261
262
263
264
        new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")

        self.client.force_authenticate(new_user)

        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(new_vacancy.pk) + '/by_vacancy/'
        response = self.client.get(url, format='json')
265
        self.assertEqual(response.status_code, status.HTTP_200_OK)
266
267
268
269
270
271
272
273
274

    def test_company_application_list_by_vacancy_unauthorized_1(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

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

275
276
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
277
278
279
280
        new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")

        new_user3 = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
        new_company3 = Company.objects.create(user=new_user3, description="lalala", status=Company.VERIFIED, logo=None,
Zamil Majdy's avatar
Zamil Majdy committed
281
                                              address=None)
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296

        self.client.force_authenticate(new_user3)

        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(new_vacancy.pk) + '/by_vacancy/'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

    def test_company_application_list_by_vacancy_unauthorized_2(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

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

297
298
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
299
300
301
302
303
304
305
306
307
308
        new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")

        new_user3 = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
        new_company3 = Company.objects.create(user=new_user3, description="lalala", status=Company.VERIFIED, logo=None,
                                              address=None)

        self.client.force_authenticate(new_user3)

        url = '/api/companies/' + str(new_company3.pk) + '/applications/' + str(new_vacancy.pk) + '/by_vacancy/'
        response = self.client.get(url, format='json')
309
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
310
311
312
313
314
315
316
317
318

    def test_company_application_list_by_vacancy_with_status(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

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

319
320
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
        new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")

        self.client.force_authenticate(new_user)

        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(new_vacancy.pk) + '/by_vacancy/?status=2'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_company_application_list_by_vacancy_with_bad_status_string(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

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

337
338
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
339
340
341
342
        new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")

        self.client.force_authenticate(new_user)

Zamil Majdy's avatar
Zamil Majdy committed
343
344
        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(
            new_vacancy.pk) + '/by_vacancy/?status=lalala'
345
346
347
348
349
350
351
352
353
354
355
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_company_application_list_by_vacancy_with_bad_status_negative(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

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

356
357
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
358
359
360
361
        new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")

        self.client.force_authenticate(new_user)

Zamil Majdy's avatar
Zamil Majdy committed
362
363
        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(
            new_vacancy.pk) + '/by_vacancy/?status=-1'
364
365
366
367
368
369
370
371
372
373
374
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

    def test_company_application_list_by_vacancy_with_bad_status_large(self):
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)

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

375
376
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
377
378
379
380
381
382
383
        new_app = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")

        self.client.force_authenticate(new_user)

        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(new_vacancy.pk) + '/by_vacancy/?status=5'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
384

385

Zamil Majdy's avatar
Zamil Majdy committed
386
class SupervisorStudentApplicationTests(APITestCase):
387
388
389
390
391
    def test_list_student_application(self):
        new_user = User.objects.create_user('dummy.supervisor', 'dummy.supervisor@asd.asd', 'lalala123')
        new_supervisor = Supervisor.objects.create(user=new_user, nip=1212121212)
        self.client.force_authenticate(user=new_user)

Zamil Majdy's avatar
Zamil Majdy committed
392
        url = '/api/applications/'
393
394
395
396
397
398
399
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    def test_list_student_application_unauthorized(self):
        new_user = User.objects.create_user('dummy.supervisor', 'dummy.supervisor@asd.asd', 'lalala123')
        self.client.force_authenticate(user=new_user)

Zamil Majdy's avatar
Zamil Majdy committed
400
        url = '/api/applications/'
401
402
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
M. Reza Qorib's avatar
M. Reza Qorib committed
403

404

Zamil Majdy's avatar
Zamil Majdy committed
405
class SupervisorApprovalTests(APITestCase):
406
407
408
409
410
    def test_supervisor_approve_vacancy(self):
        new_user = User.objects.create_user('dummy.supervisor', 'dummy.supervisor@asd.asd', 'lalala123')
        new_supervisor = Supervisor.objects.create(user=new_user, nip=1212121212)
        self.client.force_authenticate(user=new_user)

411
412
        new_user2 = User.objects.create_user('dummy.company2', 'dummy.compan2y@company.com', 'lalala123')
        new_company2 = Company.objects.create(user=new_user2, description="lalala", status=Company.VERIFIED, logo=None,
Zamil Majdy's avatar
Zamil Majdy committed
413
                                              address=None)
414
415
        new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=False, open_time=datetime.fromtimestamp(1541319300.0),
                                              description="lalala", close_time=timezone.now())
416
417

        url = '/api/vacancies/' + str(new_vacancy2.pk) + '/verify/'
Zamil Majdy's avatar
Zamil Majdy committed
418
        response = self.client.patch(url, {'verified': True}, format='json')
419
420
421
422
423
424
425
426
427
428
429
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        retrieve_vacancy = Vacancy.objects.get(pk=new_vacancy2.pk)
        self.assertEqual(retrieve_vacancy.verified, True)

    def test_unauthorized_approve_vacancy(self):
        new_user = User.objects.create_user('dummy.companyz', 'dummy.companyz@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalalaz", status=Company.VERIFIED, logo=None,
                                             address=None)
        self.client.force_authenticate(user=new_user)

430
431
        new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now())
432
433
434
435
436

        url = '/api/vacancies/' + str(new_vacancy.pk) + '/verify/'
        response = self.client.patch(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(new_vacancy.verified, False)