Fakultas Ilmu Komputer UI

Commit 12e71ce1 authored by Ami's avatar Ami
Browse files

resolve latest merge conflict with staging

parents 2635df36 f53e05f6
Pipeline #76418 passed with stages
in 11 minutes and 19 seconds
......@@ -236,6 +236,8 @@ class GetProfilesAndCSVTest(APITestCase):
class DietRecommendationTests(APITestCase):
client = APIClient()
@classmethod
def setUpTestData(cls):
cls.BASE_URL = "/diet-recommendation/"
......@@ -272,6 +274,16 @@ class DietRecommendationTests(APITestCase):
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):
self.assertEqual(str(self.diet_recommendation), 'email2@email.com - Test, S.Gz')
......@@ -308,6 +320,7 @@ class DietRecommendationTests(APITestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_get_all_diet_recommendation(self):
self.client.credentials(HTTP_AUTHORIZATION=self.login_credentials)
response = self.client.get(self.BASE_URL)
json_response = json.loads(response.content)
self.assertEqual(len(json_response), 1)
......
......@@ -53,6 +53,12 @@ class DietRecommendationViewSet(viewsets.ModelViewSet):
serializer_class = DietRecommendationSerializer
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)
class ExportCSVTimDietela(APIView):
def get(self, request):
response = HttpResponse(content_type='text/csv')
......
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