Fakultas Ilmu Komputer UI

Commit 5ab90751 authored by Refo Ilmiya Akbar's avatar Refo Ilmiya Akbar
Browse files

Merge branch '1606876033-12' into 'master'

1606876033 12

See merge request !18
parents b8a75ce0 7aa7dae4
Pipeline #21984 canceled with stages
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2019-10-05 19:35
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0016_merge_20191005_2235'),
]
operations = [
migrations.AddField(
model_name='vacancy',
name='amount',
field=models.IntegerField(null=True),
),
]
......@@ -12,6 +12,7 @@ class Vacancy(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=100, null=False)
amount = models.IntegerField(null=True)
class Meta:
ordering = ['-updated']
......
......@@ -23,6 +23,21 @@ class CreateAndUpdateVacancyTest(APITestCase):
vacancies = Vacancy.objects.count()
self.assertEqual(vacancies,1)
def test_new_vacancy_with_amount_success(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)
self.client.force_authenticate(user=superuser)
url = '/api/vacancies/'
response = self.client.post(url, {'company': new_company.pk, 'open_time': datetime.fromtimestamp(0),
'close_time': datetime.today(), 'name': 'new_vacancy',
'description': 'new_vacancy ', 'amount': 10}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
vacancy = Vacancy.objects.first()
self.assertEqual(vacancy.amount, 10)
def test_new_vacancy_failed(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,
......@@ -37,6 +52,21 @@ class CreateAndUpdateVacancyTest(APITestCase):
vacancies = Vacancy.objects.count()
self.assertEqual(vacancies,0)
def test_new_vacancy_with_amount_failed(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)
self.client.force_authenticate(user=superuser)
url = '/api/vacancies/'
response = self.client.post(url, {'company': new_company.pk, 'open_time': datetime.fromtimestamp(0),
'close_time': datetime.today(), 'name': 'new_vacancy',
'description': 'new_vacancy ', 'amount': 'sepuluh'}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
vacancies_count = Vacancy.objects.count()
self.assertEqual(vacancies_count, 0)
def test_update_vacancy_success(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,
......@@ -51,6 +81,23 @@ class CreateAndUpdateVacancyTest(APITestCase):
'name': 'new_vacancy2', 'description': 'new_vacancy2'}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_update_vacancy_with_amount_success(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)
self.client.force_authenticate(user=superuser)
new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=datetime.fromtimestamp(0),
description="lalala", close_time=datetime.today(), name='new_company')
url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
response = self.client.patch(url, {'open_time': datetime.fromtimestamp(0), 'close_time': datetime.today(),
'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 10}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
vacancy = Vacancy.objects.first()
self.assertEqual(vacancy.amount, 10)
def test_update_vacancy_failed(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,
......@@ -63,4 +110,21 @@ class CreateAndUpdateVacancyTest(APITestCase):
url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
response = self.client.patch(url, {'open_time': datetime.today(), 'close_time': datetime.fromtimestamp(0),
'name': 'new_vacancy2', 'description': 'new_vacancy2'}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
\ No newline at end of file
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_update_vacancy_with_amount_failed(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)
self.client.force_authenticate(user=superuser)
new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=datetime.fromtimestamp(0),
description="lalala", close_time=datetime.today(), name='new_company')
url = '/api/vacancies/' + str(new_vacancy.pk) + '/'
response = self.client.patch(url, {'open_time': datetime.fromtimestamp(0), 'close_time': datetime.today(),
'name': 'new_vacancy2', 'description': 'new_vacancy2', 'amount': 'sepuluh'}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
vacancy = Vacancy.objects.first()
self.assertEqual(vacancy.amount, None)
......@@ -57,6 +57,11 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
if close_time < open_time:
raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan!')
vacancy = Vacancy(company=company, open_time=open_time, close_time=close_time, name=name, description=description)
if 'amount' in data:
if isinstance(data['amount'], int):
vacancy.amount = data['amount']
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
vacancy.save()
return Response(status=status.HTTP_200_OK)
......@@ -73,6 +78,11 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
vacancy.close_time = close_time
vacancy.name = name
vacancy.description = description
if 'amount' in data:
if isinstance(data['amount'], int):
vacancy.amount = data['amount']
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
vacancy.save()
return Response(status=status.HTTP_200_OK)
......@@ -255,11 +265,11 @@ class CompanyApplicationViewSet(viewsets.GenericViewSet):
company = get_object_or_404(Company.objects.all().order_by('-updated'), pk=company_id)
if not self.__validating_user(request, company):
raise UnauthorizeError
return company
return company
def __validating_user(self, request, company):
return request.user.is_superuser or request.user == company.user
def __get_vacancy_list_by_pk(self, pk, company):
vacancy = get_object_or_404(Vacancy.objects.all(), pk=pk)
if not self.__validating_vacancy(vacancy, company):
......@@ -280,7 +290,7 @@ class CompanyApplicationViewSet(viewsets.GenericViewSet):
def __get_status_from_request_param(self, request):
return request.query_params.get('status', None)
def __validating_application_status(self, status):
list_status = {0 : "NEW", 1 : "READ", 2 : "BOOKMARKED", 3 : "REJECTED", 4: "ACCEPTED"}
if status not in list_status:
......
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