Fakultas Ilmu Komputer UI

Commit 79ae3176 authored by root's avatar root
Browse files

implementasi fitur and testing

parent e68e63c4
...@@ -8,6 +8,7 @@ describe('Vacancy', () => { ...@@ -8,6 +8,7 @@ describe('Vacancy', () => {
const fetchMock = require('fetch-mock'); const fetchMock = require('fetch-mock');
const response = { const response = {
close_time: '2019-03-28T05:55:42Z', close_time: '2019-03-28T05:55:42Z',
apply_before: '28 March 2019'
company: { company: {
address: 'kebayoran baru', address: 'kebayoran baru',
id: 1, id: 1,
...@@ -17,7 +18,7 @@ describe('Vacancy', () => { ...@@ -17,7 +18,7 @@ describe('Vacancy', () => {
created: '2017-03-28T07:05:47.128672Z', created: '2017-03-28T07:05:47.128672Z',
description: 'Lorem ipsum dolbh.', description: 'Lorem ipsum dolbh.',
id: 3, id: 3,
name: 'Software Engineer', name: 'Software Engineer',
open_time: '2017-03-28T05:55:38Z', open_time: '2017-03-28T05:55:38Z',
updated: '2017-03-28T07:34:13.122093Z', updated: '2017-03-28T07:34:13.122093Z',
verified: true, verified: true,
...@@ -25,6 +26,7 @@ describe('Vacancy', () => { ...@@ -25,6 +26,7 @@ describe('Vacancy', () => {
const response2 = { const response2 = {
close_time: '2019-03-28T05:55:42Z', close_time: '2019-03-28T05:55:42Z',
apply_before: '28 March 2019'
company: { company: {
address: 'kebayoran baru', address: 'kebayoran baru',
id: 1, id: 1,
...@@ -44,6 +46,7 @@ describe('Vacancy', () => { ...@@ -44,6 +46,7 @@ describe('Vacancy', () => {
role: 'company', role: 'company',
data: { data: {
url: 'http://localhost:8001/api/users/8/', url: 'http://localhost:8001/api/users/8/',
username: 'Tutuplapak', username: 'Tutuplapak',
email: '', email: '',
is_staff: false, is_staff: false,
......
...@@ -125,7 +125,7 @@ export default class Vacancy extends React.Component { ...@@ -125,7 +125,7 @@ export default class Vacancy extends React.Component {
<h4>{ this.props.data.name }</h4> <h4>{ this.props.data.name }</h4>
{ this.props.data.company.name }<br /> { this.props.data.company.name }<br />
{ this.props.data.company.address }<br /><br /> { this.props.data.company.address }<br /><br />
<b>{`Ditutup ${moment(moment(this.props.data.close_time)).fromNow()}`}</b> <b>{this.props.data.apply_before}</b>
</Grid.Column> </Grid.Column>
<Grid.Column floated="right" > <Grid.Column floated="right" >
<Grid.Row textAlign="center"> <Grid.Row textAlign="center">
......
from django.db import models from django.db import models
from core.models.accounts import Company, Student from core.models.accounts import Company, Student
import datetime
from django.utils import timezone
class Vacancy(models.Model): class Vacancy(models.Model):
company = models.ForeignKey(Company, related_name="vacancies", null=False) company = models.ForeignKey(Company, related_name="vacancies", null=False)
...@@ -13,6 +14,12 @@ class Vacancy(models.Model): ...@@ -13,6 +14,12 @@ class Vacancy(models.Model):
updated = models.DateTimeField(auto_now=True) updated = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=100, null=False) name = models.CharField(max_length=100, null=False)
@property
def apply_before(self):
if(self.close_time<timezone.now()):
return "Pendaftaran ditutup"
return "Daftar sebelum "+self.close_time.strftime('%d')+" "+self.close_time.strftime('%B')+" "+self.close_time.strftime('%Y')
class Meta: class Meta:
ordering = ['-updated'] ordering = ['-updated']
...@@ -32,3 +39,4 @@ class Application(models.Model): ...@@ -32,3 +39,4 @@ class Application(models.Model):
class Meta: class Meta:
unique_together = (("student", "vacancy"),) unique_together = (("student", "vacancy"),)
...@@ -32,7 +32,7 @@ class VacancySerializer(serializers.ModelSerializer): ...@@ -32,7 +32,7 @@ class VacancySerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = Vacancy model = Vacancy
fields = ['company', 'verified', 'open_time', 'description', 'close_time', 'created', 'updated', 'name', \ fields = ['company', 'verified', 'open_time', 'description', 'close_time', 'created','apply_before', 'updated', 'name', \
'status', 'bookmarked', 'id'] 'status', 'bookmarked', 'id']
......
# __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, CompanyListsTests from core.tests.test_vacancies import ApplicationTests, BookmarkApplicationTests, CompanyListsTests, VacancyTest
from core.tests.test_feedbacks import FeedbacksTests from core.tests.test_feedbacks import FeedbacksTests
...@@ -7,6 +7,8 @@ from rest_framework.test import APITestCase ...@@ -7,6 +7,8 @@ from rest_framework.test import APITestCase
from core.models.accounts import Company, Student, Supervisor from core.models.accounts import Company, Student, Supervisor
from core.models.vacancies import Vacancy, Application from core.models.vacancies import Vacancy, Application
from datetime import timedelta
from django.utils import timezone
class ApplicationTests(APITestCase): class ApplicationTests(APITestCase):
...@@ -165,6 +167,7 @@ class VacancyTest(APITestCase): ...@@ -165,6 +167,7 @@ class VacancyTest(APITestCase):
response = self.client.get(url, format='json') response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_unverified_vacancy_list(self): def test_unverified_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')
self.client.force_authenticate(user=superuser) self.client.force_authenticate(user=superuser)
...@@ -173,12 +176,42 @@ class VacancyTest(APITestCase): ...@@ -173,12 +176,42 @@ class VacancyTest(APITestCase):
response = self.client.get(url, format='json') response = self.client.get(url, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_fail_on_unverified_user_vacancy_list(self): def test_fail_on_unverified_user_vacancy_list(self):
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)
def test_vacancy_is_closed(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)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
description="lalala", close_time=timezone.now() - timedelta(minutes = 10))
self.client.force_authenticate(user=superuser)
response = new_vacancy.apply_before
self.assertEqual(response, "Pendaftaran ditutup")
def test_vacancy_is_closed(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)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0),
description="lalala", close_time=timezone.now() + timedelta(minutes = 10))
self.client.force_authenticate(user=superuser)
response = new_vacancy.apply_before
self.assertNotEqual(response, "Pendaftaran ditutup")
class CompanyListsTests(APITestCase): class CompanyListsTests(APITestCase):
def test_company_vacancy_list(self): def test_company_vacancy_list(self):
new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123') new_user = User.objects.create_user('dummy.company3', 'dummy.company3@company.com', 'lalala123')
......
...@@ -40,6 +40,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): ...@@ -40,6 +40,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
if verified.lower() in {"no", "false", "f", "0"}: if verified.lower() in {"no", "false", "f", "0"}:
vacancies = vacancies.filter(verified=False) vacancies = vacancies.filter(verified=False)
page = self.paginate_queryset(vacancies) page = self.paginate_queryset(vacancies)
print(vacancies)
print(request)
if page is not None: if page is not None:
return self.get_paginated_response(VacancySerializer(page, many=True, context={'request': request}).data) return self.get_paginated_response(VacancySerializer(page, many=True, context={'request': request}).data)
return Response(VacancySerializer(vacancies, many=True, context={'request': request}).data) return Response(VacancySerializer(vacancies, 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