From ae7b1d6b88a256815faac21868ec19bf09b0dea0 Mon Sep 17 00:00:00 2001 From: "regensa.tjahjanto" Date: Sun, 6 Oct 2019 14:28:51 +0700 Subject: [PATCH 1/6] added unit test for create vacancy --- core/tests/test_create_vacancies.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/tests/test_create_vacancies.py b/core/tests/test_create_vacancies.py index 9d8cd65..6c23cb3 100644 --- a/core/tests/test_create_vacancies.py +++ b/core/tests/test_create_vacancies.py @@ -128,3 +128,17 @@ class CreateAndUpdateVacancyTest(APITestCase): vacancy = Vacancy.objects.first() self.assertEqual(vacancy.amount, None) + + def test_create_vacancy_with_same_date_failed(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) + self.client.force_authenticate(user=superuser) + + url = '/api/vacancies/' + response = self.client.post(url, {'company': new_company.pk, 'open_time': datetime.today(), + 'close_time': datetime.today(), 'name': 'new_vacancy', 'description': 'new_vacancy'}, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + vacancies = Vacancy.objects.count() + self.assertEqual(vacancies,0) \ No newline at end of file -- GitLab From d3e7d43dc4c8464f1674d40121df2503bf2d49c7 Mon Sep 17 00:00:00 2001 From: "regensa.tjahjanto" Date: Sun, 6 Oct 2019 14:52:05 +0700 Subject: [PATCH 2/6] finished implementing validation feature --- core/tests/test_create_vacancies.py | 24 +++++++++++++++++++++--- core/views/vacancies.py | 4 ++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/core/tests/test_create_vacancies.py b/core/tests/test_create_vacancies.py index 6c23cb3..8a06e56 100644 --- a/core/tests/test_create_vacancies.py +++ b/core/tests/test_create_vacancies.py @@ -135,10 +135,28 @@ class CreateAndUpdateVacancyTest(APITestCase): address=None) self.client.force_authenticate(user=superuser) + today = datetime.today() + url = '/api/vacancies/' - response = self.client.post(url, {'company': new_company.pk, 'open_time': datetime.today(), - 'close_time': datetime.today(), 'name': 'new_vacancy', 'description': 'new_vacancy'}, format='json') + response = self.client.post(url, {'company': new_company.pk, 'open_time': today, + 'close_time': today, 'name': 'new_vacancy', 'description': 'new_vacancy'}, format='json') self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) vacancies = Vacancy.objects.count() - self.assertEqual(vacancies,0) \ No newline at end of file + self.assertEqual(vacancies,0) + + def test_update_vacancy_with_same_date_failed(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) + self.client.force_authenticate(user=superuser) + + today = datetime.today() + + new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=datetime.fromtimestamp(0), + description="lalala", close_time=datetime.today(), name='new_company') + + url = '/api/vacancies/' + str(new_vacancy.pk) + '/' + response = self.client.patch(url, {'open_time': today, 'close_time': today, + 'name': 'new_vacancy2', 'description': 'new_vacancy2'}, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) \ No newline at end of file diff --git a/core/views/vacancies.py b/core/views/vacancies.py index a5da9a9..bbfdda9 100644 --- a/core/views/vacancies.py +++ b/core/views/vacancies.py @@ -56,6 +56,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): description = data['description'] if close_time < open_time: raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan!') + elif close_time == open_time: + raise ValidationError('Waktu tutup dan buka lowongan tidak boleh sama!') vacancy = Vacancy(company=company, open_time=open_time, close_time=close_time, name=name, description=description) if 'amount' in data: if isinstance(data['amount'], int): @@ -74,6 +76,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): description = data['description'] if close_time < open_time: raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan!') + elif close_time == open_time: + raise ValidationError('Waktu tutup dan buka lowongan tidak boleh sama!') vacancy.open_time = open_time vacancy.close_time = close_time vacancy.name = name -- GitLab From 7287930c28e51d26644ed6b7957c27b31b9e2913 Mon Sep 17 00:00:00 2001 From: "regensa.tjahjanto" Date: Sun, 6 Oct 2019 14:28:51 +0700 Subject: [PATCH 3/6] added unit test for create vacancy finished implementing validation feature --- core/tests/test_create_vacancies.py | 32 +++++++++++++++++++++++++++++ core/views/vacancies.py | 4 ++++ 2 files changed, 36 insertions(+) diff --git a/core/tests/test_create_vacancies.py b/core/tests/test_create_vacancies.py index 9d8cd65..8a06e56 100644 --- a/core/tests/test_create_vacancies.py +++ b/core/tests/test_create_vacancies.py @@ -128,3 +128,35 @@ class CreateAndUpdateVacancyTest(APITestCase): vacancy = Vacancy.objects.first() self.assertEqual(vacancy.amount, None) + + def test_create_vacancy_with_same_date_failed(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) + self.client.force_authenticate(user=superuser) + + today = datetime.today() + + url = '/api/vacancies/' + response = self.client.post(url, {'company': new_company.pk, 'open_time': today, + 'close_time': today, 'name': 'new_vacancy', 'description': 'new_vacancy'}, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + vacancies = Vacancy.objects.count() + self.assertEqual(vacancies,0) + + def test_update_vacancy_with_same_date_failed(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) + self.client.force_authenticate(user=superuser) + + today = datetime.today() + + new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=datetime.fromtimestamp(0), + description="lalala", close_time=datetime.today(), name='new_company') + + url = '/api/vacancies/' + str(new_vacancy.pk) + '/' + response = self.client.patch(url, {'open_time': today, 'close_time': today, + 'name': 'new_vacancy2', 'description': 'new_vacancy2'}, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) \ No newline at end of file diff --git a/core/views/vacancies.py b/core/views/vacancies.py index a5da9a9..bbfdda9 100644 --- a/core/views/vacancies.py +++ b/core/views/vacancies.py @@ -56,6 +56,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): description = data['description'] if close_time < open_time: raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan!') + elif close_time == open_time: + raise ValidationError('Waktu tutup dan buka lowongan tidak boleh sama!') vacancy = Vacancy(company=company, open_time=open_time, close_time=close_time, name=name, description=description) if 'amount' in data: if isinstance(data['amount'], int): @@ -74,6 +76,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): description = data['description'] if close_time < open_time: raise ValidationError('Waktu tutup lowongan harus lebih dari waktu buka lowongan!') + elif close_time == open_time: + raise ValidationError('Waktu tutup dan buka lowongan tidak boleh sama!') vacancy.open_time = open_time vacancy.close_time = close_time vacancy.name = name -- GitLab From d43b00de3010c60358a1dba6bf93d5f2d385e71e Mon Sep 17 00:00:00 2001 From: "regensa.tjahjanto" Date: Tue, 8 Oct 2019 16:09:13 +0700 Subject: [PATCH 4/6] added new migrations --- core/migrations/0030_merge_20191008_1512.py | 16 +++++++++++++ core/migrations/0031_auto_20191008_1608.py | 26 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 core/migrations/0030_merge_20191008_1512.py create mode 100644 core/migrations/0031_auto_20191008_1608.py diff --git a/core/migrations/0030_merge_20191008_1512.py b/core/migrations/0030_merge_20191008_1512.py new file mode 100644 index 0000000..b1e7f56 --- /dev/null +++ b/core/migrations/0030_merge_20191008_1512.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-10-08 08:12 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0029_merge_20191008_1306'), + ('core', '0029_merge_20191008_1146'), + ] + + operations = [ + ] diff --git a/core/migrations/0031_auto_20191008_1608.py b/core/migrations/0031_auto_20191008_1608.py new file mode 100644 index 0000000..8c45c52 --- /dev/null +++ b/core/migrations/0031_auto_20191008_1608.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-10-08 09:08 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0030_merge_20191008_1512'), + ] + + operations = [ + migrations.AlterField( + model_name='company', + name='website', + field=models.CharField(default='Belum ada link website', max_length=100), + ), + migrations.AlterField( + model_name='student', + name='phone_number', + field=models.CharField(blank=True, db_index=True, max_length=12, null=True, validators=[django.core.validators.RegexValidator('^0\\d{1,11}$')]), + ), + ] -- GitLab From 96f92fecb33c0ea5d970cefc2e6623458fd3240b Mon Sep 17 00:00:00 2001 From: "regensa.tjahjanto" Date: Tue, 8 Oct 2019 16:38:54 +0700 Subject: [PATCH 5/6] added new migrations --- core/migrations/0032_merge_20191008_1618.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 core/migrations/0032_merge_20191008_1618.py diff --git a/core/migrations/0032_merge_20191008_1618.py b/core/migrations/0032_merge_20191008_1618.py new file mode 100644 index 0000000..52d951b --- /dev/null +++ b/core/migrations/0032_merge_20191008_1618.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-10-08 09:18 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0029_merge_20191008_1247'), + ('core', '0031_auto_20191008_1608'), + ] + + operations = [ + ] -- GitLab From baa358650d297748413c7b329789bb63e5efaf3d Mon Sep 17 00:00:00 2001 From: "regensa.tjahjanto" Date: Tue, 8 Oct 2019 17:08:03 +0700 Subject: [PATCH 6/6] added another new migrations --- core/migrations/0033_merge_20191008_1701.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 core/migrations/0033_merge_20191008_1701.py diff --git a/core/migrations/0033_merge_20191008_1701.py b/core/migrations/0033_merge_20191008_1701.py new file mode 100644 index 0000000..0e9939a --- /dev/null +++ b/core/migrations/0033_merge_20191008_1701.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2019-10-08 10:01 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0032_merge_20191008_1618'), + ('core', '0032_merge_20191008_1630'), + ] + + operations = [ + ] -- GitLab