Stop showing hitting enterprise API in case of 404 error
Stop showing hitting enterprise API when request is originated as result of 404 error. fixed quality violations Removed line break add unit tests Updated test docstring
This commit is contained in:
@@ -94,6 +94,7 @@ def render_press_release(request, slug):
|
||||
|
||||
@fix_crum_request
|
||||
def render_404(request, exception):
|
||||
request.view_name = '404'
|
||||
return HttpResponseNotFound(render_to_string('static_templates/404.html', {}, request=request))
|
||||
|
||||
|
||||
|
||||
46
openedx/features/enterprise_support/tests/test_utils.py
Normal file
46
openedx/features/enterprise_support/tests/test_utils.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Test the enterprise support utils.
|
||||
"""
|
||||
|
||||
|
||||
import mock
|
||||
import ddt
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from openedx.features.enterprise_support.tests import FEATURES_WITH_ENTERPRISE_ENABLED
|
||||
from student.tests.factories import UserFactory
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
@override_settings(FEATURES=FEATURES_WITH_ENTERPRISE_ENABLED)
|
||||
@skip_unless_lms
|
||||
class TestEnterpriseUtils(TestCase):
|
||||
"""
|
||||
Test enterprise support utils.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.user = UserFactory.create(password='password')
|
||||
super(TestEnterpriseUtils, cls).setUpTestData()
|
||||
|
||||
@ddt.data(
|
||||
('notfoundpage', 0),
|
||||
(reverse('dashboard'), 1),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_enterprise_customer_for_request_called_on_404(self, resource, expected_calls):
|
||||
"""
|
||||
Test enterprise customer API is not called from 404 page
|
||||
"""
|
||||
self.client.login(username=self.user.username, password='password')
|
||||
|
||||
with mock.patch(
|
||||
'openedx.features.enterprise_support.api.enterprise_customer_for_request'
|
||||
) as mock_customer_request:
|
||||
self.client.get(resource)
|
||||
self.assertEqual(mock_customer_request.call_count, expected_calls)
|
||||
@@ -316,6 +316,11 @@ def get_enterprise_learner_generic_name(request):
|
||||
"""
|
||||
# Prevent a circular import. This function makes sense to be in this module though. And see function description.
|
||||
from openedx.features.enterprise_support.api import enterprise_customer_for_request
|
||||
|
||||
# ENT-2626: For 404 pages we don't need to perform these actions.
|
||||
if getattr(request, 'view_name', None) == '404':
|
||||
return
|
||||
|
||||
enterprise_customer = enterprise_customer_for_request(request)
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user