Beispiel #1
0
    def setUp(self):
        self.nav = Nav(title="Test Nav")
        self.nav.save()
        NavItem.objects.create(label="Test Item 1",
                               nav=self.nav,
                               level=0,
                               position=0)
        NavItem.objects.create(label="Test Item 2",
                               nav=self.nav,
                               level=0,
                               position=1)
        NavItem.objects.create(label="Test Item 3",
                               nav=self.nav,
                               level=0,
                               position=2)
        self.add_url = '/admin/navs/nav/add/'
        self.change_url = '/admin/navs/nav/%i/' % self.nav.id

        self.client = Client()
        username = '******'
        email = '*****@*****.**'
        password = '******'
        User.objects.create_superuser(username, email, password)
        result = self.client.login(username=username, password=password)
        self.assertEqual(result, True)
Beispiel #2
0
    def setUp(self):
        self.nav = Nav(title="Test Nav")
        self.nav.save()
        NavItem.objects.create(label="Test Item 1", nav=self.nav, level=0, position=0)
        NavItem.objects.create(label="Test Item 2", nav=self.nav, level=0, position=1)
        NavItem.objects.create(label="Test Item 3", nav=self.nav, level=0, position=2)
        self.add_url = '/admin/navs/nav/add/'
        self.change_url = '/admin/navs/nav/%i/' % self.nav.id

        self.client = Client()
        username = '******'
        email = '*****@*****.**'
        password = '******'
        User.objects.create_superuser(username, email, password)
        result = self.client.login(username=username, password=password)
        self.assertEqual(result, True)
Beispiel #3
0
def load_nav(context, nav_id, show_title=False, **kwargs):
    """
    Renders the nav and its nav items.
    This will call nav_item that will call itself recursively nesting
    the subnavs
    """
    user = AnonymousUser()
    association_id = get_association_id(context)
    if 'user' in context:
        if isinstance(context['user'], User):
            user = context['user']
            if hasattr(user, 'profile'):
                association_id = user.profile.current_association_id

    is_site_map = kwargs.get('is_site_map', False)
    is_bootstrap = kwargs.get('is_bootstrap', False)

    # No perms check because load_nav is only called by the other tags
    try:
        # nav = Nav.objects.get(id=nav_id, association_id=association_id)
        filters = get_query_filters(user, 'navs.view_nav', association_id=association_id)
        navs = Nav.objects.filter(filters)  # .filter(id=nav_id)
        nav = Nav()
        items = []
        if navs and len(navs) > 0:
            nav = navs[0]
            if nav:
                items = nav.top_items
    except:
        return None
    context.update({
        "nav": nav,
        "items": items,
        "show_title": show_title,
        "is_bootstrap": is_bootstrap,
        'is_site_map': is_site_map,
        'user': user,
    })
    return context
