Fakultas Ilmu Komputer UI

test_vacancies.py 55.6 KB
Newer Older
1
from datetime import datetime, timedelta
2
from django.utils import timezone
3
import json
4
import requests_mock
5
from django.core.exceptions import ValidationError
6
7
8
from django.contrib.auth.models import User
from rest_framework import status
from rest_framework.test import APITestCase
9

10
from core.models.accounts import Company, Student, Supervisor
11
from core.models.vacancies import Vacancy, Application, VacancyMilestone
12
from core.serializers.vacancies import VacancySerializer
13

14
class ApplicationTests(APITestCase):
15
16
    @requests_mock.Mocker()
    def test_application_list(self, m):
Hafiyyan's avatar
Hafiyyan committed
17
        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)
18
19
20
21
22
23
24
25
        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
26
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
27
28
29
30
31
32
33
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)
34
35
36

        url = '/api/login/'

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

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

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

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    @requests_mock.Mocker()
    def test_application_search(self, m):
        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)
        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)
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)

        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')

        url = '/api/students/' + str(student_id) + '/applied-vacancies/?search=engineer'
        response = self.client.get(url)

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

77
78
    @requests_mock.Mocker()
    def test_application_create_and_delete(self, m):
Hafiyyan's avatar
Hafiyyan committed
79
        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)
80
81
82
83
84
85
86
87
        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
88
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
89
90
91
92
93
94
95
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)
96
97
98
99
100
101
102
103

        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
104
105
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
106
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
107
                                             description="lalala", requirements= "requirements", close_time=(timezone.now() + timedelta(days=1)))
108

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

Joshua Casey's avatar
Joshua Casey committed
114
        url = '/api/students/' + str(student_id) + '/applied-vacancies/' + str(new_vacancy.pk) + '/'
115
116
117
        response = self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
    def test_count_application_a_person_is_already_register(self):
        new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
        new_user2 = User.objects.create_user('dummy.student', 'dummy.student@student.com', 'lalala123')

        self.client.force_authenticate(new_user)
        self.client.force_authenticate(new_user2)

        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
        new_student = Student.objects.create(user=new_user2, npm=1234123412)

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

        application = Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="lorem ipsum")

        url = '/api/applications/' + str(new_vacancy.pk) + '/count/'

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

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 1)

    def test_count_application_nobody_register(self):
        new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
        new_user2 = User.objects.create_user('dummy.student', 'dummy.student@student.com', 'lalala123')

        self.client.force_authenticate(new_user)
        self.client.force_authenticate(new_user2)

        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
        new_student = Student.objects.create(user=new_user2, npm=1234123412)
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
                                             description="lalala", close_time=datetime.today())

        url = '/api/applications/' + str(new_vacancy.pk) + '/count/'

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

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['count'], 0)

161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
    @requests_mock.Mocker()
    def test_cannot_create_application_if_vacancy_is_closed(self, m):
        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)
        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)
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)

        url = '/api/login/'
182

183
184
185
186
187
188
189
190
        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')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
191
                                             description="lalala", close_time=(timezone.now() - timedelta(days=1)))
192
193
194
195
        url = '/api/students/' + str(student_id) + '/applied-vacancies/'
        response = self.client.post(url, {'vacancy_id': new_vacancy.pk, 'cover_letter': 'this is a cover letter.'},
                                    format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
196

197
class BookmarkApplicationTests(APITestCase):
198
199
    @requests_mock.Mocker()
    def test_application_list(self, m):
Hafiyyan's avatar
Hafiyyan committed
200
        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)
201
202
203
204
205
206
207
208
        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
209
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
210
211
212
213
214
215
216
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)
217
218
219

        url = '/api/login/'

Zamil Majdy's avatar
Zamil Majdy committed
220
221
        response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
                                    format='json')
222
223
224
225
226
227
228
        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)

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
    @requests_mock.Mocker()
    def test_search_bookmarked_application(self, m):
        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)
        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)
        m.get(
            'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG',
            json={
                "kota_lahir": "kota_kota",
                "tgl_lahir": "2017-12-31",
                "program": [{
                    "nm_org": "Ilmu Informasi",
                    "angkatan": "2017"
                }]
            }, status_code=200)

        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')

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

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

265
266
    @requests_mock.Mocker()
    def test_application_create_and_delete(self, m):
