From 0bdf1dbdfeafd2e7b5a37a96d331988a9095af74 Mon Sep 17 00:00:00 2001 From: refoilmiya Date: Wed, 4 Dec 2019 00:36:53 +0700 Subject: [PATCH 1/2] [RED] created tests for office address --- core/tests/test_create_vacancies.py | 82 +++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/core/tests/test_create_vacancies.py b/core/tests/test_create_vacancies.py index db89cc3..5ea68d6 100755 --- a/core/tests/test_create_vacancies.py +++ b/core/tests/test_create_vacancies.py @@ -558,3 +558,85 @@ class CreateAndUpdateVacancyTest(APITestCase): vacancy = Vacancy.objects.first() self.assertEqual(vacancy.recruiter_activity, None) + + def test_create_vacancy_with_office_address_success(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': self.today, + 'close_time': self.tomorrow, 'name': 'new vacancy', + 'description': 'new_vacancy ', 'amount': 10, 'requirements': 'new_vacancy', + 'max_accepted_applicants': 3, 'working_period': '3 Bulan', + 'office_address': 'Freelance'}, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + + vacancy = Vacancy.objects.first() + self.assertEqual(vacancy.office_address, 'Freelance') + + def test_create_vacancy_with_office_address_fail_invalid_value_type(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': self.today, + 'close_time': self.tomorrow, 'name': 'new vacancy', + 'description': 'new_vacancy ', 'amount': 10, 'requirements': 'new_vacancy', + 'max_accepted_applicants': 3, 'working_period': '3 Bulan', + 'office_address': 123}, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + self.assertEqual(response.json()['error'], 'Office Address harus berupa string!') + + vacancy_count = Vacancy.objects.count() + self.assertEqual(vacancy_count, 0) + + def test_update_vacancy_with_office_address_success(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) + + new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=self.today, + description="lalala", close_time=self.tomorrow, name='new_company', + max_accepted_applicants=3) + + url = '/api/vacancies/' + str(new_vacancy.pk) + '/' + response = self.client.patch(url, {'company': new_company.pk, 'open_time': self.today, + 'close_time': self.tomorrow, 'name': 'new vacancy', + 'description': 'new_vacancy ', 'amount': 10, + 'requirements': 'new_vacancy', 'responsibilities': 'new_vacancy', + 'max_accepted_applicants': 3, 'working_period': '3 Bulan', + 'office_address': 'Freelance'}, format='json') + self.assertEqual(response.status_code, status.HTTP_200_OK) + + vacancy = Vacancy.objects.first() + self.assertEqual(vacancy.office_address, 'Freelance') + + def test_update_vacancy_with_office_address_fail_invalid_value_type(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) + + new_vacancy = Vacancy.objects.create(company=new_company, verified=False, open_time=self.today, + description="lalala", close_time=self.tomorrow, name='new_company', + max_accepted_applicants=3) + + url = '/api/vacancies/' + str(new_vacancy.pk) + '/' + response = self.client.patch(url, {'company': new_company.pk, 'open_time': self.today, + 'close_time': self.tomorrow, 'name': 'new vacancy', + 'description': 'new_vacancy ', 'amount': 10, + 'requirements': 'new_vacancy', + 'max_accepted_applicants': 3, 'working_period': '3 Bulan', + 'office_address': 123}, format='json') + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + self.assertEqual(response.json()['error'], 'Office Address harus berupa string!') + + vacancy = Vacancy.objects.first() + self.assertEqual(vacancy.office_address, None) -- GitLab From 0572b641bfacb21ed01fccc55b3833a4cc8c0dd3 Mon Sep 17 00:00:00 2001 From: refoilmiya Date: Wed, 4 Dec 2019 02:29:38 +0700 Subject: [PATCH 2/2] [GREEN] finished implementing feature add office address to vacancy --- core/migrations/0001_initial.py | 25 +++++++++++----------- core/migrations/0002_auto_20191203_1051.py | 20 ----------------- core/models/vacancies.py | 1 + core/tests/test_create_vacancies.py | 2 +- core/views/vacancies.py | 12 ++++++++++- core/views/views_constants.py | 2 ++ 6 files changed, 28 insertions(+), 34 deletions(-) delete mode 100644 core/migrations/0002_auto_20191203_1051.py diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py index 85a9c23..642f87b 100644 --- a/core/migrations/0001_initial.py +++ b/core/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.17 on 2019-12-03 03:38 +# Generated by Django 1.11.17 on 2019-12-03 19:28 from __future__ import unicode_literals import core.lib.validators @@ -37,9 +37,9 @@ class Migration(migrations.Migration): ('status', models.IntegerField(default=0, validators=[django.core.validators.MaxValueValidator(2), django.core.validators.MinValueValidator(0)])), ('logo', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_company_logo_file_path, validators=[core.lib.validators.validate_image_file_extension])), ('address', models.CharField(blank=True, max_length=1000, null=True)), - ('category', models.CharField(default='Belum ada kategori perusahaan', max_length=140)), + ('category', models.CharField(default=b'Belum ada kategori perusahaan', max_length=140)), ('size', models.CharField(blank=True, default=0, max_length=10, null=True)), - ('website', models.CharField(default='Belum ada link website', max_length=100)), + ('website', models.CharField(default=b'Belum ada link website', max_length=100)), ('linkedin_url', models.URLField(blank=True, null=True)), ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], @@ -52,7 +52,7 @@ class Migration(migrations.Migration): fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('created', models.DateTimeField(auto_now_add=True)), - ('title', models.CharField(blank=True, default='', max_length=100)), + ('title', models.CharField(blank=True, default=b'', max_length=100)), ('content', models.TextField()), ('companyId', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Company')), ], @@ -79,16 +79,16 @@ class Migration(migrations.Migration): ('created', models.DateTimeField(auto_now_add=True)), ('updated', models.DateTimeField(auto_now=True)), ('npm', models.IntegerField(unique=True, validators=[core.lib.validators.validate_npm])), - ('resume', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_resume_file_path, validators=[django.core.validators.FileExtensionValidator(['pdf'])])), + ('resume', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_resume_file_path, validators=[django.core.validators.FileExtensionValidator([b'pdf'])])), ('sertifikat', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_sertifikat_file_path, validators=[core.lib.validators.validate_document_file_extension])), - ('phone_number', models.CharField(blank=True, db_index=True, max_length=100, null=True, validators=[django.core.validators.RegexValidator('^0\\d{1,11}$')])), + ('phone_number', models.CharField(blank=True, db_index=True, max_length=100, null=True, validators=[django.core.validators.RegexValidator(b'^0\\d{1,11}$')])), ('gender', models.CharField(blank=True, max_length=30, null=True)), ('birth_place', models.CharField(blank=True, max_length=30, null=True)), ('birth_date', models.DateField(blank=True, null=True)), ('major', models.CharField(blank=True, max_length=30, null=True)), ('batch', models.CharField(blank=True, max_length=4, null=True)), ('show_transcript', models.BooleanField(default=False)), - ('photo', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_photo_file_path, validators=[django.core.validators.FileExtensionValidator(['jpg', 'jpeg', 'png'])])), + ('photo', models.FileField(blank=True, null=True, upload_to=core.models.accounts.get_student_photo_file_path, validators=[django.core.validators.FileExtensionValidator([b'jpg', b'jpeg', b'png'])])), ('self_description', models.CharField(blank=True, db_index=True, max_length=500, null=True)), ('portfolio_link', models.URLField(blank=True, null=True)), ('linkedin_url', models.URLField(blank=True, null=True)), @@ -104,10 +104,10 @@ class Migration(migrations.Migration): ('github_url', models.URLField(blank=True, null=True)), ('gitlab_url', models.URLField(blank=True, null=True)), ('intro', models.CharField(blank=True, max_length=50, null=True)), - ('expected_salary', models.CharField(blank=True, max_length=10, null=True, validators=[django.core.validators.RegexValidator('^\\d{0,10}$')])), + ('expected_salary', models.CharField(blank=True, max_length=10, null=True, validators=[django.core.validators.RegexValidator(b'^\\d{0,10}$')])), ('job_seeking_status', models.CharField(blank=True, max_length=30, null=True)), - ('student_gpa', models.FloatField(blank=True, db_column='student_gpa', default=1.0, null=True, validators=[core.lib.validators.validate_student_gpa])), - ('student_toefl', models.CharField(blank=True, max_length=3, null=True)), + ('student_gpa', models.FloatField(blank=True, db_column=b'student_gpa', default=1.0, null=True, validators=[core.lib.validators.validate_student_gpa])), + ('student_toefl', models.IntegerField(blank=True, db_column=b'toefl', default=0, null=True)), ('volunteer', models.CharField(blank=True, max_length=100, null=True)), ('awards', models.CharField(blank=True, max_length=100, null=True)), ('projects', models.CharField(blank=True, max_length=100, null=True)), @@ -115,7 +115,7 @@ class Migration(migrations.Migration): ('languages', models.CharField(blank=True, max_length=100, null=True)), ('seminar', models.CharField(blank=True, max_length=100, null=True)), ('interests', models.CharField(blank=True, max_length=100, null=True)), - ('dependants', models.IntegerField(blank=True, db_column='dependants', default=0, null=True)), + ('dependants', models.IntegerField(blank=True, db_column=b'dependants', default=0, null=True)), ], options={ 'ordering': ['-updated'], @@ -154,6 +154,7 @@ class Migration(migrations.Migration): ('tag', models.TextField(blank=True)), ('salary', models.IntegerField(default=0)), ('recruiter_activity', models.CharField(blank=True, max_length=10, null=True)), + ('office_address', models.TextField(blank=True, default=b'')), ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='vacancies', to='core.Company')), ], options={ @@ -175,7 +176,7 @@ class Migration(migrations.Migration): name='ReasonRejected', fields=[ ('application', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='core.Application')), - ('reason', models.TextField(default='Tidak memenuhi kualifikasi perusahaan.')), + ('reason', models.TextField(default=b'Tidak memenuhi kualifikasi perusahaan.')), ], ), migrations.AddField( diff --git a/core/migrations/0002_auto_20191203_1051.py b/core/migrations/0002_auto_20191203_1051.py deleted file mode 100644 index ff119c5..0000000 --- a/core/migrations/0002_auto_20191203_1051.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.17 on 2019-12-03 03:51 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('core', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='student', - name='student_toefl', - field=models.IntegerField(blank=True, db_column='toefl', default=0, null=True), - ), - ] diff --git a/core/models/vacancies.py b/core/models/vacancies.py index d5ca7fb..4c63954 100755 --- a/core/models/vacancies.py +++ b/core/models/vacancies.py @@ -22,6 +22,7 @@ class Vacancy(models.Model): tag = models.TextField(blank=True) salary = models.IntegerField(default=0) recruiter_activity = models.CharField(blank=True, max_length=10, null=True) + office_address= models.TextField(blank=True, default='') @property def apply_before(self): diff --git a/core/tests/test_create_vacancies.py b/core/tests/test_create_vacancies.py index 5ea68d6..27ea528 100755 --- a/core/tests/test_create_vacancies.py +++ b/core/tests/test_create_vacancies.py @@ -639,4 +639,4 @@ class CreateAndUpdateVacancyTest(APITestCase): self.assertEqual(response.json()['error'], 'Office Address harus berupa string!') vacancy = Vacancy.objects.first() - self.assertEqual(vacancy.office_address, None) + self.assertEqual(vacancy.office_address, '') diff --git a/core/views/vacancies.py b/core/views/vacancies.py index d711244..eb1fc98 100644 --- a/core/views/vacancies.py +++ b/core/views/vacancies.py @@ -127,6 +127,13 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): except: raise ValidationError(views_constants.ERROR_AMOUNT_MUST_NUMBER) + def office_address_validator(self, office_address): + print(office_address) + print(type(office_address)) + if not isinstance(office_address, basestring): + print('DEBUG ERROR') + raise ValidationError(views_constants.ERROR_INVALID_OFFICE_ADDRESS) + def responsibilities_validator(self, responsibilities): if not isinstance(responsibilities, basestring): raise ValidationError(views_constants.ERROR_RESPONSIBILITIES_MUST_STRING) @@ -154,6 +161,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): views_constants.NAME: raw_data[views_constants.NAME], views_constants.SALARY: raw_data.get(views_constants.SALARY, 0), views_constants.TAG: raw_data.get(views_constants.TAG, ''), + views_constants.OFFICE_ADDRESS: raw_data.get(views_constants.OFFICE_ADDRESS, ''), views_constants.REQUIREMENTS: raw_data.get(views_constants.REQUIREMENTS, ''), views_constants.RESPONSIBILITIES: raw_data.get(views_constants.RESPONSIBILITIES, ''), views_constants.BENEFITS: raw_data.get(views_constants.BENEFITS, ''), @@ -161,7 +169,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): views_constants.RECRUITER_ACTIVITY: raw_data.get(views_constants.RECRUITER_ACTIVITY, ''), views_constants.DESCRIPTION: raw_data[views_constants.DESCRIPTION], views_constants.WORKING_PERIOD: raw_data[views_constants.WORKING_PERIOD], - views_constants.MAX_ACCEPTED_APPLICANTS: raw_data[views_constants.MAX_ACCEPTED_APPLICANTS] + views_constants.MAX_ACCEPTED_APPLICANTS: raw_data[views_constants.MAX_ACCEPTED_APPLICANTS], } return data @@ -175,6 +183,8 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet): self.responsibilities_validator(data[views_constants.RESPONSIBILITIES]) if data.get(views_constants.RECRUITER_ACTIVITY): self.recruiter_activity_validator(data[views_constants.RECRUITER_ACTIVITY]) + if data.get(views_constants.OFFICE_ADDRESS): + self.office_address_validator(data[views_constants.OFFICE_ADDRESS]) def create(self, request): print("[LOG] data: " + str(request.data)) diff --git a/core/views/views_constants.py b/core/views/views_constants.py index 9874200..c095e9a 100644 --- a/core/views/views_constants.py +++ b/core/views/views_constants.py @@ -7,6 +7,7 @@ ERROR_AMOUNT_MUST_NUMBER = 'Amount must number only' ERROR_RESPONSIBILITIES_MUST_STRING = 'Responsibilities must be string' ERROR_INVALID_RECRUITER_RESPONSE = 'Tingkat Respons Perekrut harus salah satu dari Selalu, Sering, Kadang, Jarang, ' \ 'dan Tidak Pernah!' +ERROR_INVALID_OFFICE_ADDRESS = 'Office Address harus berupa string!' ERROR_VACANCY_ALREADY_APPLIED = 'You have already applied for the vacancy' ERROR_COMPANY_DOES_NOT_EXIST = 'No company exists with that ID' ERROR_VACANCY_CLOSED = 'vacancy is closed' @@ -54,6 +55,7 @@ ERROR = 'error' IS_VALID = 'is_valid' MAX_ACCEPTED_APPLICANTS = 'max_accepted_applicants' NAME = 'name' +OFFICE_ADDRESS = 'office_address' OPEN_TIME = 'open_time' OPENED_ONLY = 'opened_only' ORDERING = 'order' -- GitLab