Fakultas Ilmu Komputer UI

test_vacancies.py 64.8 KB
Newer Older
1
import json
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
2
3
from datetime import datetime, timedelta

4
5
import requests_mock
from django.contrib.auth.models import User
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
6
7
from django.core.exceptions import ValidationError
from django.utils import timezone
8
from rest_framework import status
9
from rest_framework.test import APITestCase, APIRequestFactory
10

11
from core.models.accounts import Company, Student, Supervisor
12
from core.models.vacancies import Vacancy, Application, VacancyMilestone
13
from core.serializers.vacancies import VacancySerializer
14
from core.tests.mocks import mock_csui_oauth_verify, mock_csui_ldap_student, mock_csui_siak_student
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
15
from core.views.vacancies import date_validator
16
from core.views import views_constants
17

18
class ApplicationTests(APITestCase):
19
20
21
22
23
    def get_student_id(self, mock_obj):
        mock_csui_oauth_verify(mock_obj)
        mock_csui_ldap_student(mock_obj)
        mock_csui_siak_student(mock_obj)
        login_url = '/api/login/'
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
24
25
        response = self.client.post(login_url,
                                    {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
Zamil Majdy's avatar
Zamil Majdy committed
26
                                    format='json')
27
        return response.data.get('student').get('id')
28

29
30
31
    @requests_mock.Mocker()
    def test_application_list(self, m):
        student_id = self.get_student_id(m)
Joshua Casey's avatar
Joshua Casey committed
32
        url = '/api/students/' + str(student_id) + '/applied-vacancies/'
33
34
35
36
        response = self.client.get(url)

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

37
38
    @requests_mock.Mocker()
    def test_application_search(self, m):
39
        student_id = self.get_student_id(m)
40
41
42
43
44
        url = '/api/students/' + str(student_id) + '/applied-vacancies/?search=engineer'
        response = self.client.get(url)

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

45
46
    @requests_mock.Mocker()
    def test_application_create_and_delete(self, m):
47
        student_id = self.get_student_id(m)
48
        new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
49
50
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
51
52
53
54
55
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", max_accepted_applicants=3, working_period="3 Bulan",
                                             requirements="requirements",
                                             close_time=(timezone.now() + timedelta(days=1)))
56

Joshua Casey's avatar
Joshua Casey committed
57
        url = '/api/students/' + str(student_id) + '/applied-vacancies/'
58
        response = self.client.post(url, {'vacancy_id': new_vacancy.pk, 'cover_letter': 'this is a cover letter. ' * 50},
Zamil Majdy's avatar
Zamil Majdy committed
59
                                    format='json')
60
61
        self.assertEqual(response.status_code, status.HTTP_200_OK)

Joshua Casey's avatar
Joshua Casey committed
62
        url = '/api/students/' + str(student_id) + '/applied-vacancies/' + str(new_vacancy.pk) + '/'
63
64
65
        response = self.client.delete(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    @requests_mock.Mocker()
    def test_application_cover_letter_validation_error(self, m):
        student_id = self.get_student_id(m)

        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(1541319300.0),
            description="lalala",
            max_accepted_applicants=3,
            working_period="3 Bulan",
            requirements="requirements",
            close_time=(timezone.now() + timedelta(days=1))
        )

        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)

        message_error = response.data[0]
        self.assertEqual(message_error, views_constants.ERROR_WORDS_COUNT)

111
112
113
114
115
116
117
118
119
120
121
122
    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),
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
123
124
                                             description="lalala", close_time=datetime.today(),
                                             max_accepted_applicants=3, working_period="3 Bulan")
125

126
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="lorem ipsum")
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

        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)
144
        Student.objects.create(user=new_user2, npm=1234123412)
145
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
146
147
                                             description="lalala", close_time=datetime.today(),
                                             max_accepted_applicants=3, working_period="3 Bulan")
148
149
150
151
152
153
154
155

        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)

156
157
    @requests_mock.Mocker()
    def test_cannot_create_application_if_vacancy_is_closed(self, m):
158
        student_id = self.get_student_id(m)
159
160
161
162
        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),
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
163
164
                                             description="lalala", close_time=(timezone.now() - timedelta(days=1)),
                                             max_accepted_applicants=3, working_period="3 Bulan")
