Fakultas Ilmu Komputer UI

Commit 27c50698 authored by Bimo Iman Smartadi's avatar Bimo Iman Smartadi
Browse files

Coldfix pull

parents 40186a87 3cb4d9b0
......@@ -10,7 +10,6 @@ UnitTest:
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+)%/'
before_script:
- pip install -r requirements.txt
- python manage.py makemigrations
- python manage.py migrate
- python manage.py collectstatic --no-input
when: on_success
......
#!/bin/bash
python manage.py makemigrations
python manage.py migrate
......@@ -130,6 +130,9 @@ class InformasiFasilitasTest(TestCase):
def client_user_token(self):
Client().post('/api/register/', self.user_post)
test_user = User.objects.get(username=self.user_post["email"])
test_user.is_active = True
test_user.save()
token_response = Client().post('/api-token-auth/', {'username': self.user_post["email"],
'password': self.user_post["password"]})
content = json.loads(token_response.content.decode('utf-8'))
......@@ -139,6 +142,9 @@ class InformasiFasilitasTest(TestCase):
def client_user_token2(self):
Client().post('/api/register/', self.user_post)
test_user = User.objects.get(username=self.default_username_email)
test_user.is_active = True
test_user.save()
token_response = Client().post('/api-token-auth/', {'username': self.default_username_email,
'password': self.default_password})
content = json.loads(token_response.content.decode('utf-8'))
......@@ -160,6 +166,9 @@ class InformasiFasilitasViewTest(InformasiFasilitasTest):
'email': email,
'phone_number': 1000000,
'password': password})
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': password})
......
......@@ -66,13 +66,7 @@ class LokasiRelatedViewTest(InformasiFasilitasViewTest):
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
def test_cannot_get_add_lokasi(self):
Client().post('/api/register/', self.user_post)
token_response = Client().post('/api-token-auth/', {'username': self.user_post["email"],
'password': self.user_post["password"]})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION='token '+token)
client = self.client_user_token()
response = client.get(reverse('add-lokasi'))
self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED)
......@@ -109,13 +103,7 @@ class LokasiRelatedViewTest(InformasiFasilitasViewTest):
self.assertEqual(response_json, expected_json)
def test_put_update_detail_lokasi_success(self):
Client().post('/api/register/', self.user_post)
token_response = Client().post('/api-token-auth/', {'username': self.user_post["email"],
'password': self.user_post["password"]})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION='token '+token)
client = self.client_user_token()
urls = reverse('update-lokasi',
kwargs={'nama_lokasi': self.lokasi_test_1["name"]})
response = client.put(urls, data=urlencode({'no_telp': '0000000121', }),
......
from django.contrib import admin
from .models import Sekolah, Penyandang
from .models import Sekolah
# Register your models here.
admin.site.register(Sekolah)
admin.site.register(Penyandang)
# Generated by Django 2.1.5 on 2020-05-03 04:13
# Generated by Django 2.1.5 on 2020-05-04 20:14
from django.db import migrations, models
......@@ -10,12 +10,6 @@ class Migration(migrations.Migration):
]
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',
......
# 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,14 +2,19 @@ from django.db import models
class Sekolah(models.Model):
SWASTA = "SW"
NEGRI = "NG"
INTERNASIONAL = "IT"
INKLUSI = "IK"
SEGREGASI = "SG"
STATUS_SEKOLAH = (
("SW", "Swasta"),
("NG", "Negri"),
("IT", "Internasional")
(SWASTA, "Swasta"),
(NEGRI, "Negri"),
(INTERNASIONAL, "Internasional")
)
JENIS = (
("IK", "Inklusi"),
("SG", "Segregasi")
(INKLUSI, "Inklusi"),
(SEGREGASI, "Segregasi")
)
name = models.CharField(max_length=50)
alamat = models.CharField(max_length=100)
......@@ -19,79 +24,11 @@ class Sekolah(models.Model):
status = models.CharField(
max_length=2,
choices=STATUS_SEKOLAH,
default="SW"
default=SWASTA
)
jenis_sekolah = models.CharField(
max_length=2,
choices=JENIS,
default="IK"
default=INKLUSI
)
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, Penyandang
from .models import Sekolah
class SekolahSerializer(serializers.HyperlinkedModelSerializer):
......@@ -16,24 +16,3 @@ 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,111 +3,45 @@ 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, Penyandang
from .models import Sekolah
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_SEKOLAH = {
MOCK_DATA = {
ID: 1,
NAME: 'Sekolah Cita Buana',
ALAMAT: 'Jl. Paso No.84, Jagakarsa, Jakarta Selatan',
NO_TELP: '(021)7820088',
WEBSITE: 'https://www.sekolahcitabuana.com',
WEBSITE: 'http://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 sekolah_setup():
def setup():
Sekolah.objects.create(
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]
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]
)
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):
......@@ -118,22 +52,10 @@ class LayananKhususModelTest(TestCase):
NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_sekolah(self):
sekolah_setup()
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 = [
......@@ -141,23 +63,19 @@ class LayananKhususViewsTest(TestCase):
]
def test_sekolah_serializer_valid(self):
serializer = SekolahSerializer(data=MOCK_SEKOLAH)
self.assertTrue(serializer.is_valid)
def test_penyandang_serializer_valid(self):
serializer = SekolahSerializer(data=MOCK_PENYANDANG)
serializer = SekolahSerializer(data=MOCK_DATA)
self.assertTrue(serializer.is_valid)
def test_can_get_list_sekolah(self):
sekolah_setup()
setup()
response = Client().get(reverse('list-sekolah'))
self.assertEqual(response.status_code, HTTPStatus.OK)
def test_get_lokasi_list_json(self):
sekolah_setup()
setup()
response = Client().get(reverse('list-sekolah'))
content = json.loads(response.content.decode('utf-8'))
expected_json = [MOCK_SEKOLAH]
expected_json = [MOCK_DATA]
self.assertEqual(content, expected_json)
def test_cannot_post_list_sekolah(self):
......@@ -165,23 +83,23 @@ class LayananKhususViewsTest(TestCase):
self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED)
def test_can_get_detail_sekolah(self):
sekolah_setup()
setup()
response = Client().get(
reverse('detail-sekolah', kwargs={'id_sekolah': 1})
)
self.assertEqual(response.status_code, HTTPStatus.OK)
def test_get_details_detail_json(self):
sekolah_setup()
def test_can_get_lokasi_details_json(self):
setup()
response = Client().get(