Esempio n. 1
0
    def test_event_group_page_delete(self):
        special_group = LocalGroup.objects.create(name=self.special_group_name)

        special_group_page = LocalGroupPage(
            title=self.special_group_name, group=special_group
        )
        self.event_list_page.add_child(instance=special_group_page)

        self.assertAuthGroupsExists(self.special_group_name, EVENT_AUTH_GROUP_TYPES)

        special_group_page.delete()

        self.assertAuthGroupsNotExists(self.special_group_name, EVENT_AUTH_GROUP_TYPES)
Esempio n. 2
0
    def test_local_group_page_delete(self):
        special_group = self._create_local_group(name=self.special_group_name)

        special_group_page = LocalGroupPage(title=self.special_group_name,
                                            group=special_group)
        self.local_group_list_page.add_child(instance=special_group_page)

        self.assertAuthGroupsExists(self.special_group_name,
                                    PAGE_AUTH_GROUP_TYPES)

        special_group_page.delete()

        self.assertAuthGroupsNotExists(self.special_group_name,
                                       PAGE_AUTH_GROUP_TYPES)
Esempio n. 3
0
class BlogBaseTest(PagesBaseTest):
    def setUp(self):
        super().setUp()

    def _setup_blog_pages(self):
        # create local_group(and ..._list_page) if needed
        self.local_group_list_page = LocalGroupListPage.objects.get()

        local_group_page_qs = LocalGroupPage.objects.filter(
            group=self.local_group)
        if local_group_page_qs.exists():
            self.local_group_page = local_group_page_qs.get()

        else:
            self.local_group_page = LocalGroupPage(title="Example Group",
                                                   group=self.local_group)
            self.local_group_list_page.add_child(
                instance=self.local_group_page)

        # local blog
        self.blog_list_page = BlogListPage(title="Example Blog List Page",
                                           group=self.local_group)
        self.local_group_page.add_child(instance=self.blog_list_page)

        self.blog_entry_page = BlogEntryPage(
            title="Example Blog Entry Page",
            group=self.local_group,
            date=datetime.date.today(),
            author="Joe Example",
        )
        self.blog_list_page.add_child(instance=self.blog_entry_page)

        # regional blog
        self.regional_blog_list_page = BlogListPage(
            title="Regional Blog List Page", group=self.regional_group)
        self.home_page.add_child(instance=self.regional_blog_list_page)

        self.regional_blog_entry_page = BlogEntryPage(
            title="Regional Blog Entry Page",
            group=self.regional_group,
            date=datetime.date.today(),
            author="Joe Regio Example",
        )
        self.regional_blog_list_page.add_child(
            instance=self.regional_blog_entry_page)
Esempio n. 4
0
    def _setup_local_group_pages(self):
        self.local_group_list_page = LocalGroupListPage.objects.get()

        self.local_group_page = LocalGroupPage(title="Example Group",
                                               group=self.local_group)
        self.local_group_list_page.add_child(instance=self.local_group_page)

        self.local_group_sub_page = LocalGroupSubPage(title="Example SubPage",
                                                      show_in_menus=True)
        self.local_group_page.add_child(instance=self.local_group_sub_page)

        self.LOCAL_GROUP_PAGES = {
            self.local_group_list_page,
            self.local_group_page,
            self.local_group_sub_page,
        }

        MainMenuItem.objects.get_or_create(
            menu=self.main_menu, link_page=self.local_group_list_page)
        self.local_group_list_page.show_in_menus = True
        self.local_group_list_page.save()
Esempio n. 5
0
    def _setup_local_group_pages(self):
        # create local_group if needed
        self.local_group, created = LocalGroup.objects.get_or_create(
            name="Example Group")
        self.local_group_list_page = LocalGroupListPage.objects.get()

        self.local_group_page = LocalGroupPage(title="Example Group",
                                               group=self.local_group)
        self.local_group_list_page.add_child(instance=self.local_group_page)

        self.local_group_sub_page = LocalGroupSubPage(title="Example SubPage")
        self.local_group_page.add_child(instance=self.local_group_sub_page)

        self.regional_group_page = LocalGroupPage.objects.get(
            group__is_regional_group=True)

        self.LOCAL_GROUP_PAGES = {
            self.local_group_list_page,
            self.local_group_page,
            self.local_group_sub_page,
            self.regional_group_page,
        }
Esempio n. 6
0
    def _setup_event_pages(self):
        # create local_group if needed
        self.local_group_list_page = LocalGroupListPage.objects.get()

        local_group_page_qs = LocalGroupPage.objects.filter(
            group=self.local_group)
        if local_group_page_qs.exists():
            self.local_group_page = local_group_page_qs.get()

        else:
            self.local_group_page = LocalGroupPage(title="Example Group",
                                                   group=self.local_group)
            self.local_group_list_page.add_child(
                instance=self.local_group_page)

        # create event pages
        self.event_list_page = EventListPage.objects.get()

        self.regional_event_group_page = EventGroupPage.objects.get(
            group__is_regional_group=True)

        self.regional_event_page = EventPage(
            title="Example Regional Event Page")
        self.regional_event_page.dates.add(
            EventDate(start=localtime() + datetime.timedelta(1)))
        self.regional_event_group_page.add_child(
            instance=self.regional_event_page)
        self.regional_event_page.save()

        self.event_group_page = EventGroupPage(title="Example Event Group",
                                               group=self.local_group)
        self.event_list_page.add_child(instance=self.event_group_page)

        self.event_page = EventPage(title="Example Event Page")
        self.event_page.dates.add(
            EventDate(start=localtime() + datetime.timedelta(1)))
        self.event_group_page.add_child(instance=self.event_page)

        self.EVENT_PAGES = {
            self.event_list_page,
            self.event_group_page,
            self.event_page,
            self.regional_event_group_page,
        }

        MainMenuItem.objects.get_or_create(menu=self.main_menu,
                                           link_page=self.event_list_page)
        self.event_list_page.show_in_menus = True
        self.event_list_page.save()
Esempio n. 7
0
    def test_local_group_name_change(self):
        special_group = LocalGroup.objects.create(name=self.special_group_name)

        special_group_page = LocalGroupPage(title=self.special_group_name,
                                            group=special_group)
        self.local_group_list_page.add_child(instance=special_group_page)

        self.assertAuthGroupsExists(self.special_group_name,
                                    PAGE_AUTH_GROUP_TYPES)

        special_group.name = "Another Group"
        special_group.save()

        self.assertAuthGroupsNotExists(self.special_group_name,
                                       PAGE_AUTH_GROUP_TYPES)
        self.assertAuthGroupsExists("Another Group", PAGE_AUTH_GROUP_TYPES)
Esempio n. 8
0
    def test_local_group_collection_permissions(self):
        # create a local group
        local_group, created = LocalGroup.objects.get_or_create(
            name="Example Group")
        local_group_page = LocalGroupPage(title="Example Group",
                                          group=local_group)
        local_group_list_page = LocalGroupListPage.objects.get()
        local_group_list_page.add_child(instance=local_group_page)

        local_moderators = Group.objects.get(
            name="Example Group Page Moderators")
        local_editors = Group.objects.get(name="Example Group Page Editors")
        collection = Collection.objects.get(name=COMMON_COLLECTION_NAME)

        self.assertHasGroupCollectionPermissions(
            local_moderators, collection, MODERATORS_COLLECTION_PERMISSIONS)
        self.assertHasGroupCollectionPermissions(
            local_editors, collection, EDITORS_COLLECTION_PERMISSIONS)
Esempio n. 9
0
    def _setup_event_pages(self):
        # create local_group if needed
        self.local_group_list_page = LocalGroupListPage.objects.get()
        self.local_group, created = LocalGroup.objects.get_or_create(
            name="Example Group"
        )

        if created:
            self.local_group_page = LocalGroupPage(
                title="Example Group", group=self.local_group
            )
            self.local_group_list_page.add_child(instance=self.local_group_page)

        else:
            self.local_group_page = LocalGroupPage.objects.get(group=self.local_group)

        # create event pages
        self.event_list_page = EventListPage.objects.get()

        self.regional_event_group_page = EventGroupPage.objects.get(
            group__is_regional_group=True
        )

        self.event_group_page = EventGroupPage(
            title="Example Event Group", group=self.local_group
        )
        self.event_list_page.add_child(instance=self.event_group_page)

        self.event_page = EventPage(title="Example Event")
        self.event_group_page.add_child(instance=self.event_page)

        self.EVENT_PAGES = {
            self.event_list_page,
            self.event_group_page,
            self.event_page,
            self.regional_event_group_page,
        }
