From 58dbb18c97919c1dc4436666925fb98372307af9 Mon Sep 17 00:00:00 2001
From: Ned Batchelder <ned@nedbatchelder.com>
Date: Fri, 19 Mar 2021 10:42:14 -0400
Subject: [PATCH] fix: show the configuration as nicely formatted JSON (#149)

---
 lti_consumer/api.py                             | 5 ++++-
 lti_consumer/templates/html/lti_1p3_studio.html | 4 +---
 lti_consumer/tests/unit/test_api.py             | 6 +++---
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/lti_consumer/api.py b/lti_consumer/api.py
index 4a83181..462e9ad 100644
--- a/lti_consumer/api.py
+++ b/lti_consumer/api.py
@@ -4,6 +4,9 @@ Python APIs used to handle LTI configuration and launches.
 Some methods are meant to be used inside the XBlock, so they
 return plaintext to allow easy testing/mocking.
 """
+
+import json
+
 from .exceptions import LtiError
 from .models import LtiConfiguration, LtiDlContentItem
 from .utils import (
@@ -109,7 +112,7 @@ def get_lti_1p3_launch_info(config_id=None, block=None):
         'oidc_callback': get_lms_lti_launch_link(),
         'token_url': get_lms_lti_access_token_link(lti_config.location),
         'deep_linking_launch_url': deep_linking_launch_url,
-        'deep_linking_content_items': deep_linking_content_items,
+        'deep_linking_content_items': json.dumps(deep_linking_content_items, indent=4),
     }
 
 
diff --git a/lti_consumer/templates/html/lti_1p3_studio.html b/lti_consumer/templates/html/lti_1p3_studio.html
index 820c378..84d5702 100644
--- a/lti_consumer/templates/html/lti_1p3_studio.html
+++ b/lti_consumer/templates/html/lti_1p3_studio.html
@@ -39,9 +39,7 @@
             <b>{% trans "Deep Linking is configured on this tool." %}</b>
             {% trans "The Deep Linking configuration stored is presented below:" %}
         </p>
-        <code>
-            {{ deep_linking_content_items }}
-        </code>
+        <pre>{{ deep_linking_content_items }}</pre>
 
         <p>
             {% trans "If you run deep linking again, the content above will be replaced." %}
diff --git a/lti_consumer/tests/unit/test_api.py b/lti_consumer/tests/unit/test_api.py
index 64af91f..bf7b0de 100644
--- a/lti_consumer/tests/unit/test_api.py
+++ b/lti_consumer/tests/unit/test_api.py
@@ -231,9 +231,9 @@ class TestGetLti1p3LaunchInfo(TestCase):
                     lti_config.location
                 ),
                 'deep_linking_launch_url': 'http://example.com',
-                'deep_linking_content_items': [{
-                    "test": "this is a test attribute",
-                }]
+
+                'deep_linking_content_items':
+                    '[\n    {\n        "test": "this is a test attribute"\n    }\n]',
             }
         )
 
-- 
GitLab