Fakultas Ilmu Komputer UI

Commit 3ccdceae authored by Ibnu Sofian Firdaus's avatar Ibnu Sofian Firdaus
Browse files

Merge branch 'master' into '1606893986-21'

# Conflicts:
#   core/views/vacancies.py
parent 1682b6a7
......@@ -166,3 +166,4 @@ container. Thus, you can see the app via Web browser by opening
Copyright (c) 2017 PPLA1 Team & Faculty of Computer Science Universitas
Indonesia. This project is licensed under [ISC](LICENSE) license.
......@@ -78,6 +78,19 @@ export default class VacancyPage extends React.Component {
}
/>
</Pane>
<Pane label="Lowongan Tersedia" >
<Pagination
key={4}
url="/vacancies/opened_only=1"
child={
<VacancyList
user={this.props.user}
key={4}
userId={this.state.id}
/>
}
/>
</Pane>
</Tabs>
);
} else if ((this.props.user.role === 'admin' && this.props.user.data.company != null)
......
......@@ -206,6 +206,58 @@ class VacancyTest(APITestCase):
response = self.client.post(url, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_opened_only_vacancy_list(self):
superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
self.client.force_authenticate(user=superuser)
url = '/api/vacancies/?opened_only=true'
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_opened_and_unopened_vacancy_list(self):
superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
self.client.force_authenticate(user=superuser)
url = '/api/vacancies/?opened_only=false'
response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
@requests_mock.Mocker()
def test_closed_vacancy_not_included(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)
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, status_code=200)
m.get('https://api.cs.ui.ac.id/siakngcs/mahasiswa/1234567890?client_id=X3zNkFmepkdA47ASNMDZRX3Z9gqSU1Lwywu5WepG', json={
"kota_lahir": "kota_kota",
"tgl_lahir": "2017-12-31",
"program": [{
"nm_org": "Ilmu Informasi",
"angkatan": "2017"
}]
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
format='json')
student_id = response.data.get('student').get('id')
new_user = User.objects.create_user('dummy.company2', 'dummy.compan2y@company.com', 'lalala123')
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(1541319300.0),
description="expired vacancy", close_time=datetime.fromtimestamp(1541319301.0))
url = '/api/vacancies/?opened_only=true'
response = self.client.get(url, format='json')
self.assertEqual("expired vacancy" in response, False)
class CompanyListsTests(APITestCase):
def test_company_vacancy_list(self):
......
......@@ -17,6 +17,7 @@ from core.serializers.vacancies import VacancySerializer, ApplicationSerializer,
PostVacancySerializer, VacancyVerifiedSerializer, SupervisorStudentApplicationSerializer
from core.views.accounts import StudentViewSet
from datetime import datetime, timedelta, time
class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
queryset = Vacancy.objects.all()
......@@ -40,8 +41,16 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
vacancies = vacancies.filter(verified=True)
if verified.lower() in {"no", "false", "f", "0"}:
vacancies = vacancies.filter(verified=False)
opened_only = str(request.query_params['opened_only']) \
if 'opened_only' in request.query_params else "False"
if opened_only.lower() in ("yes", "true", "t", "1"):
today = datetime.combine(datetime.now().date(), time())
vacancies = vacancies.filter(close_time__gte=today)
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