Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
Kape
Commits
b4fac668
Commit
b4fac668
authored
Dec 06, 2019
by
NICHOLAS PRIAMBODO
Browse files
1606879905-232 "Membuat Validasi Minimum Panjang Field cover_letter pada Backend"
parent
2094103d
Changes
3
Hide whitespace changes
Inline
Side-by-side
core/tests/test_vacancies.py
View file @
b4fac668
...
...
@@ -13,7 +13,7 @@ from core.models.vacancies import Vacancy, Application, VacancyMilestone
from
core.serializers.vacancies
import
VacancySerializer
from
core.tests.mocks
import
mock_csui_oauth_verify
,
mock_csui_ldap_student
,
mock_csui_siak_student
from
core.views.vacancies
import
date_validator
from
core.views
import
views_constants
class
ApplicationTests
(
APITestCase
):
def
get_student_id
(
self
,
mock_obj
):
...
...
@@ -55,7 +55,7 @@ class ApplicationTests(APITestCase):
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.
'
},
response
=
self
.
client
.
post
(
url
,
{
'vacancy_id'
:
new_vacancy
.
pk
,
'cover_letter'
:
'this is a cover letter.
'
*
50
},
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
...
...
@@ -63,6 +63,51 @@ class ApplicationTests(APITestCase):
response
=
self
.
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
@
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
)
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'
)
...
...
core/views/vacancies.py
View file @
b4fac668
...
...
@@ -325,6 +325,10 @@ class StudentApplicationViewSet(viewsets.GenericViewSet):
paramType: body
"""
cover_letter
=
request
.
data
.
get
(
views_constants
.
COVER_LETTER
)
words_count
=
len
(
cover_letter
.
split
())
if
words_count
<
250
:
raise
ValidationError
(
views_constants
.
ERROR_WORDS_COUNT
)
vacancy
=
get_object_or_404
(
Vacancy
.
objects
.
all
(),
pk
=
request
.
data
.
get
(
views_constants
.
VACANCY_ID
))
if
vacancy
.
close_time
<
timezone
.
now
():
return
Response
({
views_constants
.
ERROR
:
views_constants
.
ERROR_VACANCY_CLOSED
},
...
...
core/views/views_constants.py
View file @
b4fac668
...
...
@@ -14,6 +14,7 @@ ERROR_VACANCY_CLOSED = 'vacancy is closed'
ERROR_INVALID_STATUS_CODE
=
'status must be an integer between 0 and 4'
ERROR_FORBIDDEN
=
'forbidden'
ERROR_BAD_REQUEST
=
'bad request'
ERROR_WORDS_COUNT
=
'Cover letter must minimum 250 words!'
ACTION_LIST
=
'list'
ACTION_PARTIAL_UPDATE
=
'partial_update'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment