Fakultas Ilmu Komputer UI

Commit b3ff9443 authored by Glenda Emanuella Sutanto's avatar Glenda Emanuella Sutanto
Browse files

[REFACTOR] Made non-existent value in response as a null + removed unused variable

parent 26e9b031
Pipeline #76240 passed with stages
in 10 minutes and 59 seconds
......@@ -18,7 +18,6 @@ class GetProfilesTest(APITestCase):
@classmethod
def setUpTestData(cls):
cls.BASE_URL = "/profiles/"
cls.SPECIFIC_URL = "/profiles/?nutritionist=1"
cls.diet_profile_1 = DietProfile.objects.create(
name="test",
......@@ -134,11 +133,11 @@ class GetProfilesTest(APITestCase):
expected_response.append({
'user': CustomUserDetailsSerializer(user).data,
'diet_profile_id': user.diet_profile.id \
if user.diet_profile is not None else '-',
if user.diet_profile is not None else None,
'diet_questionnaire_id': user.diet_questionnaire.id \
if hasattr(user, 'diet_questionnaire') else '-',
if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else '-'
if hasattr(user, 'diet_recommendation') else None
})
self.assertEqual(response.data, expected_response)
self.assertEqual(response.status_code, status.HTTP_200_OK)
......@@ -163,11 +162,11 @@ class GetProfilesTest(APITestCase):
expected_response.append({
'user': CustomUserDetailsSerializer(user).data,
'diet_profile_id': user.diet_profile.id \
if user.diet_profile is not None else '-',
if user.diet_profile is not None else None,
'diet_questionnaire_id': user.diet_questionnaire.id \
if hasattr(user, 'diet_questionnaire') else '-',
if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else '-'
if hasattr(user, 'diet_recommendation') else None
})
self.assertEqual(response.data, expected_response)
self.assertEqual(response.status_code, status.HTTP_200_OK)
......@@ -192,11 +191,11 @@ class GetProfilesTest(APITestCase):
expected_response.append({
'user': CustomUserDetailsSerializer(user).data,
'diet_profile_id': user.diet_profile.id \
if user.diet_profile is not None else '-',
if user.diet_profile is not None else None,
'diet_questionnaire_id': user.diet_questionnaire.id \
if hasattr(user, 'diet_questionnaire') else '-',
if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else '-'
if hasattr(user, 'diet_recommendation') else None
})
self.assertEqual(response.data, expected_response)
self.assertEqual(response.status_code, status.HTTP_200_OK)
......
......@@ -34,11 +34,11 @@ class GetProfilesViewSet(generics.ListAPIView):
response.append({
'user': CustomUserDetailsSerializer(user).data,
'diet_profile_id': user.diet_profile.id \
if user.diet_profile is not None else '-',
if user.diet_profile is not None else None,
'diet_questionnaire_id': user.diet_questionnaire.id \
if hasattr(user, 'diet_questionnaire') else '-',
if hasattr(user, 'diet_questionnaire') else None,
'diet_recommendation_id': user.diet_recommendation.id \
if hasattr(user, 'diet_recommendation') else '-'
if hasattr(user, 'diet_recommendation') else None
})
return Response(response, status=status.HTTP_200_OK)
......
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