Пример #1
0
    def test_breadcrumbs_active_in_other_menu(self):
        request = self.factory.get('/a/')
        menu = {
            'label':
            'Menu',
            'slug':
            'menu',
            'order':
            0,
            'login_required':
            True,
            'children': [
                {
                    'label': 'A',
                    'slug': 'a',
                    'link': '/a/',
                    'order': 0,
                },
            ]
        }

        MenuItem.from_json(json.dumps(menu))

        context = {
            'user': self.superuser,
            'request': request,
        }

        res = lineup_breadcrumbs(context, 'main-menu')

        self.assertEqual(res['items'], [])
Пример #2
0
 def test_from_json_unsupported_json_data(self):
     try:
         invalid_json = self.menu.copy()
         MenuItem.from_json(json.dumps([invalid_json, invalid_json]))
         self.fail()
     except exceptions.UnsupportedJsonData:
         pass
Пример #3
0
 def test_from_json_invalid_json(self):
     try:
         invalid_json = "{\"key\" = \"prop\"}"
         MenuItem.from_json(invalid_json)
         self.fail()
     except exceptions.InvalidJson:
         pass
Пример #4
0
 def test_from_json_missing_json_prop(self):
     try:
         invalid_json = self.menu.copy()
         invalid_json.pop('children')
         invalid_json.pop('slug')
         MenuItem.from_json(json.dumps(invalid_json))
         self.fail()
     except exceptions.MissingJsonRequiredProp:
         pass
Пример #5
0
    def handle(self, *args, **options):
        path = options['json_path']
        if not os.path.isfile(path):
            raise CommandError('File %s does not exist' % path)

        # read file
        with open(path, 'r') as json_file:
            json_data = json_file.read()

        if json_data:
            try:
                MenuItem.from_json(json_data)
                self.stdout.write(self.style.SUCCESS('Successfully imported menu'))
            except Exception as e:
                raise CommandError('Cannot import menu: %s' % str(e))
        else:
            raise CommandError('File %s is empty' % path)
Пример #6
0
    def test_lineup_menu_login_required(self):
        menu = {
            'label': 'Menu',
            'slug': 'menu',
            'order': 0,
            'login_required': True,
            'children': [
                {
                    'label': 'A',
                    'slug': 'a',
                    'order': 0,
                },
            ]
        }

        MenuItem.from_json(json.dumps(menu))

        out = Template("{% load lineup_tags %}"
                       "{% lineup_menu 'menu' %}").render(
                           Context({'user': AnonymousUser()}))
        self.assertEqual(out, '\n\n')
Пример #7
0
    def test_lineup_disabled_menu(self):
        menu = {
            'label': 'Menu',
            'slug': 'menu',
            'order': 0,
            'enabled': False,
            'children': [
                {
                    'label': 'A',
                    'slug': 'a',
                    'order': 0,
                },
            ]
        }

        MenuItem.from_json(json.dumps(menu))

        out = Template("{% load lineup_tags %}"
                       "{% lineup_menu 'menu' %}").render(
                           Context({'user': self.user}))
        self.assertEqual(out, '\n\n')
Пример #8
0
    def setUp(self):
        self.factory = RequestFactory()
        self.menu = {
            'label':
            'Root',
            'slug':
            'main-menu',
            'order':
            0,
            'children': [{
                'label': 'Tools',
                'slug': 'tools',
                'order': 0,
            }, {
                'label':
                'Disabled Item',
                'slug':
                'disabled-item',
                'order':
                1,
                'enabled':
                False,
                'children': [{
                    'label': 'Disabled child',
                    'slug': 'disabled-child',
                    'order': 0,
                }]
            }, {
                'label': 'Perm Item',
                'slug': 'perm-item',
                'order': 2,
                'permissions': ['add_permission', 'view_session']
            }]
        }

        self.tree = MenuItem.from_json(json.dumps(self.menu))
Пример #9
0
    def setUp(self):
        self.factory = RequestFactory()
        self.superuser = User.objects.create(
            username='******',
            password='******',
            email='*****@*****.**',
            is_superuser=True,
        )
        self.user = User.objects.create(
            username='******',
            password='******',
            email='*****@*****.**',
        )

        # [(10, 'change_group'), (5, 'add_permission'), (8, 'view_permission'), (24, 'view_session')]
        self.permissions = Permission.objects.filter(id__in=[5, 8, 10, 24])
        self.user.user_permissions.add(self.permissions[0])
        self.user.user_permissions.add(self.permissions[2])

        group = Group.objects.create(name='dev')
        group.permissions.add(self.permissions[1])
        group.permissions.add(self.permissions[3])

        self.user.groups.add(group)

        self.wrong_perm_user = User.objects.create(
            username='******',
            password='******',
            email='*****@*****.**',
        )
        self.wrong_perm_user.user_permissions.add(self.permissions[2])

        self.menu = {
            'label':
            'Root',
            'slug':
            'main-menu',
            'order':
            0,
            'children': [{
                'label':
                'Tools',
                'slug':
                'tools',
                'order':
                0,
                'children': [{
                    'label':
                    'DNS Tools',
                    'slug':
                    'dns-tools',
                    'order':
                    0,
                    'login_required':
                    True,
                    'children': [{
                        'label': 'DMARC DNS Tools',
                        'slug': 'dmarc-dns-tools',
                        'link': '/dmarc-tools/',
                        'title': 'DMARC Rulez',
                        'order': 0,
                    }]
                }, {
                    'label': 'Password Generator',
                    'slug': 'password-generator',
                    'order': 1,
                }]
            }, {
                'label':
                'Disabled Item',
                'slug':
                'disabled-item',
                'order':
                1,
                'enabled':
                False,
                'children': [{
                    'label': 'Disabled child',
                    'slug': 'disabled-child',
                    'order': 0,
                }]
            }, {
                'label': 'Perm Item',
                'slug': 'perm-item',
                'order': 2,
                'permissions': ['add_permission', 'view_session']
            }]
        }

        self.tree = MenuItem.from_json(json.dumps(self.menu))