Esempio n. 10
0
class PagesBaseTest(WagtailPageTests):
    def setUp(self):
        site = Site.objects.get()
        self.home_page = site.root_page
        self.root_page = Page.objects.parent_of(self.home_page).get()
        self.home_sub_page = HomeSubPage.objects.get()

        self.BASE_PAGES = {
            self.home_sub_page, self.root_page, self.home_sub_page
        }

        self.regional_group = LocalGroup.objects.get(is_regional_group=True)

    def _setup_local_group_pages(self):
        # create local_group if needed
        self.local_group, created = LocalGroup.objects.get_or_create(
            name="Example Group")
        self.local_group_list_page = LocalGroupListPage.objects.get()

        self.local_group_page = LocalGroupPage(title="Example Group",
                                               group=self.local_group)
        self.local_group_list_page.add_child(instance=self.local_group_page)

        self.local_group_sub_page = LocalGroupSubPage(title="Example SubPage")
        self.local_group_page.add_child(instance=self.local_group_sub_page)

        self.regional_group_page = LocalGroupPage.objects.get(
            group__is_regional_group=True)

        self.LOCAL_GROUP_PAGES = {
            self.local_group_list_page,
            self.local_group_page,
            self.local_group_sub_page,
            self.regional_group_page,
        }

    def assertHasGroupPagePermissions(self,
                                      group,
                                      page,
                                      permission_types=None,
                                      msg=None,
                                      exact=True):
        if permission_types is None:
            permission_types = []

        for permission_type in AVAILABLE_PAGE_PERMISSION_TYPES:
            has_permission = GroupPagePermission.objects.filter(
                group=group, page=page,
                permission_type=permission_type).exists()

            should_have_permission = permission_type in permission_types
            if not has_permission and should_have_permission:
                msg = self._formatMessage(
                    msg,
                    'Group "%s" has no "%s" permission for page %s.%s but should.'
                    % (
                        group.name,
                        permission_type,
                        page._meta.app_label,
                        page._meta.model_name,
                    ),
                )
                raise self.failureException(msg)

            elif exact and has_permission and not should_have_permission:
                msg = self._formatMessage(
                    msg,
                    'Group "%s" has "%s" permission for page %s.%s but should not.'
                    % (
                        group.name,
                        permission_type,
                        page._meta.app_label,
                        page._meta.model_name,
                    ),
                )
                raise self.failureException(msg)

    def assertHasGroupCollectionPermissions(self,
                                            groups,
                                            collection,
                                            permission_types=None,
                                            msg=None,
                                            exact=True):
        if permission_types is None:
            permission_types = []

        if not isinstance(groups, (list, tuple, set)):
            groups = [groups]

        for group in groups:
            for permission_type in AVAILABLE_COLLECTION_PERMISSION_TYPES:
                permission = get_collection_permission(permission_type)

                has_permission = GroupCollectionPermission.objects.filter(
                    group=group, collection=collection,
                    permission=permission).exists()

                should_have_permission = permission_type in permission_types

                if not has_permission and should_have_permission:
                    msg = self._formatMessage(
                        msg,
                        'Group "%s" has no "%s" permission for collection "%s" but should.'
                        % (group.name, permission_type, collection.name),
                    )
                    raise self.failureException(msg)

                if exact and has_permission and not should_have_permission:
                    msg = self._formatMessage(
                        msg,
                        'Group "%s" has "%s" permission for collection "%s" but should not.'
                        % (group.name, permission_type, collection.name),
                    )
                    raise self.failureException(msg)

    def assertAuthGroupsExists(self, group_name, msg=None):
        for auth_group_type in PAGE_AUTH_GROUP_TYPES:
            auth_group_name = get_auth_group_name(group_name, auth_group_type)
            if not Group.objects.filter(name=auth_group_name).exists():
                msg = self._formatMessage(
                    msg, 'auth.Group "%s" does not exist but should.' %
                    auth_group_name)
                raise self.failureException(msg)

    def assertAuthGroupsNotExists(self, group_name, msg=None):
        for auth_group_type in PAGE_AUTH_GROUP_TYPES:
            auth_group_name = get_auth_group_name(group_name, auth_group_type)
            if Group.objects.filter(name=auth_group_name).exists():
                msg = self._formatMessage(
                    msg,
                    'auth.Group "%s" exists but should not.' % auth_group_name)
                raise self.failureException(msg)