165
166
167
168
        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)
169

Adib Yusril Wafi's avatar
Adib Yusril Wafi committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    def test_get_applicant_transcript_denied(self):
        company_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
        student_user = User.objects.create_user('dummy.student', 'dummy.student@student.com', 'lalala123')

        self.client.force_authenticate(student_user)
        self.client.force_authenticate(company_user)

        new_student = Student.objects.create(user=student_user, npm=1234123412)
        new_company = Company.objects.create(user=company_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),
                                             description="lalala", close_time=datetime.today(),
                                             max_accepted_applicants=3, working_period="3 Bulan")

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

        url = '/api/applications/' + str(new_application.pk) + '/transcript/'

        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.json()['error'], 'student does not allow transcript to be shown')

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
192

193
class BookmarkApplicationTests(APITestCase):
194
    @requests_mock.Mocker()
195
196
197
198
199
    def setUp(self, m):
        mock_csui_oauth_verify(m)
        mock_csui_ldap_student(m)
        mock_csui_siak_student(m)
        login_url = '/api/login/'
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
200
201
        response = self.client.post(login_url,
                                    {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
Zamil Majdy's avatar
Zamil Majdy committed
202
                                    format='json')
203
        self.student_id = response.data.get('student').get('id')
204

205
206
    def test_application_list(self):
        url = '/api/students/' + str(self.student_id) + '/bookmarked-vacancies/'
207
208
209
210
        response = self.client.get(url)

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

211
212
    def test_search_bookmarked_application(self):
        url = '/api/students/' + str(self.student_id) + '/bookmarked-vacancies/?search=engineer'
213
214
215
216
        response = self.client.get(url)

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

217
    def test_application_create_and_delete(self):
218
        new_user = User.objects.create_user('dummy.company2', 'dummy.compan2y@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
219
220
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
221
222
223
224
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, requirements="requirements",
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", close_time=timezone.now(), max_accepted_applicants=3,
                                             working_period="3 Bulan")
225

226
        url = '/api/students/' + str(self.student_id) + '/bookmarked-vacancies/'
Zamil Majdy's avatar
Zamil Majdy committed
227
        response = self.client.post(url, {'vacancy_id': new_vacancy.pk}, format='json')
228
229
        self.assertEqual(response.status_code, status.HTTP_200_OK)

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

234

235
class VacancyTest(APITestCase):
236
237
238
239
240
    def login(self, mock_obj):
        mock_csui_oauth_verify(mock_obj)
        mock_csui_ldap_student(mock_obj)
        mock_csui_siak_student(mock_obj)
        login_url = '/api/login/'
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
241
242
        self.client.post(login_url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
                         format='json')
243

244
245
246
247
248
249
250
251
    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)

252
253
254
255
    @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")
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
256
257
258
259
        Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(),
                               name="Software Engineer", max_accepted_applicants=3, working_period="3 Bulan")
        Vacancy.objects.create(company=company, open_time=datetime.now(), close_time=datetime.now(),
                               name="Data Engineer", max_accepted_applicants=3, working_period="3 Bulan")
260

261
        self.login(m)
262
263
264
265
266
        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
267

268
269
270
271
272
273
274
    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)
275

276
277
278
    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)
279

280
281
282
283
284
285
286
287
288
289
        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)
290
        Vacancy.objects.create(company=new_company, verified=True, open_time=open_time,
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
291
292
                               description='', close_time=close_time, name='vacancy1', max_accepted_applicants=3,
                               working_period="3 Bulan")
293
        Vacancy.objects.create(company=new_company2, verified=True, open_time=open_time,
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
294
295
                               description='', close_time=close_time, name='vacancy2', max_accepted_applicants=3,
                               working_period="3 Bulan")
296
297
        url = '/api/vacancies/?company={}&company={}'.format(new_company.id, new_company2.id)
        response = self.client.get(url, format='json')
298
        Vacancy.objects.filter(company__id__in=[new_company.id, new_company2.id])
299
300
        self.assertEqual(dict(response.data)['count'], Vacancy.objects.count())
        self.assertEqual(response.status_code, status.HTTP_200_OK)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
301