Hafiyyan's avatar
Hafiyyan committed
267
        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)
268
269
270
271
272
273
274
275
        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
276
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
277
278
279
280
281
282
283
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)
284
285
286
287
288
289
290

        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')

291
        new_user = User.objects.create_user('dummy.company2', 'dummy.compan2y@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
292
293
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
294
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, requirements= "requirements", open_time=datetime.fromtimestamp(1541319300.0),
295
                                             description="lalala", close_time=timezone.now())
296
297

        url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/'
Zamil Majdy's avatar
Zamil Majdy committed
298
        response = self.client.post(url, {'vacancy_id': new_vacancy.pk}, format='json')
299
300
301
302
303
        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)
304

305

306
307
308
309
310
311
312
313
314
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)

315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
    @requests_mock.Mocker()
    def test_search_vacancy(self, m):
        superuser = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
        company = Company.objects.create(user=superuser, description="This is a test company")
        Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Software Engineer")
        Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(), name="Data Engineer")
        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)
        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)
        m.get(
            'https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG',
            json={
                "kota_lahir": "kota_kota",
                "tgl_lahir": "2017-12-31",
                "program": [{
                    "nm_org": "Ilmu Informasi",
                    "angkatan": "2017"
                }]
            }, status_code=200)

        url = '/api/login/'

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

        url = '/api/vacancies/?search=software'
        response = self.client.get(url, format='json')
        self.assertEqual(1, Company.objects.all().count())
        self.assertEqual(2, Vacancy.objects.all().count())
        self.assertEqual(response.status_code, status.HTTP_200_OK)
root's avatar
root committed
352

353
354
355
356
357
358
359
    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)
360

361
362
363
    def test_filter_vacancy_list_by_company_ids(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        self.client.force_authenticate(user=superuser)
364

365
366
367
368
369
370
371
372
373
374
        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)
        open_time = datetime(2019, 10, 20)
        close_time = datetime(2019, 12, 20)
375
        vacancy1 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time,
376
                                            description='', close_time=close_time, name='vacancy1')
377
        vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=open_time,
378
379
380
381
382
383
384
                                            description='', close_time=close_time, name='vacancy2')
        url = '/api/vacancies/?company={}&company={}'.format(new_company.id, new_company2.id)
        response = self.client.get(url, format='json')
        vacancies = Vacancy.objects.filter(company__id__in=[new_company.id, new_company2.id])
        self.assertEqual(dict(response.data)['count'], Vacancy.objects.count())
        self.assertEqual(response.status_code, status.HTTP_200_OK)

385

root's avatar
root committed
386

387
388
389
390
    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)
391

392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
    def test_opened_only_vacancy_list(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        self.client.force_authenticate(user=superuser)

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

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

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

408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
    @requests_mock.Mocker()
    def test_closed_vacancy_not_included(self, m):
        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)
        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)
        m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
            "kota_lahir": "kota_kota",
            "tgl_lahir": "2017-12-31",
            "program": [{
                "nm_org": "Ilmu Informasi",
                "angkatan": "2017"
            }]
        }, status_code=200)

        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.company2', 'dummy.compan2y@company.com', 'lalala123')
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
                                             description="expired vacancy", close_time=datetime.fromtimestamp(1541319301.0))

        url = '/api/vacancies/?opened_only=true'
        response = self.client.get(url, format='json')
        self.assertEqual("expired vacancy" in response, False)

444

root's avatar
root committed
445
446
447
448
449

    def test_vacancy_is_closed(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        new_company = Company.objects.create(user=superuser, description="lalalaz", status=Company.VERIFIED, logo=None,
                                             address=None)
450

root's avatar
root committed
451
452
453
454
455
456
457
458
459
460
461
462
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
                                             description="lalala", close_time=timezone.now() - timedelta(minutes = 10))
        self.client.force_authenticate(user=superuser)

        response = new_vacancy.apply_before

        self.assertEqual(response, "Pendaftaran ditutup")

    def test_vacancy_is_closed(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        new_company = Company.objects.create(user=superuser, description="lalalaz", status=Company.VERIFIED, logo=None,
                                             address=None)
463

root's avatar
root committed
464
465
466
467
468
469
470
471
472
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
                                             description="lalala", close_time=timezone.now() + timedelta(minutes = 10))
        self.client.force_authenticate(user=superuser)

        response = new_vacancy.apply_before

        self.assertNotEqual(response, "Pendaftaran ditutup")


473

474
class CompanyListsTests(APITestCase):
475
    def test_company_vacancy_list(self):
476
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
477
478
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
479

480
481
482
483
        self.client.force_authenticate(new_user)

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

486
487
    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
488
489
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
490
491

        new_user2 = User.objects.create_user('dummy.companyzxc', 'dummy.companyzxc@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
492
493
494
        new_company2 = Company.objects.create(user=new_user2, description="lalalaasdsad", status=Company.VERIFIED,
                                              logo=None,
                                              address=None)
495
496
497
498
499
500
501
502

        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):
503
        new_user = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
504
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
505
506
                                             address=None)

507
508
509
510
511
512
        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)

513
514
515
516
517
518
519
520
521
522
523
    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)

524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
    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)

548
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
549
                                             description="lalala", requirements= "requirements", close_time=timezone.now())
550
551
552
553
554
555
        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')
556
        self.assertEqual(response.status_code, status.HTTP_200_OK)
557
558
559
560
561
562
563
564
565

    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)

566
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
567
                                             description="lalala", requirements= "requirements", close_time=timezone.now())
568
569
570
571
        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
572
                                              address=None)
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587

        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)

588
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
589
                                             description="lalala", requirements= "requirements", close_time=timezone.now())
590
591
592
593
594
595
596
597
598
599
        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')
600
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
601
602
603
604
605
606
607
608
609

    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)

610
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
611
                                             description="lalala", requirements= "requirements", close_time=timezone.now())
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
        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)

628
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
629
                                             description="lalala", requirements= "requirements", close_time=timezone.now())
630
631
632
633
        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
634
635
        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(
            new_vacancy.pk) + '/by_vacancy/?status=lalala'
636
637
638
639
640
641
642
643
644
645
646
        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)

647
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
648
                                             description="lalala", requirements= "requirements", close_time=timezone.now())
649
650
651
652
        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
653
654
        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(
            new_vacancy.pk) + '/by_vacancy/?status=-1'
655
656
657
658
659
660
661
662
663
664
665
        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)

666
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
667
                                             description="lalala", requirements= "requirements", close_time=timezone.now())
668
669
670
671
672
673
674
        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)
675

676
677
678
    def test_company_application_list_with_major(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)
679

680
        self.client.force_authenticate(new_user)
681

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

Zamil Majdy's avatar
Zamil Majdy committed
686
class SupervisorStudentApplicationTests(APITestCase):
687
688
689
690
691
    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
692
        url = '/api/applications/'
693
694
695
696
697
698
699
        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
700
        url = '/api/applications/'
701
702
        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
703

704

Zamil Majdy's avatar
Zamil Majdy committed
705
class SupervisorApprovalTests(APITestCase):
706
707
708
709
710
    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)

711
712
        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
713
                                              address=None)
714
        new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=False, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
715
                                              description="lalala", requirements= "requirements", close_time=timezone.now())
716
717

        url = '/api/vacancies/' + str(new_vacancy2.pk) + '/verify/'
Zamil Majdy's avatar
Zamil Majdy committed
718
        response = self.client.patch(url, {'verified': True}, format='json')
719
720
721
722
723
724
725
726
727
728
729
        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)

730
        new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=datetime.fromtimestamp(1541319300.0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
731
                                             description="lalala", requirements= "requirements", close_time=timezone.now())
732
733
734
735
736

        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)
737

738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
class ValidationPositionNameinCreateLowonganKP(APITestCase):
    def setUp(self):
        user = User.objects.create_user('dummy', 'dummy@dummy.com', 'dummy')
        self.client.force_authenticate(user=user)
        self.company = Company.objects.create(
            user=user,
            description="dummy",
            status=Company.VERIFIED,
            logo=None,
            address=None
        )
        self.url = '/api/vacancies/'
        self.payload = {
            "company" : self.company.id,
            "open_time" : datetime.fromtimestamp(0),
753
754
            "close_time" : datetime.today(),
            "description" : "dummy",
755
756
757
758
759
760
761
762
763
764
765
766
767
768
        }
        self.message = "Name must alphabets only"

    def test_name_contains_only_alphabets(self):
        self.payload["name"] = "Engineer"

        response = self.client.post(
            self.url,
            self.payload,
            format="json"
        )

        response_status_code = response.status_code

