From 8f7496d00e33f86d1abcb3eaf901689782378107 Mon Sep 17 00:00:00 2001 From: Muhammad Anas Date: Mon, 8 Jul 2024 14:23:19 +0000 Subject: [PATCH] fix: DiscussionsConfigurations admin error --- openedx/core/djangoapps/discussions/admin.py | 4 +++ .../discussions/tests/test_admin.py | 32 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 openedx/core/djangoapps/discussions/tests/test_admin.py diff --git a/openedx/core/djangoapps/discussions/admin.py b/openedx/core/djangoapps/discussions/admin.py index eb61942abf2a..810f57e95226 100644 --- a/openedx/core/djangoapps/discussions/admin.py +++ b/openedx/core/djangoapps/discussions/admin.py @@ -3,6 +3,7 @@ """ from django.contrib import admin from django.contrib.admin import SimpleListFilter +from django.contrib.admin.utils import quote from simple_history.admin import SimpleHistoryAdmin from openedx.core.djangoapps.config_model_utils.admin import StackedConfigModelAdmin @@ -26,6 +27,9 @@ class DiscussionsConfigurationAdmin(SimpleHistoryAdmin): 'provider_type', ) + def change_view(self, request, object_id=None, form_url="", extra_context=None): + return super().change_view(request, quote(object_id), form_url, extra_context) + class AllowListFilter(SimpleListFilter): """ diff --git a/openedx/core/djangoapps/discussions/tests/test_admin.py b/openedx/core/djangoapps/discussions/tests/test_admin.py new file mode 100644 index 000000000000..d16d73dd8bef --- /dev/null +++ b/openedx/core/djangoapps/discussions/tests/test_admin.py @@ -0,0 +1,32 @@ +""" +Tests for DiscussionsConfiguration admin view +""" +from django.test import TestCase +from django.urls import reverse + +from common.djangoapps.student.tests.factories import UserFactory +from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider + + +class DiscussionsConfigurationAdminTest(TestCase): + """ + Tests for discussion config admin + """ + def setUp(self): + super().setUp() + self.superuser = UserFactory(is_staff=True, is_superuser=True) + self.client.login(username=self.superuser.username, password="Password1234") + + def test_change_view(self): + """ + Test that the DiscussionAdmin's change_view processes the context_key correctly and returns a successful + response. + """ + discussion_config = DiscussionsConfiguration.objects.create( + context_key='course-v1:test+test+06_25_2024', + provider_type=Provider.OPEN_EDX, + ) + url = reverse('admin:discussions_discussionsconfiguration_change', args=[discussion_config.context_key]) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertContains(response, 'course-v1:test+test+06_25_2024')