Fakultas Ilmu Komputer UI

Commit 2d58d4a5 authored by M. Abdurrahman's avatar M. Abdurrahman
Browse files

Pbi 6 melihat halaman detail fasilitas publik

parent e050a5bc
......@@ -202,8 +202,15 @@ It will return a json with key:
* `no_telp` : Phone number
* `website` : website of the sekolah
* `jumlah_siswa` : number of students
* `status` : status of the sekolah (swasta, negri, or international)
* `jenis_sekolah` : type of sekolah's management (inklusi, segregasi)
* `status` : status of the sekolah
* The options are :
* Swasta = "SW"
* Negri = "NG"
* Internasional = "IT"
* `jenis_sekolah` : type of sekolah's management
* The options are :
* Inklusi = "IK"
* Segregasi = "SG" (Sekolah Luar Biasa)
* `akreditasi` : accreditation
### 15. To register penyandang disabilitas:
......
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'
REGISTER = '/api/register/'
TOKEN_AUTH = '/api-token-auth/'
TOKEN_SUFFIX = 'token '
class InformasiFasilitasTest(TestCase):
default_username_email = "user_test@gmail.com"
......@@ -129,27 +129,27 @@ class InformasiFasilitasTest(TestCase):
return dislike_test
def client_user_token(self):
Client().post('/api/register/', self.user_post)
Client().post(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"],
token_response = Client().post(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 = Client(HTTP_AUTHORIZATION=TOKEN_SUFFIX+token)
return client
def client_user_token2(self):
Client().post('/api/register/', self.user_post)
Client().post(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,
token_response = Client().post(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)
client = Client(HTTP_AUTHORIZATION=TOKEN_SUFFIX+token)
return client
......@@ -161,7 +161,7 @@ class InformasiFasilitasViewTest(InformasiFasilitasTest):
def setUp(self):
email = 'usersetup@gmail.com'
password = 'hahagotim'
Client().post('/api/register/',
Client().post(REGISTER,
{'name': 'name',
'email': email,
'phone_number': 1000000,
......@@ -169,12 +169,12 @@ class InformasiFasilitasViewTest(InformasiFasilitasTest):
test_user = User.objects.get(username=email)
test_user.is_active = True
test_user.save()
token_response = Client().post('/api-token-auth/',
token_response = Client().post(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 = Client(HTTP_AUTHORIZATION=TOKEN_SUFFIX+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'
......
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 django.test import Client
from django.urls import reverse
from .test_base import InformasiFasilitasViewTest
from .models import Lokasi, Fasilitas, Komentar, Likes, Dislikes
from .serializers import LokasiSerializer
PENJELASAN = 'penjelasan fasilitas'
class FasilitasRelatedViewTest(InformasiFasilitasViewTest):
......@@ -85,7 +79,7 @@ class FasilitasRelatedViewTest(InformasiFasilitasViewTest):
self.create_lokasi_test()
urls = reverse('add-fasilitas',
kwargs={'nama_lokasi': self.default_lokasi_name})
response = client.post(urls, {'deskripsi': 'penjelasan fasilitas',
response = client.post(urls, {'deskripsi': PENJELASAN,
'rating': 2,
'tag': 'KR RT'})
self.assertEqual(response.status_code, HTTPStatus.CREATED)
......@@ -100,7 +94,7 @@ class FasilitasRelatedViewTest(InformasiFasilitasViewTest):
def test_post_add_fasilitas_not_found(self):
client = self.client_user_token()
urls = reverse('add-fasilitas', kwargs={'nama_lokasi': 'Mall'})
response = client.post(urls, {'deskripsi': 'penjelasan fasilitas',
response = client.post(urls, {'deskripsi': PENJELASAN,
'rating': 2})
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
......@@ -109,7 +103,7 @@ class FasilitasRelatedViewTest(InformasiFasilitasViewTest):
self.create_lokasi_test()
urls = reverse('add-fasilitas',
kwargs={'nama_lokasi': self.default_lokasi_name})
response = client.post(urls, {'deskripsi': 'penjelasan fasilitas',
response = client.post(urls, {'deskripsi': PENJELASAN,
'rating': 2,
'tag': 'KR RT'})
self.assertEqual(response.status_code, HTTPStatus.UNAUTHORIZED)
......@@ -119,7 +113,7 @@ class FasilitasRelatedViewTest(InformasiFasilitasViewTest):
self.create_lokasi_test()
urls_post = reverse(
'add-fasilitas', kwargs={'nama_lokasi': self.default_lokasi_name})
data_post = {'deskripsi': 'penjelasan fasilitas',
data_post = {'deskripsi': PENJELASAN,
'rating': 2,
'tag': 'KR RT'}
response = client.post(urls_post, data=data_post)
......@@ -133,5 +127,4 @@ class FasilitasRelatedViewTest(InformasiFasilitasViewTest):
'tag': 'KR'}
response = client.put(urls_put, data=send_data,
content_type="multipart/form-data")
response_json = json.loads(response.content.decode("utf-8"))
self.assertEqual(response.status_code, HTTPStatus.ACCEPTED)
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 django.urls import reverse
from .test_base import InformasiFasilitasViewTest
from .models import Lokasi, Fasilitas, Komentar, Likes, Dislikes
from .serializers import LokasiSerializer
from .models import Komentar
COMMENT = "halo saya komen"
class KomentarRelatedViewTest(InformasiFasilitasViewTest):
......@@ -23,7 +17,7 @@ class KomentarRelatedViewTest(InformasiFasilitasViewTest):
kwargs={'nama_lokasi': self.default_lokasi_name,
'id': 1,
})
comment_data = {"deskripsi": "halo saya komen"}
comment_data = {"deskripsi": COMMENT}
client.post(urls, comment_data)
count = Komentar.objects.filter(fasilitas=fasilitas).count()
self.assertEqual(count, 1)
......@@ -35,9 +29,8 @@ class KomentarRelatedViewTest(InformasiFasilitasViewTest):
kwargs={'nama_lokasi': self.default_lokasi_name,
'id': 1,
})
comment_data = {'deskripsi': "halo saya komen"}
comment_data = {'deskripsi': COMMENT}
response = client.post(urls, comment_data)
#print(response.content)
self.assertEqual(response.status_code, HTTPStatus.CREATED)
def test_not_comment_facility_empty(self):
......@@ -71,7 +64,7 @@ class KomentarRelatedViewTest(InformasiFasilitasViewTest):
kwargs={'nama_lokasi': self.default_lokasi_name,
'id': 1,
})
comment_data = {"deskripsi": "halo saya komen"}
comment_data = {"deskripsi": COMMENT}
client.post(urls, comment_data)
urls_get = reverse('list-komentar',
kwargs={'nama_lokasi': self.default_lokasi_name,
......
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 django.urls import reverse
from .test_base import InformasiFasilitasViewTest
from .models import Lokasi, Fasilitas, Komentar, Likes, Dislikes
from .serializers import LokasiSerializer
from .models import Likes, Dislikes
class LikeDislikeRelatedViewTest(InformasiFasilitasViewTest):
......@@ -49,7 +41,7 @@ class LikeDislikeRelatedViewTest(InformasiFasilitasViewTest):
})
response = client.put(urls)
response = client.put(urls) # like and like
self.assertEqual(response.status_code, HTTPStatus.NOT_ACCEPTABLE)
self.assertEqual(response.status_code, HTTPStatus.ACCEPTED)
def test_like_like_facility_response(self):
client = self.client_user_token()
......@@ -130,7 +122,7 @@ class LikeDislikeRelatedViewTest(InformasiFasilitasViewTest):
})
response = client.put(urls)
response = client.put(urls) # Dislike and dislike
self.assertEqual(response.status_code, HTTPStatus.NOT_ACCEPTABLE)
self.assertEqual(response.status_code, HTTPStatus.ACCEPTED)
def test_dislike_dislike_facility_response(self):
client = self.client_user_token()
......
import json
import tempfile
import copy
from django.utils.http import urlencode
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 django.core.files import File
from django.test import Client
from django.urls import reverse
from .test_base import InformasiFasilitasViewTest
from .models import Lokasi, Fasilitas, Komentar, Likes, Dislikes
from .models import Lokasi
from .serializers import LokasiSerializer
......
from http import HTTPStatus
from datetime import datetime
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist
from rest_framework import viewsets
from rest_framework.decorators import api_view, permission_classes, authentication_classes
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated
......@@ -13,6 +11,8 @@ from rest_framework.permissions import IsAuthenticated
from .serializers import LokasiSerializer
from .models import Lokasi, Fasilitas, Komentar, Likes, Dislikes
TIME_FORMAT = "%d-%m-%Y %H:%M:%S"
def missing_key_message(key):
return "Bad Request. {} key is needed".format(key)
......@@ -96,7 +96,7 @@ def list_fasilitas(request, nama_lokasi):
fasilitas_details["deskripsi"] = fasilitas.deskripsi
fasilitas_details["creator"] = fasilitas.user.last_name
fasilitas_details["date_time"] = fasilitas.date_time.strftime(
"%d-%m-%Y %H:%M:%S")
TIME_FORMAT)
fasilitas_details["like"] = fasilitas.like
fasilitas_details["dislike"] = fasilitas.dislike
fasilitas_details["rating"] = fasilitas.rating
......@@ -218,14 +218,14 @@ def update_like_fasilitas(request, nama_lokasi, id, operation):
dislike = None
if operation == "like":
if like != None:
return JsonResponse({'response': "You have already liked this facility"}, status=HTTPStatus.NOT_ACCEPTABLE)
return JsonResponse({'response': "You have already liked this facility"}, status=HTTPStatus.ACCEPTED)
else:
Likes.objects.create(fasilitas=fasilitas, user=user)
if dislike != None:
dislike.delete()
elif operation == "dislike":
if dislike != None:
return JsonResponse({'response': "You have already disliked this facility"}, status=HTTPStatus.NOT_ACCEPTABLE)
return JsonResponse({'response': "You have already disliked this facility"}, status=HTTPStatus.ACCEPTED)
else:
Dislikes.objects.create(fasilitas=fasilitas, user=user)
if like != None:
......@@ -255,7 +255,7 @@ def add_komentar(request, nama_lokasi, id):
deskripsi=deskripsi)
return JsonResponse({'response': 'komentar added',
'id': komentar.id,
"created_date": komentar.date_time.strftime("%d-%m-%Y %H:%M:%S")}, status=HTTPStatus.CREATED)
"created_date": komentar.date_time.strftime(TIME_FORMAT)}, status=HTTPStatus.CREATED)
except KeyError as e:
return JsonResponse({'response': missing_key_message(str(e))}, status=HTTPStatus.BAD_REQUEST)
except Exception as e:
......@@ -279,7 +279,7 @@ def list_komentar(request, nama_lokasi, id):
komentar_details["deskripsi"] = komentar.deskripsi
komentar_details["creator"] = komentar.user.last_name
komentar_details["date_time"] = komentar.date_time.strftime(
"%d-%m-%Y %H:%M:%S")
TIME_FORMAT)
return JsonResponse(return_json, status=HTTPStatus.OK)
except KeyError as key:
return JsonResponse({'response': missing_key_message(str(key))},
......
......@@ -110,4 +110,4 @@ def activate(request, uidb64, token):
else:
return JsonResponse({'response' : request_error_message('get')}, status = status.BAD_REQUEST)
else :
return JsonResponse({'response' : request_error_message("get")}, status = BAD_REQUEST)
return JsonResponse({'response' : request_error_message("get")}, status = status.BAD_REQUEST)
argon2-cffi==19.2.0
astroid==2.0.4
astroid==2.4.0
cachetools==4.0.0
certifi==2018.8.24
cffi==1.14.0
......@@ -23,7 +23,7 @@ gunicorn==19.7.1
httplib2==0.17.0
idna==2.6
isort==4.2.15
lazy-object-proxy==1.3.1
lazy-object-proxy==1.4.3
mccabe==0.6.1
oauthlib==3.1.0
Pillow==7.0.0
......@@ -42,11 +42,11 @@ requests-oauthlib==1.3.0
rsa==4.0
selenium==3.5.0
setuptools==40.8.0
six==1.10.0
six==1.12.0
social-auth-app-django==3.1.0
social-auth-core==3.2.0
typed-ast==1.1.0
typed-ast==1.4.1
uritemplate==3.0.1
urllib3==1.22
whitenoise==3.3.0
wrapt==1.10.11
\ No newline at end of file
wrapt==1.12.1
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment