Fakultas Ilmu Komputer UI
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ppl-fasilkom-ui
2020
PPL-C
DTB-Layanan Fasilitas Publik Penyandang Disabilitas
PoiPoLeGan-PPLapanganTembak-DTB Layanan Fasilitas Publik Penyandang Disabilitas-BE
Commits
68fa019d
Commit
68fa019d
authored
Apr 21, 2020
by
M. Abdurrahman
Browse files
[GREEN] add not found tests for informasi_fasilitas views and slight refactor
parent
405f0582
Pipeline
#42182
passed with stages
in 3 minutes and 38 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
informasi_fasilitas/tests.py
View file @
68fa019d
...
...
@@ -133,7 +133,7 @@ class InformasiFasilitasViewTest(TestCase):
def
test_LokasiSerializer_valid
(
self
):
serializer
=
LokasiSerializer
(
data
=
{
'name'
:
'Mall'
,
'name'
:
'Mall
1
'
,
'latitude'
:
0.0
,
'longitude'
:
0.0
,
'alamat'
:
'Jl. Raya Bogor no.1, Jakarta'
,
...
...
@@ -177,6 +177,10 @@ class InformasiFasilitasViewTest(TestCase):
response
=
Client
().
post
(
reverse
(
'lokasi-details'
,
kwargs
=
{
'name'
:
'Mall'
}))
self
.
assertEqual
(
response
.
status_code
,
405
)
def
test_get_lokasi_details_not_found
(
self
):
response
=
Client
().
get
(
reverse
(
'lokasi-details'
,
kwargs
=
{
'name'
:
'Mall'
}))
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_can_post_add_lokasi
(
self
):
email
=
'user@gmail.com'
password
=
'hahagotim'
...
...
@@ -218,6 +222,13 @@ class InformasiFasilitasViewTest(TestCase):
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
.
save
()
lokasi
=
Lokasi
(
name
=
'Mall'
,
latitude
=
0.0
,
...
...
@@ -227,6 +238,17 @@ class InformasiFasilitasViewTest(TestCase):
image
=
image
)
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
()
response
=
Client
().
get
(
reverse
(
'list-fasilitas'
,
kwargs
=
{
'nama_lokasi'
:
'Mall'
}))
self
.
assertEqual
(
response
.
status_code
,
200
)
...
...
@@ -244,6 +266,10 @@ class InformasiFasilitasViewTest(TestCase):
response
=
Client
().
post
(
reverse
(
'list-fasilitas'
,
kwargs
=
{
'nama_lokasi'
:
'Mall'
}))
self
.
assertEqual
(
response
.
status_code
,
405
)
def
test_get_list_fasilitas_not_found
(
self
):
response
=
Client
().
get
(
reverse
(
'list-fasilitas'
,
kwargs
=
{
'nama_lokasi'
:
'Mall'
}))
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_can_get_detail_fasilitas
(
self
):
image
=
tempfile
.
NamedTemporaryFile
(
suffix
=
".jpg"
).
name
user
=
User
(
...
...
@@ -277,7 +303,7 @@ class InformasiFasilitasViewTest(TestCase):
response
=
Client
().
get
(
reverse
(
'detail-fasilitas'
,
kwargs
=
{
'nama_lokasi'
:
'Mall'
,
'id'
:
id
}))
self
.
assertEqual
(
response
.
status_code
,
200
)
def
test_cannot_post_
lokasi_detail
s
(
self
):
def
test_cannot_post_
detail_fasilita
s
(
self
):
image
=
tempfile
.
NamedTemporaryFile
(
suffix
=
".jpg"
).
name
user
=
User
(
username
=
'user@gmail.com'
,
...
...
@@ -310,9 +336,9 @@ class InformasiFasilitasViewTest(TestCase):
response
=
Client
().
post
(
reverse
(
'detail-fasilitas'
,
kwargs
=
{
'nama_lokasi'
:
'Mall'
,
'id'
:
id
}))
self
.
assertEqual
(
response
.
status_code
,
405
)
#=======
def
test_get_detail_fasilitas_not_found
(
self
):
response
=
Client
().
get
(
reverse
(
'detail-fasilitas'
,
kwargs
=
{
'nama_lokasi'
:
'Mall'
,
'id'
:
0
}))
self
.
assertEqual
(
response
.
status_code
,
404
)
def
test_can_post_add_fasilitas
(
self
):
email
=
'user@gmail.com'
...
...
@@ -370,4 +396,23 @@ class InformasiFasilitasViewTest(TestCase):
lokasi
.
save
()
response
=
client
.
get
(
reverse
(
'add-fasilitas'
,
kwargs
=
{
'nama_lokasi'
:
'Mall'
}))
self
.
assertEqual
(
response
.
status_code
,
405
)
\ No newline at end of file
self
.
assertEqual
(
response
.
status_code
,
405
)
def
test_post_add_fasilitas_not_found
(
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-fasilitas'
,
kwargs
=
{
'nama_lokasi'
:
'Mall'
}),
{
'deskripsi'
:
'penjelasan fasilitas'
,
'rating'
:
2
})
self
.
assertEqual
(
response
.
status_code
,
404
)
\ No newline at end of file
informasi_fasilitas/views.py
View file @
68fa019d
...
...
@@ -91,7 +91,7 @@ def list_fasilitas(request, nama_lokasi):
except
KeyError
as
e
:
return
JsonResponse
({
'response'
:
missing_key_message
(
str
(
e
))},
status
=
500
)
except
Exception
as
e
:
return
JsonResponse
({
'response'
:
str
(
e
)})
return
JsonResponse
({
'response'
:
str
(
e
)}
,
status
=
404
)
@
api_view
([
'POST'
])
@
authentication_classes
([
TokenAuthentication
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment