Fakultas Ilmu Komputer UI

Commit e83db095 authored by M. Abdurrahman's avatar M. Abdurrahman Committed by BIMO IMAN SMARTADI
Browse files

Pbi 7 fitur informasi layanan khusus disabilitas

parent 9c7a0c21
......@@ -206,4 +206,48 @@ It will return a json with key:
* `jumlah_siswa` : number of students
* `status` : status of the sekolah (swasta, negri, or international)
* `jenis_sekolah` : type of sekolah's management (inklusi, segregasi)
* `akreditasi` : accreditation
\ No newline at end of file
* `akreditasi` : accreditation
### 15. To register penyandang disabilitas:
Make `POST` request to API endpoint `/layanan-khusus/penyandang/register/` with the following key:
* `name` : name
* `alamat` : currrent address
* `tempat_lahir` : place of birth
* `tanggal_lahir` : date of birth (yyyy-mm-dd)
* `jenis_kelamin` : sex ("LAKI-LAKI" or "PEREMPUAN")
* `pendidikan` : education
* The options are :
* SD = "SD"
* SMP/SLTP = "MP"
* SMA/SLTA = "MA"
* Diploma 1 = "D1"
* Diploma 2 = "D2"
* Diploma 3 = "D3"
* Sarjana = "S1"
* Magister = "S2"
* Doktor = "S3"
* Non-Formal/Lainnya = "NF"
* Tidak Sekolah = "NA"
* `pekerjaan` : occupation
* The options are :
* Petani = "PT"
* Buruh = "BR"
* Pedagang/Wiraswasta = "WS"
* Jasa = "JS"
* PNS/TNI/POLRI = "PN"
* Pensiunan = "SN"
* Ibu Rumah Tangga = "IR"
* Pelajar = "PL"
* Lainnya = "LA"
* Tidak Bekerja = "NA"
* `kategori` : disability type
* The option are :
* fisik = "FS"
* intelektual = "IN"
* mental = "MN"
* sensorik = "SN"
* `no_telp` : phone number
* `email` : email
* `nama_wali` : name of parent/guardian
* `alamat_wali` : address of parent/guardian
* `telp_wali` : phone number of parent/guardian
from django.contrib import admin
from .models import Sekolah
from .models import Sekolah, Penyandang
# Register your models here.
admin.site.register(Sekolah)
admin.site.register(Penyandang)
# Generated by Django 2.1.5 on 2020-05-03 04:13
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('layanan_khusus', '0011_auto_20200430_1308'),
]
operations = [
migrations.CreateModel(
name='Penyandang',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
],
),
migrations.AlterField(
model_name='sekolah',
name='jenis_sekolah',
field=models.CharField(choices=[('IK', 'Inklusi'), ('SG', 'Segregasi')], default='IK', max_length=2),
),
]
# Generated by Django 2.1.5 on 2020-05-03 04:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('layanan_khusus', '0012_auto_20200503_1113'),
]
operations = [
migrations.AddField(
model_name='penyandang',
name='alamat',
field=models.CharField(default='empty', max_length=100),
preserve_default=False,
),
migrations.AddField(
model_name='penyandang',
name='name',
field=models.CharField(default='empty', max_length=50),
preserve_default=False,
),
migrations.AddField(
model_name='penyandang',
name='no_telp',
field=models.CharField(default='empty', max_length=16),
preserve_default=False,
),
]
# Generated by Django 2.1.5 on 2020-05-03 13:44
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('layanan_khusus', '0013_auto_20200503_1134'),
]
operations = [
migrations.AddField(
model_name='penyandang',
name='tanggal_lahir',
field=models.DateField(default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='penyandang',
name='tempat_lahir',
field=models.CharField(default='empty', max_length=50),
preserve_default=False,
),
]
# Generated by Django 2.1.5 on 2020-05-03 18:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('layanan_khusus', '0014_auto_20200503_2044'),
]
operations = [
migrations.AddField(
model_name='penyandang',
name='kategori',
field=models.CharField(choices=[('FS', 'Fisik'), ('IN', 'Intelektual'), ('MN', 'Mental'), ('SN', 'Sensorik')], default='FS', max_length=2),
),
migrations.AddField(
model_name='penyandang',
name='pekerjaan',
field=models.CharField(choices=[('PT', 'Petani'), ('BR', 'Buruh'), ('WS', 'Pedagang/Wiraswasta'), ('JS', 'Jasa'), ('PN', 'PNS/TNI/POLRI'), ('SN', 'Pensiunan'), ('IR', 'Ibu Rumah Tangga'), ('PL', 'Pelajar'), ('LA', 'Lainnya'), ('NA', 'Tidak Bekerja')], default='NA', max_length=2),
),
migrations.AddField(
model_name='penyandang',
name='pendidikan',
field=models.CharField(choices=[('SD', 'SD'), ('MP', 'SMP/SLTP'), ('MA', 'SMA/SLTA'), ('D1', 'Diploma 1'), ('D2', 'Diploma 2'), ('D3', 'Diploma 3'), ('S1', 'Sarjana'), ('S2', 'Magister'), ('S3', 'Doktor'), ('NF', 'Non-Formal/Lainnya'), ('NA', 'Tidak Sekolah')], default='NA', max_length=2),
),
]
# Generated by Django 2.1.5 on 2020-05-03 18:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('layanan_khusus', '0015_auto_20200504_0116'),
]
operations = [
migrations.AddField(
model_name='penyandang',
name='jenis_kelamin',
field=models.CharField(choices=[('LAKI-LAKI', 'Laki-Laki'), ('PEREMPUAN', 'Perempuan')], default='LAKI-LAkI', max_length=9),
),
]
# Generated by Django 2.1.5 on 2020-05-03 18:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('layanan_khusus', '0016_penyandang_jenis_kelamin'),
]
operations = [
migrations.AddField(
model_name='penyandang',
name='email',
field=models.CharField(max_length=50, null=True),
),
migrations.AlterField(
model_name='penyandang',
name='no_telp',
field=models.CharField(max_length=16, null=True),
),
]
# Generated by Django 2.1.5 on 2020-05-03 19:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('layanan_khusus', '0017_auto_20200504_0151'),
]
operations = [
migrations.AddField(
model_name='penyandang',
name='alamat_wali',
field=models.CharField(max_length=100, null=True),
),
migrations.AddField(
model_name='penyandang',
name='nama_wali',
field=models.CharField(max_length=50, null=True),
),
migrations.AddField(
model_name='penyandang',
name='telp_wali',
field=models.CharField(max_length=16, null=True),
),
]
......@@ -2,19 +2,14 @@ from django.db import models
class Sekolah(models.Model):
SWASTA = "SW"
NEGRI = "NG"
INTERNASIONAL = "IT"
INKLUSI = "IK"
SEGREGASI = "SG"
STATUS_SEKOLAH = (
(SWASTA, "Swasta"),
(NEGRI, "Negri"),
(INTERNASIONAL, "Internasional")
("SW", "Swasta"),
("NG", "Negri"),
("IT", "Internasional")
)
JENIS = (
(INKLUSI, "Inklusi"),
(SEGREGASI, "Segregasi")
("IK", "Inklusi"),
("SG", "Segregasi")
)
name = models.CharField(max_length=50)
alamat = models.CharField(max_length=100)
......@@ -24,11 +19,79 @@ class Sekolah(models.Model):
status = models.CharField(
max_length=2,
choices=STATUS_SEKOLAH,
default=SWASTA
default="SW"
)
jenis_sekolah = models.CharField(
max_length=2,
choices=JENIS,
default=INKLUSI
default="IK"
)
akreditasi = models.CharField(max_length=1, null=True, default=None)
class Penyandang(models.Model):
JENIS_KELAMIN_OPTION = (
("LAKI-LAKI", "Laki-Laki"),
("PEREMPUAN", "Perempuan")
)
PENDIDIKAN_TERAKHIR = (
("SD", "SD"),
("MP", "SMP/SLTP"),
("MA", "SMA/SLTA"),
("D1", "Diploma 1"),
("D2", "Diploma 2"),
("D3", "Diploma 3"),
("S1", "Sarjana"),
("S2", "Magister"),
("S3", "Doktor"),
("NF", "Non-Formal/Lainnya"),
("NA", "Tidak Sekolah")
)
PEKERJAAN_OPTION = (
("PT", "Petani"),
("BR", "Buruh"),
("WS", "Pedagang/Wiraswasta"),
("JS", "Jasa"),
("PN", "PNS/TNI/POLRI"),
("SN", "Pensiunan"),
("IR", "Ibu Rumah Tangga"),
("PL", "Pelajar"),
("LA", "Lainnya"),
("NA", "Tidak Bekerja")
)
KATEGORI_DISABILITAS = (
("FS", "Fisik"),
("IN", "Intelektual"),
("MN", "Mental"),
("SN", "Sensorik")
)
name = models.CharField(max_length=50)
alamat = models.CharField(max_length=100)
tempat_lahir = models.CharField(max_length=50)
tanggal_lahir = models.DateField()
jenis_kelamin = models.CharField(
max_length=9,
choices=JENIS_KELAMIN_OPTION,
default="LAKI-LAkI"
)
pendidikan = models.CharField(
max_length=2,
choices=PENDIDIKAN_TERAKHIR,
default="NA"
)
pekerjaan = models.CharField(
max_length=2,
choices=PEKERJAAN_OPTION,
default="NA"
)
kategori = models.CharField(
max_length=2,
choices=KATEGORI_DISABILITAS,
default="FS"
)
no_telp = models.CharField(max_length=16, null=True)
email = models.CharField(max_length=50, null=True)
nama_wali = models.CharField(max_length=50, null=True)
alamat_wali = models.CharField(max_length=100, null=True)
telp_wali = models.CharField(max_length=16, null=True)
from rest_framework import serializers
from .models import Sekolah
from .models import Sekolah, Penyandang
class SekolahSerializer(serializers.HyperlinkedModelSerializer):
......@@ -16,3 +16,24 @@ class SekolahSerializer(serializers.HyperlinkedModelSerializer):
'jenis_sekolah',
'akreditasi'
)
class PenyandangSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Penyandang
fields = (
'id',
'name',
'alamat',
'tempat_lahir',
'tanggal_lahir',
'jenis_kelamin',
'pendidikan',
'pekerjaan',
'kategori',
'no_telp',
'email',
'nama_wali',
'alamat_wali',
'telp_wali'
)
......@@ -3,45 +3,111 @@ from http import HTTPStatus
from django.test import TestCase, Client
from django.db.utils import IntegrityError
from django.urls import path, include, reverse
from .models import Sekolah
from .models import Sekolah, Penyandang
from .serializers import SekolahSerializer
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'NOT NULL constraint failed'
ID = 'id'
NAME = 'name'
ALAMAT = 'alamat'
NO_TELP = 'no_telp'
WEBSITE = 'website'
JUMLAH_SISWA = 'jumlah_siswa'
STATUS = 'status'
JENIS_SEKOLAH = 'jenis_sekolah'
AKREDITASI = 'akreditasi'
MOCK_DATA = {
MOCK_SEKOLAH = {
ID: 1,
NAME: 'Sekolah Cita Buana',
ALAMAT: 'Jl. Paso No.84, Jagakarsa, Jakarta Selatan',
NO_TELP: '(021)7820088',
WEBSITE: 'http://www.sekolahcitabuana.com',
WEBSITE: 'https://www.sekolahcitabuana.com',
JUMLAH_SISWA: 250,
STATUS: 'SW',
JENIS_SEKOLAH: 'IK',
AKREDITASI: 'B'
}
TEMPAT_LAHIR = 'tempat_lahir'
TANGGAL_LAHIR = 'tanggal_lahir'
JENIS_KELAMIN = 'jenis_kelamin'
PENDIDIKAN = 'pendidikan'
PEKERJAAN = 'pekerjaan'
KATEGORI = 'kategori'
EMAIL = 'email'
NAMA_WALI = 'nama_wali'
ALAMAT_WALI = 'alamat_wali'
TELP_WALI = 'telp_wali'
MOCK_PENYANDANG = {
ID: 1,
NAME: 'Nadia Anggraini',
ALAMAT: 'Depok, Jawa Barat',
TEMPAT_LAHIR: 'Depok',
TANGGAL_LAHIR: '1999-02-01',
JENIS_KELAMIN: 'PEREMPUAN',
PENDIDIKAN: 'S1',
PEKERJAAN: 'PL',
KATEGORI: 'FS',
NO_TELP: '082577776666',
EMAIL: 'nadiaag@email.com',
NAMA_WALI: 'wali',
ALAMAT_WALI: 'sama',
TELP_WALI: 'sama'
}
def setup():
def sekolah_setup():
Sekolah.objects.create(
name=MOCK_DATA[NAME],
alamat=MOCK_DATA[ALAMAT],
no_telp=MOCK_DATA[NO_TELP],
website=MOCK_DATA[WEBSITE],
jumlah_siswa=MOCK_DATA[JUMLAH_SISWA],
status=MOCK_DATA[STATUS],
jenis_sekolah=MOCK_DATA[JENIS_SEKOLAH],
akreditasi=MOCK_DATA[AKREDITASI]
name=MOCK_SEKOLAH[NAME],
alamat=MOCK_SEKOLAH[ALAMAT],
no_telp=MOCK_SEKOLAH[NO_TELP],
website=MOCK_SEKOLAH[WEBSITE],
jumlah_siswa=MOCK_SEKOLAH[JUMLAH_SISWA],
status=MOCK_SEKOLAH[STATUS],
jenis_sekolah=MOCK_SEKOLAH[JENIS_SEKOLAH],
akreditasi=MOCK_SEKOLAH[AKREDITASI]
)
def penyandang_setup():
Penyandang.objects.create(
name=MOCK_PENYANDANG[NAME],
alamat=MOCK_PENYANDANG[ALAMAT],
tempat_lahir=MOCK_PENYANDANG[TEMPAT_LAHIR],
tanggal_lahir=MOCK_PENYANDANG[TANGGAL_LAHIR],
jenis_kelamin=MOCK_PENYANDANG[JENIS_KELAMIN],
pendidikan=MOCK_PENYANDANG[PENDIDIKAN],
pekerjaan=MOCK_PENYANDANG[PEKERJAAN],
kategori=MOCK_PENYANDANG[KATEGORI],
no_telp=MOCK_PENYANDANG[NO_TELP],
email=MOCK_PENYANDANG[EMAIL],
nama_wali=MOCK_PENYANDANG[NAMA_WALI],
alamat_wali=MOCK_PENYANDANG[ALAMAT_WALI],
telp_wali=MOCK_PENYANDANG[TELP_WALI]
)
def auth_setup():
email = 'mock_user@email.com'
passcode = 'pass12345'
Client().post('/api/register/', {
'name': 'name',
'email': email,
'phone_number': 000000000,
'password': passcode
})
token_response = Client().post('/api-token-auth/',
{'username': email, 'password': passcode})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
return Client(HTTP_AUTHORIZATION='token '+token)
class LayananKhususModelTest(TestCase):
def test_models_sekolah_not_created(self):
......@@ -52,10 +118,22 @@ class LayananKhususModelTest(TestCase):
NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_sekolah(self):
setup()
sekolah_setup()
count = Sekolah.objects.all().count()
self.assertNotEqual(count, 0)
def test_models_penyandang_not_created(self):
with self.assertRaises(IntegrityError) as ex:
obj = Penyandang(name=None)
obj.save()
self.assertTrue(str(ex.exception).startswith(
NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_penyandang(self):
penyandang_setup()
count = Penyandang.objects.all().count()
self.assertNotEqual(count, 0)
class LayananKhususViewsTest(TestCase):
urlpatterns = [
......@@ -63,19 +141,23 @@ class LayananKhususViewsTest(TestCase):
]
def test_sekolah_serializer_valid(self):
serializer = SekolahSerializer(data=MOCK_DATA)
serializer = SekolahSerializer(data=MOCK_SEKOLAH)
self.assertTrue(serializer.is_valid)
def test_penyandang_serializer_valid(self):
serializer = SekolahSerializer(data=MOCK_PENYANDANG)
self.assertTrue(serializer.is_valid)
def test_can_get_list_sekolah(self):
setup()
sekolah_setup()
response = Client().get(reverse('list-sekolah'))
self.assertEqual(response.status_code, HTTPStatus.OK)
def test_get_lokasi_list_json(self):
setup()
sekolah_setup()
response = Client().get(reverse('list-sekolah'))
content = json.loads(response.content.decode('utf-8'))
expected_json = [MOCK_DATA]
expected_json = [MOCK_SEKOLAH]
self.assertEqual(content, expected_json)
def test_cannot_post_list_sekolah(self):
......@@ -83,23 +165,23 @@ class LayananKhususViewsTest(TestCase):
self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED)
def test_can_get_detail_sekolah(self):
setup()
sekolah_setup()
response = Client().get(
reverse('detail-sekolah', kwargs={'id_sekolah': 1})
)
self.assertEqual(response.status_code, HTTPStatus.OK)
def test_can_get_lokasi_details_json(self):
setup()
def test_get_details_detail_json(self):
sekolah_setup()
response = Client().get(
reverse('detail-sekolah', kwargs={'id_sekolah': 1})
)
content = json.loads(response.content.decode('utf-8'))
expected_json = MOCK_DATA
expected_json = MOCK_SEKOLAH
self.assertEqual(content, expected_json)
def test_cannot_post_detail_sekolah(self):
setup()
sekolah_setup()
response = Client().post(
reverse('detail-sekolah', kwargs={'id_sekolah': 1})
)
......@@ -109,3 +191,28 @@ class LayananKhususViewsTest(TestCase):
response = Client().get(
reverse('detail-sekolah', kwargs={'id_sekolah': 1}))
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
def test_can_post_register_penyandang(self):
client = auth_setup()
response = client.post(reverse('register-penyandang-disabilitas'),
MOCK_PENYANDANG)
self.assertEqual(response.status_code, HTTPStatus.CREATED)