769
        self.assertEqual(response_status_code, 200)
770
771

    def test_name_contains_only_alphabets_and_spaces(self):
772
        self.payload["name"] = "Software Engineer"
773
774
775
776
777
778
779
780
781

        response = self.client.post(
            self.url,
            self.payload,
            format="json"
        )

        response_status_code = response.status_code

782
        self.assertEqual(response_status_code, 200)
783

784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
    def test_name_contains_alphabets_and_numerics(self):
        self.payload["name"] = "Software18 Engineer"

        response = self.client.post(
            self.url,
            self.payload,
            format="json"
        )

        response_status_code = response.status_code
        self.assertEqual(response_status_code, 400)

    def test_name_contains_only_numerics(self):
        self.payload["name"] = "123654789"

        response = self.client.post(
            self.url,
            self.payload,
            format="json"
        )

        response_status_code = response.status_code
        self.assertEqual(response_status_code, 400)

    def test_name_contains_characters_besides_alphabets(self):
        self.payload["name"] = "!@#$%^&*()"

        response = self.client.post(
            self.url,
            self.payload,
            format="json"
        )

        response_status_code = response.status_code
        self.assertEqual(response_status_code, 400)

820

821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
class VacancyMilestoneTests(APITestCase):
    def setUp(self):
        super(VacancyMilestoneTests, self).setUp()
        self.user = User.objects.create_user('dummy.student', 'dummy.student@home.com', 'lalala123')
        self.company_user =  User.objects.create_user('dummy.company2', 'dummy.compan2y@company.com', 'lalala123')
        self.company = Company.objects.create(user=self.company_user, description="lalala", status=Company.VERIFIED, logo=None,
                                              address=None)
        self.vacancy = Vacancy.objects.create(company=self.company, verified=True, open_time=datetime.fromtimestamp(0),
                                              description="lalala", close_time=datetime.today())

    def create_milestone_object(self):
        return VacancyMilestone.objects.create(vacancy=self.vacancy, name="initiate", detail="install things",
                                               expected_start=datetime.fromtimestamp(0),
                                               expected_finish=datetime.fromtimestamp(86400))

    def test_vacancy_milestone_model(self):
        milestone1 = VacancyMilestone(vacancy=self.vacancy, name="initiate", detail="install things",
                                      expected_start=datetime.fromtimestamp(0),
                                      expected_finish=datetime.fromtimestamp(86400))
        milestone1.full_clean()

        milestone2 = VacancyMilestone(vacancy=self.vacancy, name="a"*101, detail="install things",
                                      expected_start=datetime.fromtimestamp(0),
                                      expected_finish=datetime.fromtimestamp(86400))
        with self.assertRaises(ValidationError, msg="Name with more than 100 character should raise ValidationError"):
            milestone2.full_clean()

        milestone3 = VacancyMilestone(vacancy=self.vacancy, name="initiate", detail="install things",
                                      expected_start=datetime.fromtimestamp(86400),
                                      expected_finish=datetime.fromtimestamp(0))
        with self.assertRaises(ValidationError, msg="Expected finish earlier than tart should raise ValidationError"):
            milestone3.full_clean()

    def test_vacancy_milestones_list(self):
        milestone1 = self.create_milestone_object()
        self.client.force_authenticate(user=self.user)

        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data["results"]), 1)
        self.assertEqual(response.data["results"][0]["name"], milestone1.name)
        self.assertEqual(response.data["results"][0]["detail"], milestone1.detail)

    def test_create_new_milestone_on_a_vacancy_success(self):
        self.client.force_authenticate(user=self.company_user)
        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/'
        data = {"name": "initiate", "detail": "install things", "expected_start": "2019-01-20",
                "expected_finish": "2019-01-21"}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(self.vacancy.milestones.count(), 1)
        new_milestone = self.vacancy.milestones.first()
        self.assertEqual(new_milestone.name, data["name"])
        self.assertEqual(new_milestone.detail, data["detail"])

    def test_create_new_milestone_on_a_vacancy_invalid_data(self):
        self.client.force_authenticate(user=self.company_user)
        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/'
        data = {"name": "initiate", "detail": "install things", "expected_start": "2019-01-20",
                "expected_finish": "2019-01-01"}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(self.vacancy.milestones.count(), 0)

    def test_create_new_milestone_on_a_vacancy_unauthorized_user(self):
        self.client.force_authenticate(user=self.user)
        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/'
        data = {"name": "initiate", "detail": "install things", "expected_start": "2019-01-20",
                "expected_finish": "2019-01-21"}
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(self.vacancy.milestones.count(), 0)

    def test_modify_milestone_on_a_vacancy_success(self):
        milestone = self.create_milestone_object()
        self.client.force_authenticate(user=self.company_user)
        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/' + str(milestone.pk) + '/'
        data = {"name": "initiate env", "detail": "install all things", "expected_start": "2019-01-20",
                "expected_finish": "2019-01-21"}
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(self.vacancy.milestones.count(), 1)
        new_milestone = self.vacancy.milestones.first()
        self.assertEqual(new_milestone.name, data["name"])
        self.assertEqual(new_milestone.detail, data["detail"])

    def test_modify_milestone_on_a_vacancy_not_found(self):
        milestone = self.create_milestone_object()
        self.client.force_authenticate(user=self.company_user)
        url = '/api/vacancies/1000/milestones/' + str(milestone.pk) + '/'
        data = {"name": "initiate env", "detail": "install all things", "expected_start": "2019-01-20",
                "expected_finish": "2019-01-21"}
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        url2 = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/1000/'
        response2 = self.client.put(url2, data, format='json')
        self.assertEqual(response2.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(self.vacancy.milestones.count(), 1)
        new_milestone = self.vacancy.milestones.first()
        self.assertEqual(new_milestone.name, milestone.name)
        self.assertEqual(new_milestone.detail, milestone.detail)

    def test_modify_milestone_on_a_vacancy_invalid_data(self):
        milestone = self.create_milestone_object()
        self.client.force_authenticate(user=self.company_user)
        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/' + str(milestone.pk) + '/'
        data = {"name": "a" * 101, "detail": "install all things", "expected_start": "2019-01-21",
                "expected_finish": "2019-01-19"}
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(self.vacancy.milestones.count(), 1)
        new_milestone = self.vacancy.milestones.first()
        self.assertEqual(new_milestone.name, milestone.name)
        self.assertEqual(new_milestone.detail, milestone.detail)

    def test_modify_milestone_on_a_vacancy_unauthorized_user(self):
        milestone = self.create_milestone_object()
        self.client.force_authenticate(user=self.user)
        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/' + str(milestone.pk) + '/'
        data = {"name": "initiate env", "detail": "install all things", "expected_start": "2019-01-20",
                "expected_finish": "2019-01-21"}
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(self.vacancy.milestones.count(), 1)
        new_milestone = self.vacancy.milestones.first()
        self.assertEqual(new_milestone.name, milestone.name)
        self.assertEqual(new_milestone.detail, milestone.detail)

    def test_delete_milestone_on_a_vacancy_success(self):
        milestone = self.create_milestone_object()
        self.client.force_authenticate(user=self.company_user)
        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/' + str(milestone.pk) + '/'
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(self.vacancy.milestones.count(), 0)

    def test_delete_milestone_on_a_vacancy_not_found(self):
        milestone = self.create_milestone_object()
        self.client.force_authenticate(user=self.company_user)
        url = '/api/vacancies/1000/milestones/' + str(milestone.pk) + '/'
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        url2 = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/1000/'
        response2 = self.client.delete(url2, format='json')
        self.assertEqual(response2.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(self.vacancy.milestones.count(), 1)

    def test_delete_milestone_on_a_vacancy_unauthorized_user(self):
        milestone = self.create_milestone_object()
        self.client.force_authenticate(user=self.user)
        url = '/api/vacancies/' + str(self.vacancy.pk) + '/milestones/' + str(milestone.pk) + '/'
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(self.vacancy.milestones.count(), 1)

977

978
class AcceptOneOfferTests(APITestCase):
979
980
981
982
    def generateObject(self):
        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)
983

984
985
986
987
988
        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,
                                             address=None)

        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
989
                                             description="lalala", requirements= "requirements", close_time=datetime.today())
990

991
        new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=datetime.fromtimestamp(0),
Hadlina Rahmadinni's avatar
Hadlina Rahmadinni committed
992
                                             description="lalala", requirements= "requirements", close_time=datetime.today())
993
994
995
996
997
998
999

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

For faster browsing, not all history is shown. View entire blame