Repository: deis/deis

Issue:
fix(client): parse logs as JSON string
Fixes issue #4657.



Discussion:
Any chance to get this merged? Should I remove the `.PHONY` line? edit: removed it


Resolving patch:
diff --git a/controller/api/views.py b/controller/api/views.py
--- a/controller/api/views.py
+++ b/controller/api/views.py
@@ -224,22 +224,20 @@ def scale(self, request, **kwargs):
     def logs(self, request, **kwargs):
         app = self.get_object()
         try:
-            return Response(app.logs(request.query_params.get('log_lines',
-                                     str(settings.LOG_LINES))),
-                            status=status.HTTP_200_OK, content_type='text/plain')
+            return HttpResponse(app.logs(request.query_params.get('log_lines',
+                                         str(settings.LOG_LINES))),
+                                status=status.HTTP_200_OK, content_type='text/plain')
         except requests.exceptions.RequestException:
-            return Response("Error accessing logs for {}".format(app.id),
-                            status=status.HTTP_500_INTERNAL_SERVER_ERROR,
-                            content_type='text/plain')
-        except EnvironmentError as e:
-            if e.message == 'Error accessing deis-logger':
-                return Response("Error accessing logs for {}".format(app.id),
+            return HttpResponse("Error accessing logs for {}".format(app.id),
                                 status=status.HTTP_500_INTERNAL_SERVER_ERROR,
                                 content_type='text/plain')
+        except EnvironmentError as e:
+            if e.message == 'Error accessing deis-logger':
+                return HttpResponse("Error accessing logs for {}".format(app.id),
+                                    status=status.HTTP_500_INTERNAL_SERVER_ERROR,
+                                    content_type='text/plain')
             else:
-                return Response("No logs for {}".format(app.id),
-                                status=status.HTTP_204_NO_CONTENT,
-                                content_type='text/plain')
+                return HttpResponse(status=status.HTTP_204_NO_CONTENT)
 
     def run(self, request, **kwargs):
         app = self.get_object()


Test patch:
diff --git a/controller/api/tests/test_app.py b/controller/api/tests/test_app.py
--- a/controller/api/tests/test_app.py
+++ b/controller/api/tests/test_app.py
@@ -105,32 +105,30 @@ def test_app_actions(self, mock_get):
         url = "/v1/apps/{app_id}/logs".format(**locals())
         response = self.client.get(url, HTTP_AUTHORIZATION="token {}".format(self.token))
         self.assertEqual(response.status_code, 204)
-        self.assertEqual(response.data, "No logs for {}".format(app_id))
 
         # test logs - 404 from deis-logger
         mock_response.status_code = 404
         response = self.client.get(url, HTTP_AUTHORIZATION="token {}".format(self.token))
         self.assertEqual(response.status_code, 204)
-        self.assertEqual(response.data, "No logs for {}".format(app_id))
 
         # test logs - unanticipated status code from deis-logger
         mock_response.status_code = 400
         response = self.client.get(url, HTTP_AUTHORIZATION="token {}".format(self.token))
         self.assertEqual(response.status_code, 500)
-        self.assertEqual(response.data, "Error accessing logs for {}".format(app_id))
+        self.assertEqual(response.content, "Error accessing logs for {}".format(app_id))
 
         # test logs - success accessing deis-logger
         mock_response.status_code = 200
         mock_response.content = FAKE_LOG_DATA
         response = self.client.get(url, HTTP_AUTHORIZATION="token {}".format(self.token))
         self.assertEqual(response.status_code, 200)
-        self.assertEqual(response.data, FAKE_LOG_DATA)
+        self.assertEqual(response.content, FAKE_LOG_DATA)
 
         # test logs - HTTP request error while accessing deis-logger
         mock_get.side_effect = requests.exceptions.RequestException('Boom!')
         response = self.client.get(url, HTTP_AUTHORIZATION="token {}".format(self.token))
         self.assertEqual(response.status_code, 500)
-        self.assertEqual(response.data, "Error accessing logs for {}".format(app_id))
+        self.assertEqual(response.content, "Error accessing logs for {}".format(app_id))
 
         # TODO: test run needs an initial build