Fakultas Ilmu Komputer UI
Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
PMPL
Class Project
Kape
Commits
bc1e8bb1
Commit
bc1e8bb1
authored
Oct 02, 2019
by
Ivana Irene Thomas
Browse files
modify commit, return 400 when vacancy close_time less than today
parent
ea879d49
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/tests/test_vacancies.py
View file @
bc1e8bb1
from
datetime
import
datetime
,
timedelta
from
django.utils
import
timezone
import
json
import
requests_mock
from
django.contrib.auth.models
import
User
...
...
@@ -73,8 +72,13 @@ class ApplicationTests(APITestCase):
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
)
<<<<<<<
HEAD
new_vacancy
=
Vacancy
.
objects
.
create
(
company
=
new_company
,
verified
=
True
,
open_time
=
datetime
.
fromtimestamp
(
1541319300.0
),
description
=
"lalala"
,
close_time
=
timezone
.
now
())
=======
new_vacancy
=
Vacancy
.
objects
.
create
(
company
=
new_company
,
verified
=
True
,
open_time
=
datetime
.
fromtimestamp
(
0
),
description
=
"lalala"
,
close_time
=
(
timezone
.
now
()
+
timedelta
(
days
=
1
)))
>>>>>>>
modify
commit
,
return
400
when
vacancy
close_time
less
than
today
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.'
},
...
...
@@ -84,7 +88,7 @@ class ApplicationTests(APITestCase):
url
=
'/api/students/'
+
str
(
student_id
)
+
'/applied-vacancies/'
+
str
(
new_vacancy
.
pk
)
+
'/'
response
=
self
.
client
.
delete
(
url
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
@
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
)
...
...
@@ -115,7 +119,7 @@ class ApplicationTests(APITestCase):
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
),
description
=
"lalala"
,
close_time
=
datetime
.
today
()
-
timedelta
(
days
=
1
))
description
=
"lalala"
,
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'
)
...
...
core/views/vacancies.py
View file @
bc1e8bb1
import
requests
from
django.utils
import
timezone
from
django.conf
import
settings
from
rest_framework
import
viewsets
,
status
from
rest_framework.decorators
import
detail_route
...
...
@@ -194,6 +195,9 @@ class StudentApplicationViewSet(viewsets.GenericViewSet):
"""
cover_letter
=
request
.
data
.
get
(
'cover_letter'
)
vacancy
=
get_object_or_404
(
Vacancy
.
objects
.
all
(),
pk
=
request
.
data
.
get
(
'vacancy_id'
))
if
vacancy
.
close_time
<
timezone
.
now
():
return
Response
({
"error"
:
"vacancy is closed"
},
\
status
=
status
.
HTTP_400_BAD_REQUEST
)
student
=
get_object_or_404
(
Student
.
objects
.
all
(),
pk
=
student_id
)
if
Application
.
objects
.
filter
(
vacancy
=
vacancy
,
student
=
student
).
exists
():
raise
ValidationError
(
"You have already applied for the vacancy"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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