Fakultas Ilmu Komputer UI

Commit 0c2a62b6 authored by FARI QODRI ANDANA's avatar FARI QODRI ANDANA
Browse files

Merge branch '1606875964-23' into 'master'

1606875964-23 Saring lowongan berdasarkan perusahaan

See merge request pmpl/class-project/kape!20
parents 5ab90751 76ac1a74
Pipeline #21928 canceled with stages
......@@ -9,6 +9,7 @@ from rest_framework.test import APITestCase
from core.models.accounts import Company, Student, Supervisor
from core.models.vacancies import Vacancy, Application
from core.serializers.vacancies import VacancySerializer
class ApplicationTests(APITestCase):
......@@ -174,6 +175,31 @@ class VacancyTest(APITestCase):
url = '/api/vacancies/?verified=false'
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
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)
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)
vacancy1 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time,
description='', close_time=close_time, name='vacancy1')
vacancy2 = Vacancy.objects.create(company=new_company2, verified=True, open_time=open_time,
description='', close_time=close_time, name='vacancy2')
url = '/api/vacancies/?company={}&company={}'.format(new_company.id, new_company2.id)
response = self.client.get(url, format='json')
vacancies = Vacancy.objects.filter(company__id__in=[new_company.id, new_company2.id])
self.assertEqual(dict(response.data)['count'], Vacancy.objects.count())
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_fail_on_unverified_user_vacancy_list(self):
url = '/api/vacancies/'
......
......@@ -35,10 +35,13 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
def list(self, request, *args, **kwargs):
vacancies = Vacancy.objects.all()
verified = request.query_params['verified'] if 'verified' in request.query_params else "True"
companies = [int(x) for x in request.query_params.getlist('company', [])]
if verified.lower() in ("yes", "true", "t", "1"):
vacancies = vacancies.filter(verified=True)
if verified.lower() in {"no", "false", "f", "0"}:
vacancies = vacancies.filter(verified=False)
if len(companies) > 0:
vacancies = vacancies.filter(company__id__in=companies)
page = self.paginate_queryset(vacancies)
if page is not None:
return self.get_paginated_response(VacancySerializer(page, many=True, context={'request': request}).data)
......
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