302
303
304
305
306
307
308
309
310
    def test_sort_vacancies(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        self.client.force_authenticate(user=superuser)

        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)
        open_time = datetime(2019, 10, 20)
        close_time = datetime(2019, 12, 20)
311
        v1 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time, salary=3000000,
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
312
313
                               description='', close_time=close_time, name='vacancy1', max_accepted_applicants=3,
                               working_period="3 Bulan")
314
315
316
        v1.created = datetime(2019, 12, 10)
        v1.save()
        v2 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time, salary=3500000,
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
317
                               description='', close_time=close_time, name='vacancy2', max_accepted_applicants=3,
318
319
320
                               working_period="3 Bulan", created=datetime(2018, 12, 10))
        v2.created = datetime(2018, 12, 10)
        v2.save()
321
322
323
324
        factory = APIRequestFactory()
        url_name_asc = '/api/vacancies/?sort=name&order=ascending'
        request = factory.get(url_name_asc)
        response = self.client.get(url_name_asc, format='json')
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
325
326
        self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('name'), many=True,
                                                                           context={'request': request}).data)
327
328
329
330

        url_salary_asc = '/api/vacancies/?sort=salary'
        response = self.client.get(url_salary_asc)
        request = factory.get(url_salary_asc)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
331
332
333
        self.assertEqual(dict(response.data)['results'],
                         VacancySerializer(Vacancy.objects.order_by('salary'), many=True,
                                           context={'request': request}).data)
334
335
336
337

        url_name_desc = '/api/vacancies/?sort=name&order=descending'
        response = self.client.get(url_name_desc)
        request = factory.get(url_name_desc)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
338
339
        self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('-name'), many=True,
                                                                           context={'request': request}).data)
340
341
342
343

        url_salary_desc = '/api/vacancies/?sort=salary&order=descending'
        response = self.client.get(url_salary_desc)
        request = factory.get(url_salary_desc)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
344
345
346
        self.assertEqual(dict(response.data)['results'],
                         VacancySerializer(Vacancy.objects.order_by('-salary'), many=True,
                                           context={'request': request}).data)
347

348
349
350
351
352
353
354
        url_recent = '/api/vacancies/?sort=recent'
        response = self.client.get(url_recent)
        request = factory.get(url_recent)
        self.assertEqual(dict(response.data)['results'],
                         VacancySerializer(Vacancy.objects.order_by('-created'), many=True,
                                           context={'request': request}).data)

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
    def test_sort_vacancies_by_close_time(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        self.client.force_authenticate(user=superuser)

        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)

        open_time = datetime(2019, 12, 7)
        close_time1 = datetime(2019, 12, 20)
        close_time2 = datetime(2020, 2, 22)
        close_time3 = datetime(2020, 2, 21)

        created_time = datetime(2019, 12, 6)

        v1 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time, salary=3000000,
                               description='', close_time=close_time1, name='vacancy1', max_accepted_applicants=3,
                               working_period="3 Bulan", created = created_time)
        v1.save()

        v2 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time, salary=3500000,
                               description='', close_time=close_time2, name='vacancy2', max_accepted_applicants=3,
                               working_period="3 Bulan", created=created_time)
        v2.save()

        v3 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time, salary=3500000,
                               description='', close_time=close_time3, name='vacancy2', max_accepted_applicants=3,
                               working_period="3 Bulan", created=created_time)
        v3.save()

        factory = APIRequestFactory()

        url_close_time_asc = '/api/vacancies/?sort=close_time&order=ascending'
        request = factory.get(url_close_time_asc)
        response = self.client.get(url_close_time_asc, format='json')
        self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('close_time'), many=True,
                                                                           context={'request': request}).data)

        url_close_time_desc = '/api/vacancies/?sort=close_time&order=descending'
        request = factory.get(url_close_time_desc)
        response = self.client.get(url_close_time_desc, format='json')
        self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('-close_time'), many=True,
                                                                           context={'request': request}).data)

