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
2021
Kelas D
PT Gizi Sehat - Dietela
Dietela Backend
Commits
f0842edf
Commit
f0842edf
authored
May 11, 2021
by
Glenda Emanuella Sutanto
Browse files
Filtered get all diet recommendation request by token
parent
7e768657
Changes
2
Hide whitespace changes
Inline
Side-by-side
profile_dietku/tests.py
View file @
f0842edf
...
@@ -203,6 +203,8 @@ class GetProfilesTest(APITestCase):
...
@@ -203,6 +203,8 @@ class GetProfilesTest(APITestCase):
class
DietRecommendationTests
(
APITestCase
):
class
DietRecommendationTests
(
APITestCase
):
client
=
APIClient
()
@
classmethod
@
classmethod
def
setUpTestData
(
cls
):
def
setUpTestData
(
cls
):
cls
.
BASE_URL
=
"/diet-recommendation/"
cls
.
BASE_URL
=
"/diet-recommendation/"
...
@@ -239,6 +241,16 @@ class DietRecommendationTests(APITestCase):
...
@@ -239,6 +241,16 @@ class DietRecommendationTests(APITestCase):
cls
.
SPECIFIC_URL
=
f
"
{
cls
.
BASE_URL
}{
cls
.
diet_recommendation
.
id
}
/"
cls
.
SPECIFIC_URL
=
f
"
{
cls
.
BASE_URL
}{
cls
.
diet_recommendation
.
id
}
/"
cls
.
login_data
=
{
'email'
:
'email2@email.com'
,
'password'
:
'abc'
,
'role'
:
'client'
,
}
cls
.
login_response
=
cls
.
client
.
post
(
'/auth/user-login/'
,
cls
.
login_data
,
format
=
'json'
)
cls
.
json_login_response
=
json
.
loads
(
cls
.
login_response
.
content
)
cls
.
login_credentials
=
"Bearer "
+
cls
.
json_login_response
[
'access_token'
]
def
test_string_representation
(
self
):
def
test_string_representation
(
self
):
self
.
assertEqual
(
str
(
self
.
diet_recommendation
),
'email2@email.com - Test, S.Gz'
)
self
.
assertEqual
(
str
(
self
.
diet_recommendation
),
'email2@email.com - Test, S.Gz'
)
...
@@ -275,6 +287,7 @@ class DietRecommendationTests(APITestCase):
...
@@ -275,6 +287,7 @@ class DietRecommendationTests(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_get_all_diet_recommendation
(
self
):
def
test_get_all_diet_recommendation
(
self
):
self
.
client
.
credentials
(
HTTP_AUTHORIZATION
=
self
.
login_credentials
)
response
=
self
.
client
.
get
(
self
.
BASE_URL
)
response
=
self
.
client
.
get
(
self
.
BASE_URL
)
json_response
=
json
.
loads
(
response
.
content
)
json_response
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
len
(
json_response
),
1
)
self
.
assertEqual
(
len
(
json_response
),
1
)
...
...
profile_dietku/views.py
View file @
f0842edf
...
@@ -46,3 +46,9 @@ class GetProfilesViewSet(generics.ListAPIView):
...
@@ -46,3 +46,9 @@ class GetProfilesViewSet(generics.ListAPIView):
class
DietRecommendationViewSet
(
viewsets
.
ModelViewSet
):
class
DietRecommendationViewSet
(
viewsets
.
ModelViewSet
):
serializer_class
=
DietRecommendationSerializer
serializer_class
=
DietRecommendationSerializer
queryset
=
DietRecommendation
.
objects
.
all
()
queryset
=
DietRecommendation
.
objects
.
all
()
def
list
(
self
,
request
):
instances
=
self
.
get_queryset
().
filter
(
client
=
request
.
user
)
serializer
=
DietRecommendationSerializer
(
instances
,
many
=
True
)
return
Response
(
serializer
.
data
,
status
=
status
.
HTTP_200_OK
)
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