From b6939d4eb19e41261f45806e02e152bdce09d76a Mon Sep 17 00:00:00 2001
From: Arunmozhi <arunmozhi@opencraft.com>
Date: Tue, 17 May 2022 16:27:59 +1000
Subject: [PATCH] refactor: replace getting hostname from to settings.LMS_BASE

The hostname used to construct the resource link ID is moved from using
a runtime attribute to the LMS_BASE setting.
---
 lti_consumer/lti_xblock.py                 | 4 +---
 lti_consumer/tests/unit/test_lti_xblock.py | 4 +++-
 test_settings.py                           | 1 +
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/lti_consumer/lti_xblock.py b/lti_consumer/lti_xblock.py
index 3f60d03..86620af 100644
--- a/lti_consumer/lti_xblock.py
+++ b/lti_consumer/lti_xblock.py
@@ -881,9 +881,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
         i4x-2-3-lti-31de800015cf4afb973356dbe81496df this part of resource_link_id:
         makes resource_link_id to be unique among courses inside same system.
         """
-        return str(urllib.parse.quote(
-            f"{self.runtime.hostname}-{self.location.html_id()}"  # pylint: disable=no-member
-        ))
+        return str(urllib.parse.quote(f"{settings.LMS_BASE}-{self.location.html_id()}"))  # pylint: disable=no-member
 
     @property
     def lis_result_sourcedid(self):
diff --git a/lti_consumer/tests/unit/test_lti_xblock.py b/lti_consumer/tests/unit/test_lti_xblock.py
index 604f3ab..2d3561e 100644
--- a/lti_consumer/tests/unit/test_lti_xblock.py
+++ b/lti_consumer/tests/unit/test_lti_xblock.py
@@ -292,13 +292,15 @@ class TestProperties(TestLtiConsumerXBlock):
         with self.assertRaises(LtiError):
             __ = self.xblock.external_user_id
 
+    @override_settings(LMS_BASE="edx.org")
     def test_resource_link_id(self):
         """
         Test `resource_link_id` returns appropriate string
         """
+        hostname = "edx.org"
         self.assertEqual(
             self.xblock.resource_link_id,
-            f"{self.xblock.runtime.hostname}-{self.xblock.location.html_id()}"  # pylint: disable=no-member
+            f"{hostname}-{self.xblock.location.html_id()}"  # pylint: disable=no-member
         )
 
     @patch('lti_consumer.lti_xblock.LtiConsumerXBlock.context_id')
diff --git a/test_settings.py b/test_settings.py
index c1b33d9..ec88f57 100644
--- a/test_settings.py
+++ b/test_settings.py
@@ -12,6 +12,7 @@ ROOT_URLCONF = 'test_urls'
 
 # LMS Urls - for LTI 1.3 testing
 LMS_ROOT_URL = "https://example.com"
+LMS_BASE = "example.com"
 
 # Dummy FEATURES dict
 FEATURES = {}
-- 
GitLab