Raden Fikri Ihza Dwi Nanda's avatar
Raden Fikri Ihza Dwi Nanda committed
399
400
401
402
403
404
405
406
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
    def test_sort_vacancies_by_open_time(self):
        superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
        self.client.force_authenticate(user=superuser)

        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)

        open_time1 = datetime(2019, 12, 20)
        open_time2 = datetime(2020, 2, 22)
        open_time3 = datetime(2020, 2, 21)
        close_time = datetime(2020, 3, 1)

        created_time = datetime(2019, 12, 6)

        v1 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time1, salary=3000000,
                               description='', close_time=close_time, name='vacancy1', max_accepted_applicants=3,
                               working_period="3 Bulan", created = created_time)
        v1.save()

        v2 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time2, salary=3500000,
                               description='', close_time=close_time, name='vacancy2', max_accepted_applicants=3,
                               working_period="3 Bulan", created=created_time)
        v2.save()

        v3 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time3, salary=3500000,
                               description='', close_time=close_time, name='vacancy2', max_accepted_applicants=3,
                               working_period="3 Bulan", created=created_time)
        v3.save()

        factory = APIRequestFactory()

        url_open_time_asc = '/api/vacancies/?sort=open_time&order=ascending'
        request = factory.get(url_open_time_asc)
        response = self.client.get(url_open_time_asc, format='json')
        self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('open_time'), many=True,
                                                                           context={'request': request}).data)

        url_open_time_desc = '/api/vacancies/?sort=open_time&order=descending'
        request = factory.get(url_open_time_desc)
        response = self.client.get(url_open_time_desc, format='json')
        self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('-open_time'), many=True,
                                                                           context={'request': request}).data)
442

443
444
445
446
    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)
447

448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
    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)
463

464
465
    @requests_mock.Mocker()
    def test_closed_vacancy_not_included(self, m):
466
        self.login(m)
467
468
469
        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)
470
        Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(1541319300.0),
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
471
472
                               description="expired vacancy", close_time=datetime.fromtimestamp(1541319301.0),
                               max_accepted_applicants=3, working_period="3 Bulan")
473
474
475
476
477

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

root's avatar
root committed
478
479
480
481
    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)
482

root's avatar
root committed
483
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
484
485
                                             description="lalala", close_time=timezone.now() - timedelta(minutes=10),
                                             working_period="3 Bulan")
root's avatar
root committed
486
487
488
489
490
491
492
493
494
495
        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)
496

root's avatar
root committed
497
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
498
                                             description="lalala", close_time=timezone.now() + timedelta(minutes=10),
499
                                             max_accepted_applicants=3, working_period="3 Bulan")
root's avatar
root committed
500
501
502
503
504
505
        self.client.force_authenticate(user=superuser)

        response = new_vacancy.apply_before

        self.assertNotEqual(response, "Pendaftaran ditutup")

506
    def test_vacancy_valid_date(self):
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
507
508
        self.assertEqual(True, date_validator(str(datetime.today() + timedelta(days=1)),
                                              str(datetime.today() + timedelta(days=2)))['is_valid'])
509
510
511
512
513
514
515
516
517
518
519
520

    def test_vacancy_invalid_date(self):
        self.assertEqual(
            status.HTTP_400_BAD_REQUEST,
            date_validator(str(datetime.today() - timedelta(days=1)), str(datetime.today()))['status'])

        self.assertEqual(status.HTTP_400_BAD_REQUEST,
                         date_validator(str(datetime.today()), str(datetime.today() - timedelta(days=1)))['status'])

        self.assertRaisesMessage(status.HTTP_400_BAD_REQUEST,
                                 date_validator(str(datetime.today()), str(datetime.today()))['status'])

Adib Yusril Wafi's avatar
Adib Yusril Wafi committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
    def test_count_vacancy(self):
        company_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
        student_user = User.objects.create_user('dummy.student', 'dummy.student@student.com', 'lalala123')

        self.client.force_authenticate(company_user)

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

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

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

        url = '/api/vacancies/' + 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)
        self.assertEqual(response.json()['count_new'], 1)

root's avatar
root committed
545

546
class CompanyListsTests(APITestCase):
547
    def test_company_vacancy_list(self):
548
        new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
Zamil Majdy's avatar
Zamil Majdy committed
549
550
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
551

552
553
554
555
        self.client.force_authenticate(new_user)

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

558
559
    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
560
561
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
562
563

        new_user2 = User.objects.create_user('dummy.companyzxc', 'dummy.companyzxc@company.com', 'lalala123')