Esempio n. 11
0
class PagesBaseTest(WagtailPageTests):
    def setUp(self):
        self.site = Site.objects.get()
        self.home_page = self.site.root_page.specific
        self.root_page = Page.objects.parent_of(self.home_page).get()
        self.home_sub_page = HomeSubPage.objects.get()

        self.BASE_PAGES = {
            self.home_sub_page, self.root_page, self.home_sub_page
        }

        self.regional_group = LocalGroup.objects.get(is_regional_group=True)

        self.main_menu = MainMenu.get_for_site(self.site)
        MainMenuItem.objects.get_or_create(menu=self.main_menu,
                                           link_page=self.home_sub_page)
        self.home_sub_page.show_in_menus = True
        self.home_sub_page.save()

        self.local_group_name = "Example Group"
        self.local_group = self._create_local_group(self.local_group_name)

    def _create_local_group(self, name):
        # create local_group if needed
        local_group, created = LocalGroup.objects.get_or_create(site=self.site,
                                                                name=name)
        local_group.email = "*****@*****.**"
        local_group.save()
        return local_group

    def _setup_local_group_pages(self):
        self.local_group_list_page = LocalGroupListPage.objects.get()

        self.local_group_page = LocalGroupPage(title="Example Group",
                                               group=self.local_group)
        self.local_group_list_page.add_child(instance=self.local_group_page)

        self.local_group_sub_page = LocalGroupSubPage(title="Example SubPage",
                                                      show_in_menus=True)
        self.local_group_page.add_child(instance=self.local_group_sub_page)

        self.LOCAL_GROUP_PAGES = {
            self.local_group_list_page,
            self.local_group_page,
            self.local_group_sub_page,
        }

        MainMenuItem.objects.get_or_create(
            menu=self.main_menu, link_page=self.local_group_list_page)
        self.local_group_list_page.show_in_menus = True
        self.local_group_list_page.save()

    def assertHasGroupPagePermissions(self,
                                      group,
                                      page,
                                      permission_types=None,
                                      msg=None,
                                      exact=True):
        if permission_types is None:
            permission_types = []

        for permission_type in AVAILABLE_PAGE_PERMISSION_TYPES:
            has_permission = GroupPagePermission.objects.filter(
                group=group, page=page,
                permission_type=permission_type).exists()

            should_have_permission = permission_type in permission_types
            if not has_permission and should_have_permission:
                msg = self._formatMessage(
                    msg,
                    'Group "%s" has no "%s" permission for page %s.%s but should.'
                    % (
                        group.name,
                        permission_type,
                        page._meta.app_label,
                        page._meta.model_name,
                    ),
                )
                raise self.failureException(msg)

            elif exact and has_permission and not should_have_permission:
                msg = self._formatMessage(
                    msg,
                    'Group "%s" has "%s" permission for page %s.%s but should not.'
                    % (
                        group.name,
                        permission_type,
                        page._meta.app_label,
                        page._meta.model_name,
                    ),
                )
                raise self.failureException(msg)

    def assertHasGroupCollectionPermissions(self,
                                            groups,
                                            collection,
                                            permission_types=None,
                                            msg=None,
                                            exact=True):
        if permission_types is None:
            permission_types = []

        if not isinstance(groups, (list, tuple, set)):
            groups = [groups]

        for group in groups:
            for permission_type in AVAILABLE_COLLECTION_PERMISSION_TYPES:
                permission = get_collection_permission(permission_type)

                has_permission = GroupCollectionPermission.objects.filter(
                    group=group, collection=collection,
                    permission=permission).exists()

                should_have_permission = permission_type in permission_types

                if not has_permission and should_have_permission:
                    msg = self._formatMessage(
                        msg,
                        'Group "%s" has no "%s" permission for collection "%s" but should.'
                        % (group.name, permission_type, collection.name),
                    )
                    raise self.failureException(msg)

                if exact and has_permission and not should_have_permission:
                    msg = self._formatMessage(
                        msg,
                        'Group "%s" has "%s" permission for collection "%s" but should not.'
                        % (group.name, permission_type, collection.name),
                    )
                    raise self.failureException(msg)

    def assertAuthGroupsExists(self,
                               group_name,
                               group_types=PAGE_AUTH_GROUP_TYPES,
                               msg=None):
        for auth_group_type in group_types:
            auth_group_name = get_auth_group_name(group_name, auth_group_type)
            if not Group.objects.filter(name=auth_group_name).exists():
                msg = self._formatMessage(
                    msg, 'auth.Group "%s" does not exist but should.' %
                    auth_group_name)
                raise self.failureException(msg)

    def assertAuthGroupsNotExists(self,
                                  group_name,
                                  group_types=PAGE_AUTH_GROUP_TYPES,
                                  msg=None):
        for auth_group_type in group_types:
            auth_group_name = get_auth_group_name(group_name, auth_group_type)
            if Group.objects.filter(name=auth_group_name).exists():
                msg = self._formatMessage(
                    msg,
                    'auth.Group "%s" exists but should not.' % auth_group_name)
                raise self.failureException(msg)

    def assertLinkExists(self, response, page_or_url):
        url = page_or_url
        if isinstance(page_or_url, Page):
            url = page_or_url.get_url()
        return self.assertContains(response, 'href="{0}'.format(url))