Fakultas Ilmu Komputer UI

Commit 2b130ea9 authored by Raden Fikri Ihza Dwi Nanda's avatar Raden Fikri Ihza Dwi Nanda
Browse files

1606833476 230

parent 2cb489fd
...@@ -329,6 +329,49 @@ class VacancyTest(APITestCase): ...@@ -329,6 +329,49 @@ class VacancyTest(APITestCase):
self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('-close_time'), many=True, self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('-close_time'), many=True,
context={'request': request}).data) context={'request': request}).data)
def test_sort_vacancies_by_open_time(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)
open_time1 = datetime(2019, 12, 20)
open_time2 = datetime(2020, 2, 22)
open_time3 = datetime(2020, 2, 21)
close_time = datetime(2020, 3, 1)
created_time = datetime(2019, 12, 6)
v1 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time1, salary=3000000,
description='', close_time=close_time, name='vacancy1', max_accepted_applicants=3,
working_period="3 Bulan", created = created_time)
v1.save()
v2 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time2, salary=3500000,
description='', close_time=close_time, name='vacancy2', max_accepted_applicants=3,
working_period="3 Bulan", created=created_time)
v2.save()
v3 = Vacancy.objects.create(company=new_company, verified=True, open_time=open_time3, salary=3500000,
description='', close_time=close_time, name='vacancy2', max_accepted_applicants=3,
working_period="3 Bulan", created=created_time)
v3.save()
factory = APIRequestFactory()
url_open_time_asc = '/api/vacancies/?sort=open_time&order=ascending'
request = factory.get(url_open_time_asc)
response = self.client.get(url_open_time_asc, format='json')
self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('open_time'), many=True,
context={'request': request}).data)
url_open_time_desc = '/api/vacancies/?sort=open_time&order=descending'
request = factory.get(url_open_time_desc)
response = self.client.get(url_open_time_desc, format='json')
self.assertEqual(dict(response.data)['results'], VacancySerializer(Vacancy.objects.order_by('-open_time'), many=True,
context={'request': request}).data)
def test_fail_on_unverified_user_vacancy_list(self): def test_fail_on_unverified_user_vacancy_list(self):
url = '/api/vacancies/' url = '/api/vacancies/'
......
...@@ -101,7 +101,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): ...@@ -101,7 +101,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
return vacancies return vacancies
def sort(self, order_by, vacancies, order): def sort(self, order_by, vacancies, order):
if (order_by is not None) and (order_by in [views_constants.NAME, views_constants.SALARY, views_constants.MOST_RECENT, views_constants.CLOSE_TIME]) and ( if (order_by is not None) and (order_by in [views_constants.NAME, views_constants.SALARY, views_constants.MOST_RECENT, views_constants.CLOSE_TIME, views_constants.OPEN_TIME]) and (
order in [views_constants.ORDER_ASCENDING, views_constants.ORDER_DESCENDING]): order in [views_constants.ORDER_ASCENDING, views_constants.ORDER_DESCENDING]):
if order_by == views_constants.MOST_RECENT: if order_by == views_constants.MOST_RECENT:
return vacancies.order_by('-created') return vacancies.order_by('-created')
......
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