564
        Company.objects.create(user=new_user2, description="lalalaasdsad", status=Company.VERIFIED,
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
565
566
                               logo=None,
                               address=None)
567
568
569
570
571
572
573
574

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

579
580
581
582
583
584
        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)

585
586
587
588
589
590
591
592
593
594
595
    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)

596
597
598
599
600
601
    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')
602
        Company.objects.create(user=new_user2, description="lalalaasdsad", status=Company.VERIFIED,
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
603
604
                               logo=None,
                               address=None)
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619

        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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
620
621
622
623
624
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", requirements="requirements",
                                             close_time=timezone.now(), max_accepted_applicants=3,
                                             working_period="3 Bulan")
625
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
626
627
628
629
630

        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')
631
        self.assertEqual(response.status_code, status.HTTP_200_OK)
632
633
634
635
636
637
638
639
640

    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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
641
642
643
644
645
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", requirements="requirements",
                                             close_time=timezone.now(), max_accepted_applicants=3,
                                             working_period="3 Bulan")
646
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
647
648

        new_user3 = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
649
        Company.objects.create(user=new_user3, description="lalala", status=Company.VERIFIED, logo=None,
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
650
                               address=None)
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665

        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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
666
667
668
669
670
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", requirements="requirements",
                                             close_time=timezone.now(), max_accepted_applicants=3,
                                             working_period="3 Bulan")
671
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
672
673
674
675
676
677
678
679
680

        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')
681
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
682
683
684
685
686
687
688
689
690

    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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
691
692
693
694
695
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", requirements="requirements",
                                             close_time=timezone.now(), max_accepted_applicants=3,
                                             working_period="3 Bulan")
696
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711

        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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
712
713
714
715
716
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", requirements="requirements",
                                             close_time=timezone.now(), max_accepted_applicants=3,
                                             working_period="3 Bulan")
717
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
718
719
720

        self.client.force_authenticate(new_user)

Zamil Majdy's avatar
Zamil Majdy committed
721
722
        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(
            new_vacancy.pk) + '/by_vacancy/?status=lalala'
723
724
725
726
727
728
729
730
731
732
733
        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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
734
735
736
737
738
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", requirements="requirements",
                                             close_time=timezone.now(), max_accepted_applicants=3,
                                             working_period="3 Bulan")
739
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
740
741
742

        self.client.force_authenticate(new_user)

Zamil Majdy's avatar
Zamil Majdy committed
743
744
        url = '/api/companies/' + str(new_company.pk) + '/applications/' + str(
            new_vacancy.pk) + '/by_vacancy/?status=-1'
745
746
747
748
749
750
751
752
753
754
755
        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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
756
757
758
759
760
        new_vacancy = Vacancy.objects.create(company=new_company, verified=True,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", requirements="requirements",
                                             close_time=timezone.now(), max_accepted_applicants=3,
                                             working_period="3 Bulan")
761
        Application.objects.create(student=new_student, vacancy=new_vacancy, cover_letter="asdasdasd")
762
763
764
765
766
767

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

769
770
    def test_company_application_list_with_major(self):
        new_user = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
771
772
        new_company = Company.objects.create(user=new_user, description="lalala", status=Company.VERIFIED, logo=None,
                                             address=None)
773

774
        self.client.force_authenticate(new_user)
775

776
777
778
        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)
779

780

Zamil Majdy's avatar
Zamil Majdy committed
781
class SupervisorStudentApplicationTests(APITestCase):
782
783
    def test_list_student_application(self):
        new_user = User.objects.create_user('dummy.supervisor', 'dummy.supervisor@asd.asd', 'lalala123')
784
        Supervisor.objects.create(user=new_user, nip=1212121212)
785
786
        self.client.force_authenticate(user=new_user)

Zamil Majdy's avatar
Zamil Majdy committed
787
        url = '/api/applications/'
788
789
790
791
792
793
794
        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
795
        url = '/api/applications/'
796
797
        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
798

799

Zamil Majdy's avatar
Zamil Majdy committed
800
class SupervisorApprovalTests(APITestCase):
801
802
    def test_supervisor_approve_vacancy(self):
        new_user = User.objects.create_user('dummy.supervisor', 'dummy.supervisor@asd.asd', 'lalala123')
803
        Supervisor.objects.create(user=new_user, nip=1212121212)
804
805
        self.client.force_authenticate(user=new_user)

806
807
        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
808
                                              address=None)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
809
810
811
812
        new_vacancy2 = Vacancy.objects.create(company=new_company2, verified=False,
                                              open_time=datetime.fromtimestamp(1541319300.0),
                                              description="lalala", requirements="requirements",
                                              close_time=timezone.now(), max_accepted_applicants=3)
813
814

        url = '/api/vacancies/' + str(new_vacancy2.pk) + '/verify/'
Zamil Majdy's avatar
Zamil Majdy committed
815
        response = self.client.patch(url, {'verified': True}, format='json')
816
817
818
819
820
821
822
823
824
825
826
        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)

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
827
828
829
830
        new_vacancy = Vacancy.objects.create(company=new_company, verified=False,
                                             open_time=datetime.fromtimestamp(1541319300.0),
                                             description="lalala", requirements="requirements",
                                             close_time=timezone.now(), max_accepted_applicants=3)
831
832
833
834
835

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

Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
837

838
839
840
841
842
843
844
845
846
847
848
849
850
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 = {
851
            "name": "dummy",
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
852
853
854
855
            "company": self.company.id,
            "open_time": datetime.today(),
            "close_time": datetime.today() + timedelta(days=10),
            "description": "dummy",
856
857
            "working_period": "Summer 2019",
            "max_accepted_applicants": 10,
858
859
860
861
862
        }
        self.message = "Name must alphabets only"

    def test_name_contains_only_alphabets(self):
        self.payload["name"] = "Engineer"
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
863
        self.payload["requirements"] = "lalala"
864
865
866
867
868
869
870
871
872

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

        response_status_code = response.status_code

873
        self.assertEqual(response_status_code, 200)
874
875

    def test_name_contains_only_alphabets_and_spaces(self):
876
        self.payload["name"] = "Software Engineer"
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
877
        self.payload["requirements"] = "lala la"
878
879
880
881
882
883
884
885
886

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

        response_status_code = response.status_code

887
        self.assertEqual(response_status_code, 200)
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
    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,
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
            self.payload,
            format="json"
        )

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

    def test_salary_contains_number_only(self):
        self.payload["salary"] = 2312312

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

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

    def test_salary_contains_number_and_alphabet(self):
        self.payload["salary"] = "sdsaa"

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

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

    def test_amount_contains_number_only(self):
Yusuf Sholeh's avatar
Yusuf Sholeh committed
950
        self.payload["amount"] = 231231
951
952
953
954
955
956
957
958
959
960

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

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

Fajrin Kingwijati's avatar
Fajrin Kingwijati committed
961
    def test_max_accepted_applicants_contains_only_number(self):
Yusuf Sholeh's avatar
Yusuf Sholeh committed
962
        self.payload["max_accepted_applicants"] = "11"
Fajrin Kingwijati's avatar
Fajrin Kingwijati committed
963
964
965
966
967
968
969
970
971
972
973

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

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

    def test_max_accepted_applicants_contains_only_alphabet(self):
Yusuf Sholeh's avatar
Yusuf Sholeh committed
974
        self.payload["max_accepted_applicants"] = "abcd"
Fajrin Kingwijati's avatar
Fajrin Kingwijati committed
975
976
977
978
979
980
981
982
983

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

        response_status_code = response.status_code
        self.assertEqual(response_status_code, 400)
Arga Ghulam Ahmad's avatar
Arga Ghulam Ahmad committed
984

Fajrin Kingwijati's avatar
Fajrin Kingwijati committed
985
    def test_max_accepted_applicants_contains_number_and_alphabet(self):
Yusuf Sholeh's avatar
Yusuf Sholeh committed
986
        self.payload["max_accepted_applicants"] = "a1r1"
Fajrin Kingwijati's avatar
Fajrin Kingwijati committed
987
988
989
990
991
992
993
994
995
996

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

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

997
998
999
1000
    def test_amount_contains_number_and_alphabet(self):
        self.payload["salary"] = "sadas231"

        response = self.client.post(