Fakultas Ilmu Komputer UI

Commit 505a4a3d authored by RYAN NAUFAL PIOSCHA's avatar RYAN NAUFAL PIOSCHA
Browse files

Validasi Atribut Salary dan Amount pada lamaran (1606884716-94)

parent 1d191dd9
File mode changed from 100755 to 100644
......@@ -838,6 +838,54 @@ class ValidationPositionNameinCreateLowonganKP(APITestCase):
response_status_code = response.status_code
self.assertEqual(response_status_code, 400)
def test_salary_contains_number_only(self):
self.payload["salary"] = 2312312
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 200)
def test_salary_contains_number_and_alphabet(self):
self.payload["salary"] = "sdsaa"
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 400)
def test_amount_contains_number_only(self):
self.payload["amount"] = 231231221312
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 200)
def test_amount_contains_number_and_alphabet(self):
self.payload["salary"] = "sadas231"
response = self.client.post(
self.url,
self.payload,
format="json"
)
response_status_code = response.status_code
self.assertEqual(response_status_code, 400)
class VacancyMilestoneTests(APITestCase):
def setUp(self):
......
......@@ -75,6 +75,14 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
raise serializers.ValidationError("Name must alphabets only")
return name
def salary_validator(self, salary):
if not isinstance(salary, int):
raise serializers.ValidationError("Salary must number only")
def amount_validator(self, amount):
if not isinstance(amount, int):
raise serializers.ValidationError("amount must number only")
def create(self, request):
data = request.data
print("[LOG] data: "+str(data))
......@@ -87,6 +95,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
name = data['name']
self.name_position_validator(name)
salary = data.get('salary') or 0
self.salary_validator(salary)
description = data['description']
working_period = data['working_period']
requirements = data['requirements']
......@@ -111,6 +120,7 @@ class VacancyViewSet(MultiSerializerViewSetMixin, viewsets.ModelViewSet):
if 'amount' in data:
if isinstance(data['amount'], int):
vacancy.amount = data['amount']
self.amount_validator(data['amount'])
else:
return Response(status=status.HTTP_400_BAD_REQUEST)
if 'responsibilities' in 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