Fakultas Ilmu Komputer UI

Commit 40186a87 authored by Bimo Iman Smartadi's avatar Bimo Iman Smartadi
Browse files

[COLDFIX] Komentar time format

parents 1fe837a8 0ef61934
Pipeline #45383 canceled with stages
in 13 minutes and 24 seconds
......@@ -169,8 +169,6 @@ 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>
### 12. To like / dislike a facility:
Make `PUT` request to API endpoint `/informasi-lokasi/lokasi/like-facility/*nama-lokasi*/*operation*/`. <br>
......@@ -206,4 +204,65 @@ 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
### 17. To add a comment an a facility:
Make `POST` request to API endpoint `/informasi-fasilitas/lokasi/add-komentar/*nama_lokasi*/*id_fasilitas*/`. <br>
with key:
* `deskripsi` : The comment message
<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>
### 18. To view a comment list on a facility:
Make `GET` request to API endpoint `/informasi-fasilitas/lokasi/list-komentar/*nama_lokasi*/*id_fasilitas*/`. <br>
It will return a json with these key:
* `*int*` : The index of the model, with dictionary of Komentar model with key below
* `id` : The id of the comment
* `deskripsi` : The description of the comment
* `creator` : The last name of the commentator
* `date_time` : The time when the comment was posted
<?xml version="1.0" ?>
<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="1" lines-covered="57" lines-valid="57" timestamp="1583164490374" version="4.4.1">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>D:\Arato\Documents\unistuff\class\ppl\poipole-dtb-beasiswa-miskin-dan-disabilitas</source>
</sources>
<packages>
<package branch-rate="0" complexity="0" line-rate="1" name="helloworld">
<classes>
<class branch-rate="0" complexity="0" filename="helloworld/admin.py" line-rate="1" name="admin.py">
<methods/>
<lines>
<line hits="1" number="1"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="helloworld/models.py" line-rate="1" name="models.py">
<methods/>
<lines>
<line hits="1" number="1"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="helloworld/tests.py" line-rate="1" name="tests.py">
<methods/>
<lines>
<line hits="1" number="1"/>
<line hits="1" number="2"/>
<line hits="1" number="3"/>
<line hits="1" number="5"/>
<line hits="1" number="6"/>
<line hits="1" number="7"/>
<line hits="1" number="8"/>
<line hits="1" number="9"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="helloworld/urls.py" line-rate="1" name="urls.py">
<methods/>
<lines>
<line hits="1" number="1"/>
<line hits="1" number="2"/>
<line hits="1" number="3"/>
<line hits="1" number="4"/>
<line hits="1" number="6"/>
<line hits="1" number="8"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="helloworld/views.py" line-rate="1" name="views.py">
<methods/>
<lines>
<line hits="1" number="1"/>
<line hits="1" number="4"/>
<line hits="1" number="5"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="helloworld/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
</classes>
</package>
<package branch-rate="0" complexity="0" line-rate="1" name="helloworld.migrations">
<classes>
<class branch-rate="0" complexity="0" filename="helloworld/migrations/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
</classes>
</package>
<package branch-rate="0" complexity="0" line-rate="1" name="login">
<classes>
<class branch-rate="0" complexity="0" filename="login/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
<class branch-rate="0" complexity="0" filename="login/admin.py" line-rate="1" name="admin.py">
<methods/>
<lines>
<line hits="1" number="1"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="login/models.py" line-rate="1" name="models.py">
<methods/>
<lines>
<line hits="1" number="1"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="login/tests.py" line-rate="1" name="tests.py">
<methods/>
<lines>
<line hits="1" number="1"/>
</lines>
</class>
</classes>
</package>
<package branch-rate="0" complexity="0" line-rate="1" name="login.migrations">
<classes>
<class branch-rate="0" complexity="0" filename="login/migrations/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
</classes>
</package>
<package branch-rate="0" complexity="0" line-rate="1" name="registrasi">
<classes>
<class branch-rate="0" complexity="0" filename="registrasi/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
<class branch-rate="0" complexity="0" filename="registrasi/admin.py" line-rate="1" name="admin.py">
<methods/>
<lines>
<line hits="1" number="1"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="registrasi/models.py" line-rate="1" name="models.py">
<methods/>
<lines>
<line hits="1" number="1"/>
<line hits="1" number="3"/>
<line hits="1" number="4"/>
<line hits="1" number="5"/>
<line hits="1" number="6"/>
<line hits="1" number="7"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="registrasi/tests.py" line-rate="1" name="tests.py">
<methods/>
<lines>
<line hits="1" number="1"/>
<line hits="1" number="2"/>
<line hits="1" number="4"/>
<line hits="1" number="5"/>
<line hits="1" number="6"/>
<line hits="1" number="7"/>
<line hits="1" number="8"/>
<line hits="1" number="10"/>
<line hits="1" number="11"/>
<line hits="1" number="12"/>
<line hits="1" number="13"/>
<line hits="1" number="14"/>
<line hits="1" number="15"/>
<line hits="1" number="16"/>
<line hits="1" number="17"/>
</lines>
</class>
</classes>
</package>
<package branch-rate="0" complexity="0" line-rate="1" name="registrasi.migrations">
<classes>
<class branch-rate="0" complexity="0" filename="registrasi/migrations/0001_initial.py" line-rate="1" name="0001_initial.py">
<methods/>
<lines>
<line hits="1" number="3"/>
<line hits="1" number="6"/>
<line hits="1" number="8"/>
<line hits="1" number="10"/>
<line hits="1" number="13"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="registrasi/migrations/0002_auto_20200225_1655.py" line-rate="1" name="0002_auto_20200225_1655.py">
<methods/>
<lines>
<line hits="1" number="3"/>
<line hits="1" number="6"/>
<line hits="1" number="8"/>
<line hits="1" number="12"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="registrasi/migrations/0003_auto_20200225_1657.py" line-rate="1" name="0003_auto_20200225_1657.py">
<methods/>
<lines>
<line hits="1" number="3"/>
<line hits="1" number="6"/>
<line hits="1" number="8"/>
<line hits="1" number="12"/>
</lines>
</class>
<class branch-rate="0" complexity="0" filename="registrasi/migrations/__init__.py" line-rate="1" name="__init__.py">
<methods/>
<lines/>
</class>
</classes>
</package>
</packages>
</coverage>
......@@ -41,13 +41,14 @@ class Lokasi(models.Model):
alamat = models.CharField(max_length=100)
no_telp = models.CharField(max_length=16)
image = models.ImageField(upload_to="static/img", null=True)
objects = models.Manager()
POINT_FIELD = ""+str(latitude)+","+str(longitude)
def __str__(self):
return self.name
class Fasilitas(models.Model):
objects = models.Manager()
lokasi = models.ForeignKey(Lokasi, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
date_time = models.DateTimeField(auto_now_add=True)
......@@ -60,17 +61,20 @@ class Fasilitas(models.Model):
is_verified = models.BooleanField(default=False)
class Komentar(models.Model):
fasilitas =models.ForeignKey(Fasilitas, on_delete=models.CASCADE)
objects = models.Manager()
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()
class Likes(models.Model):
objects = models.Manager()
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):
objects = models.Manager()
user = models.ForeignKey(User, on_delete=models.CASCADE)
fasilitas = models.ForeignKey(Fasilitas, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
......@@ -5,4 +5,5 @@ from .models import Lokasi
class LokasiSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Lokasi
fields = ('id', 'name', 'latitude', 'longitude', 'alamat', 'no_telp', 'image')
\ No newline at end of file
fields = ('id', 'name', 'latitude', 'longitude', 'alamat', 'no_telp', 'image')
\ No newline at end of file
import json
import tempfile
from http import HTTPStatus
from django.test import TestCase, Client
from django.db.utils import IntegrityError
from django.contrib.auth.models import User
from django.urls import reverse, path, include
from registrasi.models import BisaGoUser
from .models import Lokasi, Fasilitas, Komentar, KURSI_RODA, RUNNING_TEXT, Likes, Dislikes
from .serializers import LokasiSerializer
not_null_constraint_failed_message = 'NOT NULL constraint failed'
class InformasiFasilitasTest(TestCase):
default_username_email = "user_test@gmail.com"
default_last_name = "name"
default_password = "hahagotim"
default_lokasi_name = "Mall"
default_latitude = 0.0
default_longitude = 0.0
default_alamat = "Jl. Raya Bogor no.1 Jakarta"
default_no_telp = "08123456789"
default_image = tempfile.NamedTemporaryFile(suffix=".jpg").name
default_like = 0
default_dislike = 0
default_tag = [KURSI_RODA, RUNNING_TEXT]
default_rating = 3
default_deskripsi = "penjelasan"
user_post = {'name': 'name',
'email': "self.user_post@gmail.com",
'phone_number': 000000000,
'password': "hahagotim"}
lokasi_test_1 = {'name': 'Ma Homie',
'latitude': 0.1,
'longitude': 0.1,
'alamat': 'Jl. Raya Bogor no.2, Jakarta',
'no_telp': '081212123132',
}
def create_user_test(self, username=default_username_email,
last_name=default_last_name,
password=default_password):
user_test = User(username=username,
last_name=last_name,
email=username,
password=password)
user_test.save()
return user_test
def create_lokasi_test(self, name=default_lokasi_name,
latitude=default_latitude,
longitude=default_longitude,
alamat=default_alamat,
no_telp=default_no_telp,
image=default_image):
lokasi_test = Lokasi(name=name,
latitude=latitude,
longitude=longitude,
alamat=alamat,
no_telp=no_telp,
image=image)
lokasi_test.save()
return lokasi_test
def create_fasilitas_test(self, deskripsi=default_deskripsi,
like=default_like,
dislike=default_dislike,
rating=default_rating,
tag=default_tag,
image=default_image,
lokasi=None,
user=None):
if (user == None):
user = self.create_user_test()
if (lokasi == None):
lokasi = self.create_lokasi_test()
fasilitas_test = Fasilitas(lokasi=lokasi,
user=user,
deskripsi=deskripsi,
like=like,
dislike=dislike,
rating=rating,
tag=tag,
image=image)
fasilitas_test.save()
return fasilitas_test
def create_komentar_test(self, deskripsi=default_deskripsi,
user=None,
fasilitas=None):
if (user == None):
user = self.create_user_test()
if (fasilitas == None):
lokasi = self.create_lokasi_test()
fasilitas = self.create_fasilitas_test(user=user, lokasi=lokasi)
komentar_test = Komentar(deskripsi=deskripsi,
user=user,
fasilitas=fasilitas)
komentar_test.save()
return komentar_test
def create_likes_test(self, user=None,
fasilitas=None):
if (user == None):
user = self.create_user_test()
if (fasilitas == None):
lokasi = self.create_lokasi_test(user)
fasilitas = self.create_fasilitas_test(user=user, lokasi=lokasi)
like_test = Likes(user=user,
fasilitas=fasilitas)
like_test.save()
return like_test
def create_dislikes_test(self, user=None,
fasilitas=None):
if (user == None):
user = self.create_user_test()
if (fasilitas == None):
lokasi = self.create_lokasi_test(user)
fasilitas = self.create_fasilitas_test(user=user, lokasi=lokasi)
dislike_test = Dislikes(user=user,
fasilitas=fasilitas)
dislike_test.save()
return dislike_test
def client_user_token(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)
return client
def client_user_token2(self):
Client().post('/api/register/', self.user_post)
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'))
token = content['token']
client = Client(HTTP_AUTHORIZATION='token '+token)
return client
class InformasiFasilitasViewTest(InformasiFasilitasTest):
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'),
self.lokasi_test_1)
import json
import tempfile
from http import HTTPStatus
from django.test import TestCase, Client
from django.db.utils import IntegrityError
from django.contrib.auth.models import User
from django.urls import reverse, path, include
from .test_base import InformasiFasilitasTest
from .models import Lokasi, Fasilitas, Komentar, Likes, Dislikes
from .serializers import LokasiSerializer
NOT_NULL_CONSTRAINT_FAILED_MESSAGE = 'NOT NULL constraint failed'
class InformasiFasilitasModelTest(InformasiFasilitasTest):
def test_models_lokasi_not_created(self):
with self.assertRaises(IntegrityError) as err_message:
obj = Lokasi(name=None)
obj.save()
self.assertTrue(str(err_message.exception).startswith(
NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_lokasi(self):
self.create_lokasi_test()
count = Lokasi.objects.all().count()
self.assertNotEqual(count, 0)
def test_models_lokasi_string(self):
lokasi = self.create_lokasi_test()
self.assertEqual(str(lokasi), lokasi.name)
def test_models_fasilitas_not_created(self):
with self.assertRaises(IntegrityError) as err_message:
obj = Fasilitas(lokasi=None)
obj.save()
self.assertTrue(str(err_message.exception).startswith(
NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_fasilitas(self):
self.create_fasilitas_test()
count = Fasilitas.objects.all().count()
self.assertNotEqual(count, 0)
def test_models_komentar_not_created(self):
with self.assertRaises(IntegrityError) as err_message:
obj = Komentar(fasilitas=None)
obj.save()
self.assertTrue(str(err_message.exception).startswith(
NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_komentar(self):
self.create_komentar_test()
count = Komentar.objects.all().count()
self.assertNotEqual(count, 0)
def test_models_dislikes_not_created(self):
with self.assertRaises(IntegrityError) as err_message:
obj = Dislikes(fasilitas=None)
obj.save()
self.assertTrue(str(err_message.exception).startswith(
NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_dislikes(self):
self.create_dislikes_test()
count = Dislikes.objects.all().count()
self.assertNotEqual(count, 0)
def test_models_likes_not_created(self):
with self.assertRaises(IntegrityError) as err_message:
obj = Likes(fasilitas=None)
obj.save()
self.assertTrue(str(err_message.exception).startswith(
NOT_NULL_CONSTRAINT_FAILED_MESSAGE))
def test_models_create_new_likes(self):
self.create_likes_test()
count = Likes.objects.all().count()
self.assertNotEqual(count, 0)
import json
import tempfile
import copy
from django.utils.http import urlencode
from http import HTTPStatus
from datetime import datetime
from django.test import TestCase, Client
from django.db.utils import IntegrityError
from django.contrib.auth.models import User
from django.urls import reverse, path, include
from .test_base import InformasiFasilitasViewTest
from .models import Lokasi, Fasilitas, Komentar, Likes, Dislikes
from .serializers import LokasiSerializer
class FasilitasRelatedViewTest(InformasiFasilitasViewTest):
def test_can_get_list_fasilitas(self):
self.create_fasilitas_test()
response = Client().get(
reverse('list-fasilitas', kwargs={'nama_lokasi': self.default_lokasi_name}))
self.assertEqual(response.status_code, HTTPStatus.OK)
def test_can_get_list_fasilitas_json(self):
fasilitas = self.create_fasilitas_test()
response = Client().get(
reverse('list-fasilitas', kwargs={'nama_lokasi': self.default_lokasi_name}))
content = json.loads(response.content.decode('utf-8'))
expected_json = {'1': {'id': 1,
'nama_lokasi': self.default_lokasi_name,
'deskripsi': self.default_deskripsi,
'creator': self.default_last_name,