Beispiel #4
0
class NavAdminInlineTest(TestCase):
    def setUp(self):
        self.nav = Nav(title="Test Nav")
        self.nav.save()
        NavItem.objects.create(label="Test Item 1",
                               nav=self.nav,
                               level=0,
                               position=0)
        NavItem.objects.create(label="Test Item 2",
                               nav=self.nav,
                               level=0,
                               position=1)
        NavItem.objects.create(label="Test Item 3",
                               nav=self.nav,
                               level=0,
                               position=2)
        self.add_url = '/admin/navs/nav/add/'
        self.change_url = '/admin/navs/nav/%i/' % self.nav.id

        self.client = Client()
        username = '******'
        email = '*****@*****.**'
        password = '******'
        User.objects.create_superuser(username, email, password)
        result = self.client.login(username=username, password=password)
        self.assertEqual(result, True)

    def tearDown(self):
        self.client.logout()

    def test_nav_add(self):
        logger.info('Testing Nav addition via admin page.')
        data = {
            'navitem_set-TOTAL_FORMS': 3,
            'navitem_set-INITIAL_FORMS': 0,
            'navitem_set-MAX_NUM_FORMS': 0,
            '_save': 'Save',
            'title': "Admin Nav",
            'description': "",
            'status_detail': "active",
            'allow_anonymous_view': True,
            'user_perms': [],
            'group_perms': [],
            'navitem_set-0-level': 0,
            'navitem_set-0-position': 0,
            'navitem_set-0-label': "Main Item 1",
            'navitem_set-0-title': "",
            'navitem_set-0-css': "",
            'navitem_set-0-page': "",
            'navitem_set-0-url': "",
            'navitem_set-0-new_window': False,
            'navitem_set-1-level': 1,
            'navitem_set-1-position': 1,
            'navitem_set-1-label': "Item 1 Child",
            'navitem_set-1-title': "",
            'navitem_set-1-css': "",
            'navitem_set-1-page': "",
            'navitem_set-1-url': "",
            'navitem_set-1-new_window': False,
            'navitem_set-2-level': 0,
            'navitem_set-2-position': 2,
            'navitem_set-2-label': "Main Item 2",
            'navitem_set-2-title': "",
            'navitem_set-2-css': "",
            'navitem_set-2-page': "",
            'navitem_set-2-url': "",
            'navitem_set-2-new_window': False,
        }
        response = self.client.post(self.add_url, data)
        self.assertEqual(response.status_code, 302)

        logger.info('Testing if Nav is added')
        self.assertEqual(len(Nav.objects.filter(title__exact='Admin Nav')), 1)
        nav = Nav.objects.get(title__exact='Admin Nav')

        logger.info('Testing if NavItems are added')
        self.assertEqual(len(NavItem.objects.filter(nav=nav)), 3)
        logger.info('Testing if Nav has the correct number of top items.')
        self.assertEqual(len(nav.top_items), 2)

        logger.info('Testing if NavItem has a child')
        navItem = NavItem.objects.get(label__exact='Main Item 1')
        self.assertEqual(len(navItem.children), 1)
        logger.info('Complete.')

    def test_nav_change(self):
        logger.info('Verifying the existence of Nav to be edited')
        response = self.client.get(self.change_url)
        self.assertEqual(response.status_code, 200)

        logger.info('Testing the number of top items for Nav before edit')
        self.assertEqual(len(self.nav.top_items), 3)

        logger.info('Testing Nav edit via admin page.')
        data = {
            'navitem_set-TOTAL_FORMS': 3,
            'navitem_set-INITIAL_FORMS': 3,
            'navitem_set-MAX_NUM_FORMS': 0,
            '_save': 'Save',
            'title': "Test Nav",
            'description': "",
            'status_detail': "active",
            'allow_anonymous_view': True,
            'user_perms': [],
            'group_perms': [],
            'navitem_set-0-id': 1,
            'navitem_set-0-level': 0,
            'navitem_set-0-position': 0,
            'navitem_set-0-label': "Test Item 1",
            'navitem_set-0-title': "",
            'navitem_set-0-css': "",
            'navitem_set-0-page': "",
            'navitem_set-0-url': "",
            'navitem_set-0-new_window': False,
            'navitem_set-1-id': 2,
            'navitem_set-1-level': 1,
            'navitem_set-1-position': 1,
            'navitem_set-1-label': "Test Item 2",
            'navitem_set-1-title': "",
            'navitem_set-1-css': "",
            'navitem_set-1-page': "",
            'navitem_set-1-url': "",
            'navitem_set-1-new_window': False,
            'navitem_set-2-id': 3,
            'navitem_set-2-level': 0,
            'navitem_set-2-position': 2,
            'navitem_set-2-label': "Test Item 3",
            'navitem_set-2-title': "",
            'navitem_set-2-css': "",
            'navitem_set-2-page': "",
            'navitem_set-2-url': "",
            'navitem_set-2-new_window': False,
        }
        response = self.client.post(self.change_url, data)
        self.assertEqual(response.status_code, 302)

        logger.info('Testing the number of top items for Nav after edit')
        self.assertEqual(len(self.nav.top_items), 2)

        logger.info('Testing if the other NavItem became a child')
        navItem = NavItem.objects.get(label__exact='Test Item 1')
        self.assertEqual(len(navItem.children), 1)
        logger.info('Complete.')
