Fakultas Ilmu Komputer UI

Commit e050a5bc authored by Bimo Iman Smartadi's avatar Bimo Iman Smartadi
Browse files

[CHORES] Fixed merge conflict making an api missing

parents 493a2ed8 0b82fe81
Pipeline #45671 passed with stages
in 14 minutes and 40 seconds
from django.contrib import admin from django.contrib import admin
from .models import Sekolah from .models import Sekolah, Penyandang
# Register your models here. # Register your models here.
admin.site.register(Sekolah) 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),
),
]
# Generated by Django 2.1.5 on 2020-05-05 03:38
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('layanan_khusus', '0012_auto_20200505_0314'),
('layanan_khusus', '0018_auto_20200504_0208'),
]
operations = [
]
...@@ -2,19 +2,14 @@ from django.db import models ...@@ -2,19 +2,14 @@ from django.db import models
class Sekolah(models.Model): class Sekolah(models.Model):
SWASTA = "SW"
NEGRI = "NG"
INTERNASIONAL = "IT"
INKLUSI = "IK"
SEGREGASI = "SG"
STATUS_SEKOLAH = ( STATUS_SEKOLAH = (
(SWASTA, "Swasta"), ("SW", "Swasta"),
(NEGRI, "Negri"), ("NG", "Negri"),
(INTERNASIONAL, "Internasional") ("IT", "Internasional")
) )
JENIS = ( JENIS = (
(INKLUSI, "Inklusi"), ("IK", "Inklusi"),
(SEGREGASI, "Segregasi") ("SG", "Segregasi")
) )
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
alamat = models.CharField(max_length=100) alamat = models.CharField(max_length=100)
...@@ -24,11 +19,79 @@ class Sekolah(models.Model): ...@@ -24,11 +19,79 @@ class Sekolah(models.Model):
status = models.CharField( status = models.CharField(
max_length=2, max_length=2,
choices=STATUS_SEKOLAH, choices=STATUS_SEKOLAH,
default=SWASTA default="SW"
) )
jenis_sekolah = models.CharField( jenis_sekolah = models.CharField(
max_length=2, max_length=2,
choices=JENIS, choices=JENIS,
default=INKLUSI default="IK"
) )
akreditasi = models.CharField(max_length=1, null=True, default=None) 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 rest_framework import serializers
from .models import Sekolah from .models import Sekolah, Penyandang
class SekolahSerializer(serializers.HyperlinkedModelSerializer): class SekolahSerializer(serializers.HyperlinkedModelSerializer):
...@@ -16,3 +16,24 @@ class SekolahSerializer(serializers.HyperlinkedModelSerializer): ...@@ -16,3 +16,24 @@ class SekolahSerializer(serializers.HyperlinkedModelSerializer):
'jenis_sekolah', 'jenis_sekolah',
'akreditasi' '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'
)
...@@ -2,46 +2,116 @@ import json ...@@ -2,46 +2,116 @@ import json
from http import HTTPStatus from http import HTTPStatus
from django.test import TestCase, Client from django.test import TestCase, Client
from django.db.utils import IntegrityError from django.db.utils import IntegrityError
from django.contrib.auth.models import User
from django.urls import path, include, reverse from django.urls import path, include, reverse
from .models import Sekolah from .models import Sekolah, Penyandang
from .serializers import SekolahSerializer from .serializers import SekolahSerializer
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'NOT NULL constraint failed' NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'NOT NULL constraint failed'
ID = 'id' ID = 'id'
NAME = 'name' NAME = 'name'
ALAMAT = 'alamat' ALAMAT = 'alamat'
NO_TELP = 'no_telp' NO_TELP = 'no_telp'
WEBSITE = 'website' WEBSITE = 'website'
JUMLAH_SISWA = 'jumlah_siswa' JUMLAH_SISWA = 'jumlah_siswa'
STATUS = 'status' STATUS = 'status'
JENIS_SEKOLAH = 'jenis_sekolah' JENIS_SEKOLAH = 'jenis_sekolah'
AKREDITASI = 'akreditasi' AKREDITASI = 'akreditasi'
MOCK_DATA = {
MOCK_SEKOLAH = {
ID: 1, ID: 1,
NAME: 'Sekolah Cita Buana', NAME: 'Sekolah Cita Buana',
ALAMAT: 'Jl. Paso No.84, Jagakarsa, Jakarta Selatan', ALAMAT: 'Jl. Paso No.84, Jagakarsa, Jakarta Selatan',
NO_TELP: '(021)7820088', NO_TELP: '(021)7820088',
WEBSITE: 'http://www.sekolahcitabuana.com', WEBSITE: 'https://www.sekolahcitabuana.com',
JUMLAH_SISWA: 250, JUMLAH_SISWA: 250,
STATUS: 'SW', STATUS: 'SW',
JENIS_SEKOLAH: 'IK', JENIS_SEKOLAH: 'IK',
AKREDITASI: 'B' 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( Sekolah.objects.create(
name=MOCK_DATA[NAME], name=MOCK_SEKOLAH[NAME],
alamat=MOCK_DATA[ALAMAT], alamat=MOCK_SEKOLAH[ALAMAT],
no_telp=MOCK_DATA[NO_TELP], no_telp=MOCK_SEKOLAH[NO_TELP],
website=MOCK_DATA[WEBSITE], website=MOCK_SEKOLAH[WEBSITE],
jumlah_siswa=MOCK_DATA[JUMLAH_SISWA], jumlah_siswa=MOCK_SEKOLAH[JUMLAH_SISWA],
status=MOCK_DATA[STATUS], status=MOCK_SEKOLAH[STATUS],
jenis_sekolah=MOCK_DATA[JENIS_SEKOLAH], jenis_sekolah=MOCK_SEKOLAH[JENIS_SEKOLAH],
akreditasi=MOCK_DATA[AKREDITASI] 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
})
test_user = User.objects.get(username=email)
test_user.is_active = True
test_user.save()
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): class LayananKhususModelTest(TestCase):
def test_models_sekolah_not_created(self): def test_models_sekolah_not_created(self):
...@@ -52,10 +122,22 @@ class LayananKhususModelTest(TestCase): ...@@ -52,10 +122,22 @@ class LayananKhususModelTest(TestCase):
NOT_NULL_CONSTRAINT_FAILED_MESSAGE)) NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_sekolah(self): def test_models_create_new_sekolah(self):
setup() sekolah_setup()
count = Sekolah.objects.all().count() count = Sekolah.objects.all().count()
self.assertNotEqual(count, 0) 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): class LayananKhususViewsTest(TestCase):
urlpatterns = [ urlpatterns = [
...@@ -63,19 +145,23 @@ class LayananKhususViewsTest(TestCase): ...@@ -63,19 +145,23 @@ class LayananKhususViewsTest(TestCase):
] ]
def test_sekolah_serializer_valid(self): 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) self.assertTrue(serializer.is_valid)
def test_can_get_list_sekolah(self): def test_can_get_list_sekolah(self):
setup() sekolah_setup()
response = Client().get(reverse('list-sekolah')) response = Client().get(reverse('list-sekolah'))
self.assertEqual(response.status_code, HTTPStatus.OK) self.assertEqual(response.status_code, HTTPStatus.OK)
def test_get_lokasi_list_json(self): def test_get_lokasi_list_json(self):
setup() sekolah_setup()
response = Client().get(reverse('list-sekolah')) response = Client().get(reverse('list-sekolah'))
content = json.loads(response.content.decode('utf-8')) content = json.loads(response.content.decode('utf-8'))
expected_json = [MOCK_DATA] expected_json = [MOCK_SEKOLAH]
self.assertEqual(content, expected_json) self.assertEqual(content, expected_json)
def test_cannot_post_list_sekolah(self): def test_cannot_post_list_sekolah(self):
...@@ -83,23 +169,23 @@ class LayananKhususViewsTest(TestCase): ...@@ -83,23 +169,23 @@ class LayananKhususViewsTest(TestCase):
self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED)