Fakultas Ilmu Komputer UI

Commit e96e4f9d authored by M. Abdurrahman's avatar M. Abdurrahman
Browse files

Merge branch 'staging' into PBI-7-fitur_informasi_layanan_khusus_disabilitas

parents 1de840a9 656f9492
Pipeline #44301 passed with stages
in 7 minutes and 15 seconds
......@@ -120,13 +120,14 @@ Make `POST` request to API endpoint `/informasi-lokasi/lokasi/add-fasilitas/*nam
<b>Make sure you have token it your request header.</b>
<b>Add this to your request header. `Authorization` with value `token *your_token_from_request*`</b>
### 8. To see a facility list:
### 8. To see a facility list from a location:
Make `GET` request to API endpoint `/informasi-lokasi/lokasi/list-fasilitas/*nama-lokasi*/`. <br>
It will return a json with the following key:
* `id`: id of the facility
* `nama_lokasi`: location name of the facility
* `deskripsi`: the description
* `creator`: User's last name who registered the facility
* `creators_email`: User's email who registered the facility
* `date_time`: Date when the facility was made
* `like`: how many people like this facility. default is 0
* `dislike`: how many people dislike this facility. default is 0
......@@ -135,13 +136,13 @@ It will return a json with the following key:
* `image`: Image for facility
* `is_verified`: Verified status
### 9. To see a facility details:
Make `GET` request to API endpoint `/informasi-lokasi/lokasi/detail-fasilitas/*nama-lokasi*/*id-fasilitas*/`. <br>
It will return a json with the following key:
* `nama_lokasi`: location name of the facility
* `deskripsi`: the description
* `creator`: User's last name who registered the facility
* `creators_email`: User's email who registered the facility
* `date_time`: Date when the facility was made
* `like`: how many people like this facility. default is 0
* `dislike`: how many people dislike this facility. default is 0
......@@ -150,7 +151,38 @@ It will return a json with the following key:
* `image`: Image for facility
* `is_verified`: Verified status
### 10. To view a sekolah list:
### 10. To update a facility details:
Make `PUT` request to API endpoint `/informasi-lokasi/lokasi/update-fasilitas/*nama-lokasi*/*id-fasilitas*/`. <br>
It requires a request with the following key:
* `deskripsi`: the description
* `rating`: rating of the facility. Default is 3
* `tag`: Facility tag
* `image`: Image for facility
<b>Make sure you have token it your request header.</b>
<b>Add this to your request header. `Authorization` with value `token *your_token_from_request*`</b>
<b>This token is also used to authorize whether you are the creator of the facility or not, since only the creator
of the facility could update the facility</b>
### 10. To update a location phone_number:
Make `PUT` request to API endpoint `/informasi-lokasi/lokasi/update-lokasi/*nama-lokasi*/`. <br>
It requires a request with the following key:
* `no_telp`: the description
<b>Make sure you have token it your request header.</b>
<b>Add this to your request header. `Authorization` with value `token *your_token_from_request*`</b>
<b>This token is also used to authorize whether you are the creator of the location or not, since only the creator
of the location could update the location</b>
### 10. To like / dislike a facility:
Make `PUT` request to API endpoint `/informasi-lokasi/lokasi/like-facility/*nama-lokasi*/*operation*/`. <br>
Replace the `operation` with:
* `like` : if you want to like the facility
* `dislike` : if you want to dislike the facility
You cannot like/dislike the same model more than once, if you like a facility then you dislike it,
the "like" you give before will be replaced by dislike, and vice-versa.
<b>Make sure you have token it your request header.</b>
<b>Add this to your request header. `Authorization` with value `token *your_token_from_request*`</b>
### 11. To view a sekolah list:
Make `GET` request to API endpoint `/layanan-khusus/sekolah/list/`. <br>
It will return a json list of sekolah with key:
* `id` : id of sekolah
......@@ -163,7 +195,7 @@ It will return a json list of sekolah with key:
* `jenis_sekolah` : type of sekolah's management (inklusi, segregasi)
* `akreditasi` : accreditation
### 11. To view a sekolah details:
### 12. To view a sekolah details:
Make `GET` request to API endpoint `/layanan-khusus/sekolah/detail/*id_sekolah*/`. <br>
It will return a json with key:
* `id` : id of sekolah
......@@ -174,4 +206,4 @@ 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
* `akreditasi` : accreditation
\ No newline at end of file
# Generated by Django 2.1.5 on 2020-04-23 18:50
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('informasi_fasilitas', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Dislikes',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True)),
('fasilitas', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='informasi_fasilitas.Fasilitas')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Likes',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(auto_now_add=True)),
('fasilitas', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='informasi_fasilitas.Fasilitas')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
......@@ -54,7 +54,7 @@ class Fasilitas(models.Model):
deskripsi = models.TextField()
like = models.IntegerField(default=0)
dislike = models.IntegerField(default=0)
rating = models.IntegerField(default=3)
rating = models.IntegerField(default=3)
tag = MultiSelectField(choices=FACILITIES, null=True, default=None)
image = models.ImageField(upload_to="static/img", null=True, default=None)
is_verified = models.BooleanField(default=False)
......@@ -63,4 +63,14 @@ class Komentar(models.Model):
fasilitas =models.ForeignKey(Fasilitas, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
date_time = models.DateTimeField(auto_now_add=True)
deskripsi = models.TextField()
\ No newline at end of file
deskripsi = models.TextField()
class Likes(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
fasilitas = models.ForeignKey(Fasilitas, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
class Dislikes(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
fasilitas = models.ForeignKey(Fasilitas, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
from django.test import TestCase, Client
from django.db.utils import IntegrityError
from .models import Lokasi, Fasilitas, Komentar, KURSI_RODA, RUNNING_TEXT
from .models import Lokasi, Fasilitas, Komentar, KURSI_RODA, RUNNING_TEXT, Likes, Dislikes
from .serializers import LokasiSerializer
from registrasi.models import BisaGoUser
from django.contrib.auth.models import User
from django.urls import reverse, path, include
from http import HTTPStatus
import json
import tempfile
# Create your tests here.
not_null_constraint_failed_message = 'NOT NULL constraint failed'
user_test = User(username='user@gmail.com',
last_name='name',
email='user@gmail.com',
password='hahagotim'
)
lokasi_test = Lokasi(name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image= tempfile.NamedTemporaryFile(suffix=".jpg").name
)
class InformasiFasilitasModelTest(TestCase):
not_null_constraint_failed_message = 'NOT NULL constraint failed'
def test_models_lokasi_not_created(self):
with self.assertRaises(IntegrityError) as cm:
obj = Lokasi(name=None)
obj.save()
self.assertTrue(str(cm.exception).startswith(
self.not_null_constraint_failed_message))
not_null_constraint_failed_message))
def test_models_create_new_lokasi(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
......@@ -37,25 +50,13 @@ class InformasiFasilitasModelTest(TestCase):
obj = Fasilitas(lokasi=None)
obj.save()
self.assertTrue(str(cm.exception).startswith(
self.not_null_constraint_failed_message))
not_null_constraint_failed_message))
def test_models_create_new_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=User(
username='user@gmail.com',
last_name='name',
email='user@gmail.com',
password='hahagotim'
)
user=user_test
user.save()
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi=lokasi_test
lokasi.save()
Fasilitas.objects.create(
lokasi=lokasi,
......@@ -73,27 +74,15 @@ class InformasiFasilitasModelTest(TestCase):
def test_models_komentar_not_created(self):
with self.assertRaises(IntegrityError) as cm:
obj = Komentar(fasilitas=None)
obj.save();
obj.save()
self.assertTrue(str(cm.exception).startswith(
self.not_null_constraint_failed_message))
not_null_constraint_failed_message))
def test_models_create_new_komentar(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=User(
username='user',
last_name='name',
email='user@gmail.com',
password='hahagotim'
)
user=user_test
user.save()
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi=lokasi_test
lokasi.save()
fasilitas=Fasilitas(
lokasi=lokasi,
......@@ -113,24 +102,111 @@ class InformasiFasilitasModelTest(TestCase):
)
count = Komentar.objects.all().count()
self.assertNotEqual(count, 0)
def test_models_dislikes_not_created(self):
with self.assertRaises(IntegrityError) as cm:
obj = Dislikes(fasilitas=None)
obj.save()
self.assertTrue(str(cm.exception).startswith(
not_null_constraint_failed_message))
def test_models_create_new_dislikes(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=user_test
user.save()
lokasi=lokasi_test
lokasi.save()
fasilitas=Fasilitas(
lokasi=lokasi,
user=user,
deskripsi="penjelasan panjang",
like=0,
dislike=0,
rating=5,
tag={KURSI_RODA, RUNNING_TEXT},
image=image
)
fasilitas.save()
Dislikes.objects.create(user=user,
fasilitas=fasilitas,
)
count = Dislikes.objects.all().count()
self.assertNotEqual(count, 0)
def test_view_lokasi(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
lokasi=Lokasi(
name='Sekolah',
latitude=0.0,
longitude=0.0,
alamat='Soppeng sentosa',
no_telp='081212123131',
image=image
)
lokasi.save()
def test_models_likes_not_created(self):
with self.assertRaises(IntegrityError) as cm:
obj = Likes(fasilitas=None)
obj.save()
self.assertTrue(str(cm.exception).startswith(
not_null_constraint_failed_message))
def test_models_create_new_likes(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=user_test
user.save()
lokasi=lokasi_test
lokasi.save()
fasilitas=Fasilitas(
lokasi=lokasi,
user=user,
deskripsi="penjelasan panjang",
like=0,
dislike=0,
rating=5,
tag={KURSI_RODA, RUNNING_TEXT},
image=image
)
fasilitas.save()
Likes.objects.create(user=user,
fasilitas=fasilitas,
)
count = Likes.objects.all().count()
self.assertNotEqual(count, 0)
class InformasiFasilitasViewTest(TestCase):
urlpatterns = [
path('informasi-fasilitas/', include('informasi_fasilitas.urls')),
]
def setUp(self):
email='usersetup@gmail.com'
password='hahagotim'
Client().post('/api/register/',
{'name':'name',
'email':email,
'phone_number':1000000,
'password':password})
token_response = Client().post('/api-token-auth/',
{'username' : email, 'password' : password})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION='token '+token)
client.post(reverse('add-lokasi'),
{'name' : 'Ma Homie',
'latitude' : 0.1,
'longitude' : 0.1,
'alamat' : 'Jl. Raya Bogor no.2, Jakarta',
'no_telp' : '081212123132'})
client.post(reverse('add-lokasi'),
{'name' : 'Ma Homies',
'latitude' : 0.2,
'longitude' : 0.1,
'alamat' : 'Jl. Raya Bogor no.3, Jakarta',
'no_telp' : '081212123134'})
client.post(reverse('add-fasilitas', kwargs={"nama_lokasi":"Ma Homie"}),
{'deskripsi' : 'kayaknya deskrispi',
'rating' : 3,
'tag' : "KR RT",
'image' : 'gambar.jpg',
})
class LokasiRelatedViewTest(InformasiFasilitasViewTest):
def test_LokasiSerializer_valid(self):
serializer = LokasiSerializer(data = {
'name' : 'Mall1',
......@@ -141,45 +217,61 @@ class InformasiFasilitasViewTest(TestCase):
})
self.assertTrue(serializer.is_valid)
def test_can_get_lokasi_list(self):
def test_can_get_lokasi_list_url(self):
response = Client().get(reverse('lokasi-list'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, HTTPStatus.OK)
def test_get_lokasi_list_json(self):
response = Client().get(reverse('lokasi-list'))
content = json.loads(response.content.decode('utf-8'))
expected_json = [{'id': 1,
'name':'Ma Homie',
'latitude' : 0.1,
'longitude' : 0.1,
'alamat' : 'Jl. Raya Bogor no.2, Jakarta',
'no_telp' : '081212123132',
'image':None},
{'id': 2,
'name':'Ma Homies',
'latitude' : 0.2,
'longitude' : 0.1,
'alamat' : 'Jl. Raya Bogor no.3, Jakarta',
'no_telp' : '081212123134',
'image':None}
]
self.assertEqual(content, expected_json)
def test_cannot_post_lokasi_list(self):
def test_cannot_post_lokasi_list_url(self):
response = Client().post(reverse('lokasi-list'))
self.assertEqual(response.status_code, 405)
self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED)
def test_can_get_lokasi_details(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi=lokasi_test
lokasi.save()
response = Client().get(reverse('lokasi-details', kwargs={'name':'Mall'}))
self.assertEqual(response.status_code, 200)
response = Client().get(reverse('lokasi-details', kwargs={'nama_lokasi':'Mall'}))
self.assertEqual(response.status_code, HTTPStatus.OK)
def test_can_get_lokasi_details_json(self):
response = Client().get(reverse('lokasi-details', kwargs={'nama_lokasi':'Ma Homie'}))
content = json.loads(response.content.decode('utf-8'))
expected_json = {'id': 1,
'name':'Ma Homie',
'latitude' : 0.1,
'longitude' : 0.1,
'alamat' : 'Jl. Raya Bogor no.2, Jakarta',
'no_telp' : '081212123132',
'image':None}
self.assertEqual(content, expected_json)
def test_cannot_post_lokasi_details(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi=lokasi_test
lokasi.save()
response = Client().post(reverse('lokasi-details', kwargs={'name':'Mall'}))
self.assertEqual(response.status_code, 405)
response = Client().post(reverse('lokasi-details', kwargs={'nama_lokasi':'Mall'}))
self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED)
def test_get_lokasi_details_not_found(self):
response = Client().get(reverse('lokasi-details', kwargs={'name':'Mall'}))
self.assertEqual(response.status_code, 404)
response = Client().get(reverse('lokasi-details', kwargs={'nama_lokasi':'Mall'}))
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
def test_can_post_add_lokasi(self):
email='user@gmail.com'
......@@ -201,7 +293,64 @@ class InformasiFasilitasViewTest(TestCase):
'longitude' : 0.0,
'alamat' : 'Jl. Raya Bogor no.1, Jakarta',
'no_telp' : '081212123131'})
self.assertEqual(response.status_code, 201)
self.assertEqual(response.status_code, HTTPStatus.CREATED)
def test_can_post_add_json(self):
email='user@gmail.com'
password='hahagotim'
Client().post('/api/register/',
{'name':'name',
'email':email,
'phone_number':000000000,
'password':password})
token_response = Client().post('/api-token-auth/',
{'username' : email, 'password' : password})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION='token '+token)
response = client.post(reverse('add-lokasi'),
{'name' : 'Mall',
'latitude' : 0.0,
'longitude' : 0.0,
'alamat' : 'Jl. Raya Bogor no.1, Jakarta',
'no_telp' : '081212123131'})
response_json = json.loads(response.content.decode("utf-8"))
expected_json = {
"id": 3,
'name' : 'Mall',
'latitude' : 0.0,
'longitude' : 0.0,
'alamat' : 'Jl. Raya Bogor no.1, Jakarta',
'no_telp' : '081212123131',
"image" : None
}
self.assertEqual(response_json, expected_json)
def test_put_update_detail_lokasi_success(self):
email='user@gmail.com'
password='hahagotim'
Client().post('/api/register/',
{'name':'name',
'email':email,
'phone_number':000000000,
'password':password})
token_response = Client().post('/api-token-auth/',
{'username' : email, 'password' : password})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION='token '+token)
lokasi=lokasi_test
lokasi.save()
response = client.put(reverse('update-lokasi', kwargs={'nama_lokasi':'Mall'}),
data={'no_telp' : '0000000121',},
content_type="multipart/form-data")
self.assertEqual(response.status_code, HTTPStatus.ACCEPTED)
def test_cannot_get_add_lokasi(self):
email='user@gmail.com'
......@@ -218,25 +367,15 @@ class InformasiFasilitasViewTest(TestCase):
client = Client(HTTP_AUTHORIZATION='token '+token)
response = client.get(reverse('add-lokasi'))
self.assertEqual(response.status_code, 405)
self.assertEqual(response.status_code, HTTPStatus.METHOD_NOT_ALLOWED)
class FasilitasRelatedViewTest(InformasiFasilitasViewTest):
def test_can_get_list_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=User(
username='user@gmail.com',
last_name='name',
email='user@gmail.com',
password='hahagotim'
)
user=user_test
user.save()
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi=lokasi_test
lokasi.save()
fasilitas=Fasilitas(
lokasi=lokasi,
......@@ -250,7 +389,7 @@ class InformasiFasilitasViewTest(TestCase):
)
fasilitas.save()
response = Client().get(reverse('list-fasilitas', kwargs={'nama_lokasi':'Mall'}))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.status_code, HTTPStatus.OK)
def test_cannot_post_list_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
......@@ -272,21 +411,9 @@ class InformasiFasilitasViewTest(TestCase):
def test_can_get_detail_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=User(
username='user@gmail.com',
last_name='name',
email='user@gmail.com',
password='hahagotim'
)
user=user_test
user.save()
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi=lokasi_test
lokasi.save()
fasilitas=Fasilitas(
lokasi=lokasi,
......@@ -305,21 +432,9 @@ class InformasiFasilitasViewTest(TestCase):
def test_cannot_post_detail_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=User(
username='user@gmail.com',
last_name='name',
email='user@gmail.com',
password='hahagotim'
)
user=user_test
user.save()