Fakultas Ilmu Komputer UI

Commit 41e23466 authored by addffa's avatar addffa
Browse files

[GREEN] menambahkan fungsi hitung umur mustahik

parent f8469006
from django.db import models
from django.utils import timezone
from sizakat.validators import validate_numeric_character
......@@ -40,3 +41,6 @@ class Mustahik(models.Model):
family_size = models.PositiveSmallIntegerField()
description = models.TextField(blank=True, null=True)
gender = models.CharField(max_length=1, choices=Gender.choices)
def calculate_age(self):
return timezone.now().year - self.birthdate.year
......@@ -293,6 +293,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
familySize
description
gender
age
}
}
''',
......@@ -302,12 +303,12 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
self.assertResponseNoErrors(response)
content = json.loads(response.content)
data_mustahik = content['data']['mustahik']
self.assertEqual(len(content['data']), 1)
self.assertEqual(content['data']['mustahik']['name'], 'mustahik')
self.assertEqual(content['data']['mustahik']
['noKtp'], '31751234567890')
self.assertEqual(content['data']['mustahik']
['address'], 'Jalan raya depok')
self.assertEqual(data_mustahik['name'], 'mustahik')
self.assertEqual(data_mustahik['noKtp'], '31751234567890')
self.assertEqual(data_mustahik['address'], 'Jalan raya depok')
self.assertEqual(data_mustahik['age'], mustahik.calculate_age())
def test_mustahiks_if_name_is_set_should_return_list_of_mustahiks_that_contain_the_name(self):
Mustahik.objects.create(
......
......@@ -7,3 +7,5 @@ from .models import Mustahik
class MustahikType(DjangoObjectType):
class Meta:
model = Mustahik
age = graphene.Int(source='calculate_age')
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