Fakultas Ilmu Komputer UI

Commit cedb80f2 authored by NICHOLAS PRIAMBODO's avatar NICHOLAS PRIAMBODO
Browse files

Merge branch 'master' into '1606879905-25'

# Conflicts:
#   core/tests/test_vacancies.py
parent 3eebdef1
...@@ -35,9 +35,15 @@ class VacancySerializer(serializers.ModelSerializer): ...@@ -35,9 +35,15 @@ class VacancySerializer(serializers.ModelSerializer):
fields = ['company', 'verified', 'open_time', 'description', 'close_time', 'created', 'updated', 'name', \ fields = ['company', 'verified', 'open_time', 'description', 'close_time', 'created', 'updated', 'name', \
'status', 'bookmarked', 'id'] 'status', 'bookmarked', 'id']
def name_position_validator(names):
for name in names.split(" "):
if not name.isalpha():
raise serializers.ValidationError("Name must alphabets only")
return name
class PostVacancySerializer(serializers.ModelSerializer): class PostVacancySerializer(serializers.ModelSerializer):
company = serializers.PrimaryKeyRelatedField(queryset=Company.objects.all()) company = serializers.PrimaryKeyRelatedField(queryset=Company.objects.all())
name = serializers.CharField(validators=[name_position_validator], max_length=100, allow_null=False)
class Meta: class Meta:
model = Vacancy model = Vacancy
......
...@@ -523,6 +523,96 @@ class SupervisorApprovalTests(APITestCase): ...@@ -523,6 +523,96 @@ class SupervisorApprovalTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
self.assertEqual(new_vacancy.verified, False) self.assertEqual(new_vacancy.verified, False)
class ValidationPositionNameinCreateLowonganKP(APITestCase):
def setUp(self):
user = User.objects.create_user('dummy', 'dummy@dummy.com', 'dummy')
self.client.force_authenticate(user=user)
self.company = Company.objects.create(
user=user,
description="dummy",
status=Company.VERIFIED,
logo=None,
address=None
)
self.url = '/api/vacancies/'
self.payload = {
"company" : self.company.id,
"open_time" : datetime.fromtimestamp(0),
"close_time" : datetime.today()
}
self.message = "Name must alphabets only"
def test_name_contains_only_alphabets(self):
self.payload["name"] = "Engineer"
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 201)
def test_name_contains_only_alphabets_and_spaces(self):
self.payload["name"] = "Software Engineer "
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 201)
def test_name_contains_alphabets_and_numerics(self):
self.payload["name"] = "Software18 Engineer"
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 400)
response_message = response.data["name"][0]
self.assertEqual(response_message, self.message)
def test_name_contains_only_numerics(self):
self.payload["name"] = "123654789"
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 400)
response_message = response.data["name"][0]
self.assertEqual(response_message, self.message)
def test_name_contains_characters_besides_alphabets(self):
self.payload["name"] = "!@#$%^&*()"
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 400)
response_message = response.data["name"][0]
self.assertEqual(response_message, self.message)
class AcceptOneOfferTests(APITestCase): class AcceptOneOfferTests(APITestCase):
def generateObject(self): def generateObject(self):
......
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