diff --git a/openedx/core/djangoapps/waffle_utils/tests/test_views.py b/openedx/core/djangoapps/waffle_utils/tests/test_views.py index f6396a95d2..de47e17d02 100644 --- a/openedx/core/djangoapps/waffle_utils/tests/test_views.py +++ b/openedx/core/djangoapps/waffle_utils/tests/test_views.py @@ -2,14 +2,16 @@ Tests for waffle utils views. """ from django.test import TestCase +from edx_django_utils.monitoring.code_owner import utils as code_owner_utils +from mock import patch from rest_framework.test import APIRequestFactory from waffle.testutils import override_switch from student.tests.factories import UserFactory from .. import WaffleFlag, WaffleFlagNamespace, WaffleSwitch, WaffleSwitchNamespace -from ..views import ToggleStateView from ..testutils import override_waffle_flag +from ..views import ToggleStateView TEST_WAFFLE_FLAG_NAMESPACE = WaffleFlagNamespace('test') TEST_WAFFLE_FLAG = WaffleFlag(TEST_WAFFLE_FLAG_NAMESPACE, 'flag', __name__) @@ -45,6 +47,17 @@ class ToggleStateViewTests(TestCase): # This is no longer the first switch #self.assertEqual(response.data['waffle_switches'][0]['name'], 'test.switch') + def test_code_owners_without_module_information(self): + # Create a waffle flag without any associated module_name + waffle_flag = WaffleFlag(TEST_WAFFLE_FLAG_NAMESPACE, "flag2", module_name=None) + with patch.object(code_owner_utils, "get_code_owner_mappings", return_value={}): + response = self._get_toggle_state_response(is_staff=True) + + result = [ + flag for flag in response.data["waffle_flags"] if flag["name"] == waffle_flag.name + ][0] + self.assertNotIn("code_owner", result) + def _get_toggle_state_response(self, is_staff=True): request = APIRequestFactory().get('/api/toggles/state/') user = UserFactory() diff --git a/openedx/core/djangoapps/waffle_utils/views.py b/openedx/core/djangoapps/waffle_utils/views.py index 64ea31fcb4..2ce629a62e 100644 --- a/openedx/core/djangoapps/waffle_utils/views.py +++ b/openedx/core/djangoapps/waffle_utils/views.py @@ -2,13 +2,13 @@ Views that we will use to view toggle state in edx-platform. """ from collections import OrderedDict -from django.conf import settings -from edx_django_utils.monitoring.code_owner.utils import get_code_owner_from_module, is_code_owner_mappings_configured +from django.conf import settings +from edx_django_utils.monitoring import get_code_owner_from_module from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.permissions import IsStaff -from rest_framework.authentication import SessionAuthentication from rest_framework import permissions, views +from rest_framework.authentication import SessionAuthentication from rest_framework.response import Response from waffle.models import Flag, Switch @@ -107,7 +107,7 @@ class ToggleStateView(views.APIView): """ toggle['class'] = toggle_instance.__class__.__name__ toggle['module'] = toggle_instance.module_name - if is_code_owner_mappings_configured(): + if toggle_instance.module_name: code_owner = get_code_owner_from_module(toggle_instance.module_name) if code_owner: toggle['code_owner'] = code_owner