Exemple #1
0
    def test_user_site_links_perm(self):
        # Add link with resultpage permission
        secret_link = self._add_link(title='Results Page', component='results')
        perm = LinkPermissionFactory.create(
            permission='cms.api_change_resultpage', present=True)
        secret_link.link_permissions.add(perm)

        # User can't access link with permissions
        results = get_user_site_links(self.user1)
        self.assertEqual(len(_group_by_name(results, 'main')['links']), 2)

        # Add resultpage permission to User
        resultpage_perm = Permission.objects.get(
            codename='api_change_resultpage')
        self.user1.user_permissions.add(resultpage_perm)
        self.user1 = get_user_model().objects.get(pk=self.user1.pk)

        # User can now access link with resultpage permission
        results = get_user_site_links(self.user1)
        self.assertEqual(len(_group_by_name(results, 'main')['links']), 3)
Exemple #2
0
    def test_language_language_fallback(self, mock_get_language):
        mock_get_language.return_value = 'nl'

        # Test fallback to first site links when none found for language
        results = get_user_site_links(self.user1)
        self.assertEqual(len(_group_by_name(results, 'main')['links']), 2)

        # Now create NL site links
        language_nl = LanguageFactory.create(code='nl')
        site_links = SiteLinksFactory.create(language=language_nl)
        link_group = LinkGroupFactory.create(title='NL Group',
                                             name='main-nl',
                                             site_links=site_links)
        LinkFactory.create(link_group=link_group,
                           title='Project List NL',
                           component='project')

        # Test language specific site links are loaded if available
        results = get_user_site_links(self.user1)
        links = _group_by_name(results, 'main-nl')['links']
        self.assertEqual(len(links), 1)
        self.assertEqual(links[0]['title'], 'Project List NL')
Exemple #3
0
    def test_user_site_links_response(self):
        results = get_user_site_links(self.user1)

        main = _group_by_name(results, 'main')
        main_links = main['links']
        self.assertEqual(len(main_links), 2)
        self.assertEqual(len(_group_by_name(results, 'about')['links']), 1)

        link1 = main_links[0]
        expected1 = {
            'route': 'project',
            'isHighlighted': False,
            'title': 'Project List',
            'sequence': 1
        }
        self.assertEqual(main['title'], 'main Group')
        self.assertEqual(link1, expected1)
Exemple #4
0
    def test_user_site_links_external(self):
        results = get_user_site_links(self.user1)

        link = _group_by_name(results, 'about')['links'][0]
        self.assertTrue(link['external'])