Fakultas Ilmu Komputer UI

Commit 74603581 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

Merge branch 'Features/CompanyVacancyApplicationList' of...

Merge branch 'Features/CompanyVacancyApplicationList' of https://gitlab.com/PPL2017csui/PPLA1 into Features/create-vacancy-company

# Conflicts:
#	core/tests/test_vacancies.py
parents dacbced4 024f40e3
# __init__.py # __init__.py
from core.tests.test_accounts import LoginTests, RegisterTests from core.tests.test_accounts import LoginTests, RegisterTests
from core.tests.test_vacancies import ApplicationTests, BookmarkApplicationTests from core.tests.test_vacancies import ApplicationTests, BookmarkApplicationTests, CompanyListsTests
...@@ -26,7 +26,7 @@ class ApplicationTests(APITestCase): ...@@ -26,7 +26,7 @@ class ApplicationTests(APITestCase):
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json') response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
student_id = response.data.get('student').get('id') student_id = response.data.get('student').get('id')
url = '/api/students/' + str(student_id) + '/applications/' url = '/api/students/' + str(student_id) + '/applied-vacancies/'
response = self.client.get(url) response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
...@@ -52,11 +52,11 @@ class ApplicationTests(APITestCase): ...@@ -52,11 +52,11 @@ class ApplicationTests(APITestCase):
new_company = Company.objects.create(user=new_user, description="lalala",verified=True,logo=None,address=None) new_company = Company.objects.create(user=new_user, description="lalala",verified=True,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()) new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0), description="lalala", close_time=datetime.today())
url = '/api/students/' + str(student_id) + '/applications/' 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') response = self.client.post(url, {'vacancy_id' : new_vacancy.pk, 'cover_letter' : 'this is a cover letter.'}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
url = '/api/students/' + str(student_id) + '/applications/' + str(new_vacancy.pk) + '/' url = '/api/students/' + str(student_id) + '/applied-vacancies/' + str(new_vacancy.pk) + '/'
response = self.client.delete(url) response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
...@@ -100,7 +100,7 @@ class BookmarkApplicationTests(APITestCase): ...@@ -100,7 +100,7 @@ class BookmarkApplicationTests(APITestCase):
format='json') format='json')
student_id = response.data.get('student').get('id') student_id = response.data.get('student').get('id')
new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123') new_user = User.objects.create_user('dummy.company2', 'dummy.compan2y@company.com', 'lalala123')
new_company = Company.objects.create(user=new_user, description="lalala",verified=True,logo=None,address=None) new_company = Company.objects.create(user=new_user, description="lalala",verified=True,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()) new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0), description="lalala", close_time=datetime.today())
...@@ -112,7 +112,6 @@ class BookmarkApplicationTests(APITestCase): ...@@ -112,7 +112,6 @@ class BookmarkApplicationTests(APITestCase):
response = self.client.delete(url) response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
class VacancyTest(APITestCase): class VacancyTest(APITestCase):
def test_verified_vacancy_list(self): def test_verified_vacancy_list(self):
superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123') superuser = User.objects.create_superuser('dummy.company', 'dummy.company@company.com', 'lalala123')
...@@ -134,3 +133,23 @@ class VacancyTest(APITestCase): ...@@ -134,3 +133,23 @@ class VacancyTest(APITestCase):
url = '/api/vacancies/' url = '/api/vacancies/'
response = self.client.post(url, format='json') response = self.client.post(url, format='json')
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
class CompanyListsTests(APITestCase):
def test_company_vacancy_list_exist(self):
new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
new_company = Company.objects.create(user=new_user, description="lalala", verified=True, logo=None, address=None)
url = '/api/companies/' + str(new_company.pk) + '/vacancies'
response = self.client.post(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_company_application_list_exist(self):
new_user = User.objects.create_user('dummy.company4', 'dummy.company4@company.com', 'lalala123')
new_company = Company.objects.create(user=new_user, description="lalala", verified=True, logo=None,
address=None)
url = '/api/companies/' + str(new_company.pk) + '/applications'
response = self.client.post(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
...@@ -5,7 +5,7 @@ from rest_framework.permissions import IsAuthenticated ...@@ -5,7 +5,7 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany
from core.models import Student from core.models import Student, Company
from core.models.vacancies import Vacancy, Application from core.models.vacancies import Vacancy, Application
from core.serializers.vacancies import VacancySerializer, ApplicationSerializer from core.serializers.vacancies import VacancySerializer, ApplicationSerializer
...@@ -74,6 +74,33 @@ class ApplicationViewSet(viewsets.GenericViewSet): ...@@ -74,6 +74,33 @@ class ApplicationViewSet(viewsets.GenericViewSet):
return Response(ApplicationSerializer(application, context={'request': request}).data) return Response(ApplicationSerializer(application, context={'request': request}).data)
class CompanyApplicationViewSet(viewsets.GenericViewSet):
queryset = Application.objects.all()
def list(self, request, company_id):
"""
Get list of company {company_id}'s applications
---
"""
company = get_object_or_404(Company.objects.all(), pk=company_id)
vacancies = Vacancy.objects.filter(company = company)
applications = Application.objects.filter(vacancy__in = vacancies)
return Response(ApplicationSerializer(applications, many=True, context={'request': request}).data)
class CompanyVacanciesViewSet(viewsets.GenericViewSet):
queryset = Vacancy. objects.all()
def list(self, request, company_id):
"""
Get list of company {company_id}'s vacancies
---
"""
company = get_object_or_404(Company.objects.all(), pk=company_id)
vacancies = Vacancy.objects.filter(company = company)
return Response(VacancySerializer(vacancies, many=True, context={'request': request}).data)
class BookmarkedVacancyByStudentViewSet(viewsets.GenericViewSet): class BookmarkedVacancyByStudentViewSet(viewsets.GenericViewSet):
serializer_class = VacancySerializer serializer_class = VacancySerializer
permission_classes = [IsAdminOrStudent] permission_classes = [IsAdminOrStudent]
......
...@@ -23,7 +23,7 @@ from rest_framework_swagger.views import get_swagger_view ...@@ -23,7 +23,7 @@ from rest_framework_swagger.views import get_swagger_view
from core import apps from core import apps
from core.views.accounts import StudentViewSet, CompanyViewSet, SupervisorViewSet, UserViewSet, LoginViewSet, CompanyRegisterViewSet from core.views.accounts import StudentViewSet, CompanyViewSet, SupervisorViewSet, UserViewSet, LoginViewSet, CompanyRegisterViewSet
from core.views.vacancies import VacancyViewSet, BookmarkedVacancyByStudentViewSet, ApplicationViewSet from core.views.vacancies import VacancyViewSet, BookmarkedVacancyByStudentViewSet, ApplicationViewSet, CompanyApplicationViewSet, CompanyVacanciesViewSet
schema_view = get_swagger_view() schema_view = get_swagger_view()
router = routers.DefaultRouter() router = routers.DefaultRouter()
...@@ -38,7 +38,10 @@ router.register(r'students/(?P<student_id>\d+)/bookmarked-vacancies', Bookmarked ...@@ -38,7 +38,10 @@ router.register(r'students/(?P<student_id>\d+)/bookmarked-vacancies', Bookmarked
base_name='bookmarked-vacancy-list') base_name='bookmarked-vacancy-list')
router.register(r'students/(?P<student_id>\d+)/applied-vacancies', ApplicationViewSet, router.register(r'students/(?P<student_id>\d+)/applied-vacancies', ApplicationViewSet,
base_name='applications') base_name='applications')
router.register(r'companies/(?P<company_id>\d+)/applications', CompanyApplicationViewSet,
base_name='company-applications')
router.register(r'companies/(?P<company_id>\d+)/vacancies', CompanyVacanciesViewSet,
base_name='company-vacancies')
urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) urlpatterns = static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += [ urlpatterns += [
...@@ -49,5 +52,3 @@ urlpatterns += [ ...@@ -49,5 +52,3 @@ urlpatterns += [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'', apps.index, name="index"), url(r'', apps.index, name="index"),
] ]
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