def test_is_feature_enabled(self):
        request = RequestFactory().get('/')
        request.user = AnonymousUser()

        # Return True if no switch or flag are provided
        self.assertTrue(
            utils.is_feature_enabled({
                'switch': None,
                'flag': None
            }, request))

        name = 'test-waffle'
        item = {'switch': 'test-waffle'}
        # Return False if switch inactive
        with override_switch(name, active=False):
            self.assertFalse(utils.is_feature_enabled(item, request))

        # Return True if switch active
        with override_switch(name, active=True):
            self.assertTrue(utils.is_feature_enabled(item, request))

        item = {'flag': 'test-waffle'}
        # Return False if flag inactive
        with override_flag(name, active=False):
            self.assertFalse(utils.is_feature_enabled(item, request))

        # Return True if flag active
        with override_flag(name, active=True):
            self.assertTrue(utils.is_feature_enabled(item, request))
Пример #2
0
    def get_primary_nav_items(self, request):
        """
        Return the primary nav items.
        """

        items = [{
            'name': 'enrollment',
            'text': ugettext_noop('Enrollment'),
            'view': 'courses:enrollment:activity',
            'icon': 'fa-child',
            'fragment': '',
            'scope': 'course',
            'lens': 'enrollment',
            'report': 'activity',
            'depth': ''
        }, {
            'name': 'engagement',
            'text': ugettext_noop('Engagement'),
            'view': 'courses:engagement:content',
            'icon': 'fa-bar-chart',
            'fragment': '',
            'scope': 'course',
            'lens': 'engagement',
            'report': 'content',
            'depth': ''
        }, {
            'name': 'performance',
            'text': ugettext_noop('Performance'),
            'view': 'courses:performance:graded_content',
            'icon': 'fa-check-square-o',
            'switch': 'enable_course_api',
            'fragment': '',
            'scope': 'course',
            'lens': 'performance',
            'report': 'graded',
            'depth': ''
        }, {
            'name': 'learners',
            'text': ugettext_noop('Learners'),
            'view': 'courses:learners:learners',
            'icon': 'fa-users',
            'flag': 'display_learner_analytics',
            'fragment': '#?ignore_segments=inactive',
            'scope': 'course',
            'lens': 'learners',
            'report': 'roster',
            'depth': ''
        }]

        translate_dict_values(items, ('text', ))

        # Remove disabled items
        items = [item for item in items if is_feature_enabled(item, request)]

        # Clean each item
        list(map(self.clean_item, items))

        return items
Пример #3
0
    def _build_nav_items(self, nav_items, active_item, request):
        # Deep copy the list since it is a list of dictionaries
        items = copy.deepcopy(nav_items)

        # Process only the nav items that are enabled
        items = [item for item in items if is_feature_enabled(item, request)]

        for item in items:
            item['active'] = active_item == item['name']
            self.clean_item(item)

        return items