Fakultas Ilmu Komputer UI

Commit bc1e8bb1 authored by Ivana Irene Thomas's avatar Ivana Irene Thomas
Browse files

modify commit, return 400 when vacancy close_time less than today

parent ea879d49
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')
......
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")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment