Skip to content

Commit

Permalink
fix: DiscussionsConfigurations admin error
Browse files Browse the repository at this point in the history
  • Loading branch information
Anas12091101 authored and pdpinch committed Jul 22, 2024
1 parent 475b49c commit 8f7496d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions openedx/core/djangoapps/discussions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
"""
Expand Down
32 changes: 32 additions & 0 deletions openedx/core/djangoapps/discussions/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 8f7496d

Please sign in to comment.