Beispiel #5
0
class NavAdminInlineTest(TestCase):

    def setUp(self):
        self.nav = Nav(title="Test Nav")
        self.nav.save()
        NavItem.objects.create(label="Test Item 1", nav=self.nav, level=0, position=0)
        NavItem.objects.create(label="Test Item 2", nav=self.nav, level=0, position=1)
        NavItem.objects.create(label="Test Item 3", nav=self.nav, level=0, position=2)
        self.add_url = '/admin/navs/nav/add/'
        self.change_url = '/admin/navs/nav/%i/' % self.nav.id

        self.client = Client()
        username = '******'
        email = '*****@*****.**'
        password = '******'
        User.objects.create_superuser(username, email, password)
        result = self.client.login(username=username, password=password)
        self.assertEqual(result, True)

    def tearDown(self):
        self.client.logout()

    def test_nav_add(self):
        logger.info('Testing Nav addition via admin page.')
        data = {
            'navitem_set-TOTAL_FORMS': 3,
            'navitem_set-INITIAL_FORMS': 0,
            'navitem_set-MAX_NUM_FORMS': 0,
            '_save': 'Save',
            'title': "Admin Nav",
            'description': "",
            'status_detail': "active",
            'allow_anonymous_view': True,
            'user_perms': [],
            'group_perms': [],
            'navitem_set-0-level': 0,
            'navitem_set-0-position': 0,
            'navitem_set-0-label': "Main Item 1",
            'navitem_set-0-title': "",
            'navitem_set-0-css': "",
            'navitem_set-0-page': "",
            'navitem_set-0-url': "",
            'navitem_set-0-new_window': False,
            'navitem_set-1-level': 1,
            'navitem_set-1-position': 1,
            'navitem_set-1-label': "Item 1 Child",
            'navitem_set-1-title': "",
            'navitem_set-1-css': "",
            'navitem_set-1-page': "",
            'navitem_set-1-url': "",
            'navitem_set-1-new_window': False,
            'navitem_set-2-level': 0,
            'navitem_set-2-position': 2,
            'navitem_set-2-label': "Main Item 2",
            'navitem_set-2-title': "",
            'navitem_set-2-css': "",
            'navitem_set-2-page': "",
            'navitem_set-2-url': "",
            'navitem_set-2-new_window': False,
        }
        response = self.client.post(self.add_url, data)
        self.assertEqual(response.status_code, 302)

        logger.info('Testing if Nav is added')
        self.assertEqual(len(Nav.objects.filter(title__exact='Admin Nav')), 1)
        nav = Nav.objects.get(title__exact='Admin Nav')

        logger.info('Testing if NavItems are added')
        self.assertEqual(len(NavItem.objects.filter(nav=nav)), 3)
        logger.info('Testing if Nav has the correct number of top items.')
        self.assertEqual(len(nav.top_items), 2)

        logger.info('Testing if NavItem has a child')
        navItem = NavItem.objects.get(label__exact='Main Item 1')
        self.assertEqual(len(navItem.children), 1)
        logger.info('Complete.')

    def test_nav_change(self):
        logger.info('Verifying the existence of Nav to be edited')
        response = self.client.get(self.change_url)
        self.assertEqual(response.status_code, 200)

        logger.info('Testing the number of top items for Nav before edit')
        self.assertEqual(len(self.nav.top_items), 3)

        logger.info('Testing Nav edit via admin page.')
        data = {
            'navitem_set-TOTAL_FORMS': 3,
            'navitem_set-INITIAL_FORMS': 3,
            'navitem_set-MAX_NUM_FORMS': 0,
            '_save': 'Save',
            'title': "Test Nav",
            'description': "",
            'status_detail': "active",
            'allow_anonymous_view': True,
            'user_perms': [],
            'group_perms': [],
            'navitem_set-0-id': 1,
            'navitem_set-0-level': 0,
            'navitem_set-0-position': 0,
            'navitem_set-0-label': "Test Item 1",
            'navitem_set-0-title': "",
            'navitem_set-0-css': "",
            'navitem_set-0-page': "",
            'navitem_set-0-url': "",
            'navitem_set-0-new_window': False,
            'navitem_set-1-id': 2,
            'navitem_set-1-level': 1,
            'navitem_set-1-position': 1,
            'navitem_set-1-label': "Test Item 2",
            'navitem_set-1-title': "",
            'navitem_set-1-css': "",
            'navitem_set-1-page': "",
            'navitem_set-1-url': "",
            'navitem_set-1-new_window': False,
            'navitem_set-2-id': 3,
            'navitem_set-2-level': 0,
            'navitem_set-2-position': 2,
            'navitem_set-2-label': "Test Item 3",
            'navitem_set-2-title': "",
            'navitem_set-2-css': "",
            'navitem_set-2-page': "",
            'navitem_set-2-url': "",
            'navitem_set-2-new_window': False,
        }
        response = self.client.post(self.change_url, data)
        self.assertEqual(response.status_code, 302)

        logger.info('Testing the number of top items for Nav after edit')
        self.assertEqual(len(self.nav.top_items), 2)

        logger.info('Testing if the other NavItem became a child')
        navItem = NavItem.objects.get(label__exact='Test Item 1')
        self.assertEqual(len(navItem.children), 1)
        logger.info('Complete.')