Пример #1
0
    def test_change_category_roles_view(self):
        """change category roles perms view works"""
        root = Category.objects.root_category()
        for descendant in root.get_descendants():
            descendant.delete()
        """
        Create categories tree for test cases:

        Category A
          + Category B
        Category C
          + Category D
        """
        root = Category.objects.root_category()
        self.client.post(reverse('misago:admin:categories:nodes:new'),
                         data={
                             'name': 'Category A',
                             'new_parent': root.pk,
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })
        test_category = Category.objects.get(slug='category-a')

        self.assertEqual(Category.objects.count(), 3)
        """
        Create test roles
        """
        self.client.post(reverse('misago:admin:permissions:users:new'),
                         data=fake_post_data(Role(), {'name': 'Test Role A'}))
        self.client.post(reverse('misago:admin:permissions:users:new'),
                         data=fake_post_data(Role(), {'name': 'Test Role B'}))

        test_role_a = Role.objects.get(name='Test Role A')
        test_role_b = Role.objects.get(name='Test Role B')

        self.client.post(reverse('misago:admin:permissions:categories:new'),
                         data=fake_data({'name': 'Test Comments'}))
        self.client.post(reverse('misago:admin:permissions:categories:new'),
                         data=fake_data({'name': 'Test Full'}))

        role_comments = CategoryRole.objects.get(name='Test Comments')
        role_full = CategoryRole.objects.get(name='Test Full')
        """
        Test view itself
        """
        # See if form page is rendered
        response = self.client.get(
            reverse('misago:admin:categories:nodes:permissions',
                    kwargs={'pk': test_category.pk}))
        self.assertContains(response, test_category.name)
        self.assertContains(response, test_role_a.name)
        self.assertContains(response, test_role_b.name)
        self.assertContains(response, role_comments.name)
        self.assertContains(response, role_full.name)

        # Assign roles to categories
        response = self.client.post(reverse(
            'misago:admin:categories:nodes:permissions',
            kwargs={'pk': test_category.pk}),
                                    data={
                                        ('%s-category_role' % test_role_a.pk):
                                        role_full.pk,
                                        ('%s-category_role' % test_role_b.pk):
                                        role_comments.pk,
                                    })
        self.assertEqual(response.status_code, 302)

        # Check that roles were assigned
        category_role_set = test_category.category_role_set
        self.assertEqual(
            category_role_set.get(role=test_role_a).category_role_id,
            role_full.pk)
        self.assertEqual(
            category_role_set.get(role=test_role_b).category_role_id,
            role_comments.pk)
Пример #2
0
def load_fixtures():
    role_admin = Role(
                      name=_("Administrator").message,
                      token='admin',
                      protected=True,
                      )
    role_mod = Role(
                    name=_("Moderator").message,
                    token='mod',
                    protected=True,
                    )
    role_registered = Role(
                           name=_("Registered").message,
                           token='registered',
                           )
    role_guest = Role(
                      name=_("Guest").message,
                      token='guest',
                      )
    
    role_admin.save(force_insert=True)
    role_mod.save(force_insert=True)
    role_registered.save(force_insert=True)
    role_guest.save(force_insert=True)    
Пример #3
0
    def test_change_role_categories_permissions_view(self):
        """change role categories perms view works"""
        self.client.post(reverse('misago:admin:permissions:users:new'),
                         data=fake_post_data(Role(),
                                             {'name': 'Test CategoryRole'}))

        test_role = Role.objects.get(name='Test CategoryRole')

        root = Category.objects.root_category()
        for descendant in root.get_descendants():
            descendant.delete()

        self.assertEqual(Category.objects.count(), 2)
        response = self.client.get(
            reverse('misago:admin:permissions:users:categories',
                    kwargs={'pk': test_role.pk}))
        self.assertEqual(response.status_code, 302)
        """
        Create categories tree for test cases:

        Category A
          + Category B
        Category C
          + Category D
        """
        root = Category.objects.root_category()
        self.client.post(reverse('misago:admin:categories:nodes:new'),
                         data={
                             'name': 'Category A',
                             'new_parent': root.pk,
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })
        self.client.post(reverse('misago:admin:categories:nodes:new'),
                         data={
                             'name': 'Category C',
                             'new_parent': root.pk,
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })

        category_a = Category.objects.get(slug='category-a')
        category_c = Category.objects.get(slug='category-c')

        self.client.post(reverse('misago:admin:categories:nodes:new'),
                         data={
                             'name': 'Category B',
                             'new_parent': category_a.pk,
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })
        category_b = Category.objects.get(slug='category-b')

        self.client.post(reverse('misago:admin:categories:nodes:new'),
                         data={
                             'name': 'Category D',
                             'new_parent': category_c.pk,
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })
        category_d = Category.objects.get(slug='category-d')

        self.assertEqual(Category.objects.count(), 6)

        # See if form page is rendered
        response = self.client.get(
            reverse('misago:admin:permissions:users:categories',
                    kwargs={'pk': test_role.pk}))
        self.assertContains(response, category_a.name)
        self.assertContains(response, category_b.name)
        self.assertContains(response, category_c.name)
        self.assertContains(response, category_d.name)

        # Set test roles
        self.client.post(reverse('misago:admin:permissions:categories:new'),
                         data=fake_data({'name': 'Test Comments'}))
        role_comments = CategoryRole.objects.get(name='Test Comments')

        self.client.post(reverse('misago:admin:permissions:categories:new'),
                         data=fake_data({'name': 'Test Full'}))
        role_full = CategoryRole.objects.get(name='Test Full')

        # See if form contains those roles
        response = self.client.get(
            reverse('misago:admin:permissions:users:categories',
                    kwargs={'pk': test_role.pk}))
        self.assertContains(response, role_comments.name)
        self.assertContains(response, role_full.name)

        # Assign roles to categories
        response = self.client.post(reverse(
            'misago:admin:permissions:users:categories',
            kwargs={'pk': test_role.pk}),
                                    data={
                                        ('%s-role' % category_a.pk):
                                        role_comments.pk,
                                        ('%s-role' % category_b.pk):
                                        role_comments.pk,
                                        ('%s-role' % category_c.pk):
                                        role_full.pk,
                                        ('%s-role' % category_d.pk):
                                        role_full.pk,
                                    })
        self.assertEqual(response.status_code, 302)

        # Check that roles were assigned
        categories_acls = test_role.categories_acls
        self.assertEqual(
            categories_acls.get(category=category_a).category_role_id,
            role_comments.pk)
        self.assertEqual(
            categories_acls.get(category=category_b).category_role_id,
            role_comments.pk)
        self.assertEqual(
            categories_acls.get(category=category_c).category_role_id,
            role_full.pk)
        self.assertEqual(
            categories_acls.get(category=category_d).category_role_id,
            role_full.pk)
Пример #4
0
def fake_data(data_dict):
    return fake_post_data(Role(), data_dict)
Пример #5
0
def load_fixtures():
    role_admin = Role(
        name=_("Administrator").message,
        token='admin',
        protected=True,
    )
    role_mod = Role(
        name=_("Moderator").message,
        token='mod',
        protected=True,
    )
    role_registered = Role(
        name=_("Registered").message,
        token='registered',
    )
    role_guest = Role(
        name=_("Guest").message,
        token='guest',
    )

    role_admin.save(force_insert=True)
    role_mod.save(force_insert=True)
    role_registered.save(force_insert=True)
    role_guest.save(force_insert=True)
Пример #6
0
    def test_fake_post_data_for_role(self):
        """fake data was created for Role"""
        test_data = fake_post_data(Role(), {'can_fly': 1})

        self.assertIn('can_fly', test_data)
Пример #7
0
    def test_change_forum_roles_view(self):
        """change forum roles perms view works"""
        root = Forum.objects.root_category()
        for descendant in root.get_descendants():
            descendant.delete()
        """
        Create forums tree for test cases:

        Category A
          + Forum B
        Category C
          + Forum D
        """
        root = Forum.objects.root_category()
        self.client.post(reverse('misago:admin:forums:nodes:new'),
                         data={
                             'name': 'Category A',
                             'new_parent': root.pk,
                             'role': 'category',
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })
        test_category = Forum.objects.get(slug='category-a')

        self.assertEqual(Forum.objects.count(), 3)
        """
        Create test roles
        """
        self.client.post(reverse('misago:admin:permissions:users:new'),
                         data=fake_post_data(Role(), {'name': 'Test Role A'}))
        self.client.post(reverse('misago:admin:permissions:users:new'),
                         data=fake_post_data(Role(), {'name': 'Test Role B'}))

        test_role_a = Role.objects.get(name='Test Role A')
        test_role_b = Role.objects.get(name='Test Role B')

        self.client.post(reverse('misago:admin:permissions:forums:new'),
                         data=fake_data({'name': 'Test Comments'}))
        self.client.post(reverse('misago:admin:permissions:forums:new'),
                         data=fake_data({'name': 'Test Full'}))

        role_comments = ForumRole.objects.get(name='Test Comments')
        role_full = ForumRole.objects.get(name='Test Full')
        """
        Test view itself
        """
        # See if form page is rendered
        response = self.client.get(
            reverse('misago:admin:forums:nodes:permissions',
                    kwargs={'forum_id': test_category.pk}))
        self.assertEqual(response.status_code, 200)
        self.assertIn(test_category.name, response.content)
        self.assertIn(test_role_a.name, response.content)
        self.assertIn(test_role_b.name, response.content)
        self.assertIn(role_comments.name, response.content)
        self.assertIn(role_full.name, response.content)

        # Assign roles to forums
        response = self.client.post(reverse(
            'misago:admin:forums:nodes:permissions',
            kwargs={'forum_id': test_category.pk}),
                                    data={
                                        ('%s-forum_role' % test_role_a.pk):
                                        role_full.pk,
                                        ('%s-forum_role' % test_role_b.pk):
                                        role_comments.pk,
                                    })
        self.assertEqual(response.status_code, 302)

        # Check that roles were assigned
        self.assertEqual(
            test_category.forum_role_set.get(role=test_role_a).forum_role_id,
            role_full.pk)
        self.assertEqual(
            test_category.forum_role_set.get(role=test_role_b).forum_role_id,
            role_comments.pk)
Пример #8
0
    def test_change_role_forums_permissions_view(self):
        """change role forums perms view works"""
        self.client.post(reverse('misago:admin:permissions:users:new'),
                         data=fake_post_data(Role(),
                                             {'name': 'Test ForumRole'}))

        test_role = Role.objects.get(name='Test ForumRole')

        root = Forum.objects.root_category()
        for descendant in root.get_descendants():
            descendant.delete()

        self.assertEqual(Forum.objects.count(), 2)
        response = self.client.get(
            reverse('misago:admin:permissions:users:forums',
                    kwargs={'role_id': test_role.pk}))
        self.assertEqual(response.status_code, 302)
        """
        Create forums tree for test cases:

        Category A
          + Forum B
        Category C
          + Forum D
        """
        root = Forum.objects.root_category()
        self.client.post(reverse('misago:admin:forums:nodes:new'),
                         data={
                             'name': 'Category A',
                             'new_parent': root.pk,
                             'role': 'category',
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })
        self.client.post(reverse('misago:admin:forums:nodes:new'),
                         data={
                             'name': 'Category C',
                             'new_parent': root.pk,
                             'role': 'category',
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })

        category_a = Forum.objects.get(slug='category-a')
        category_c = Forum.objects.get(slug='category-c')

        self.client.post(reverse('misago:admin:forums:nodes:new'),
                         data={
                             'name': 'Forum B',
                             'new_parent': category_a.pk,
                             'role': 'forum',
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })
        forum_b = Forum.objects.get(slug='forum-b')

        self.client.post(reverse('misago:admin:forums:nodes:new'),
                         data={
                             'name': 'Forum D',
                             'new_parent': category_c.pk,
                             'role': 'forum',
                             'prune_started_after': 0,
                             'prune_replied_after': 0,
                         })
        forum_d = Forum.objects.get(slug='forum-d')

        self.assertEqual(Forum.objects.count(), 6)

        # See if form page is rendered
        response = self.client.get(
            reverse('misago:admin:permissions:users:forums',
                    kwargs={'role_id': test_role.pk}))
        self.assertEqual(response.status_code, 200)
        self.assertIn(category_a.name, response.content)
        self.assertIn(forum_b.name, response.content)
        self.assertIn(category_c.name, response.content)
        self.assertIn(forum_d.name, response.content)

        # Set test roles
        self.client.post(reverse('misago:admin:permissions:forums:new'),
                         data=fake_data({'name': 'Test Comments'}))
        role_comments = ForumRole.objects.get(name='Test Comments')

        self.client.post(reverse('misago:admin:permissions:forums:new'),
                         data=fake_data({'name': 'Test Full'}))
        role_full = ForumRole.objects.get(name='Test Full')

        # See if form contains those roles
        response = self.client.get(
            reverse('misago:admin:permissions:users:forums',
                    kwargs={'role_id': test_role.pk}))
        self.assertEqual(response.status_code, 200)
        self.assertIn(role_comments.name, response.content)
        self.assertIn(role_full.name, response.content)

        # Assign roles to forums
        response = self.client.post(reverse(
            'misago:admin:permissions:users:forums',
            kwargs={'role_id': test_role.pk}),
                                    data={
                                        ('%s-role' % category_a.pk):
                                        role_comments.pk,
                                        ('%s-role' % forum_b.pk):
                                        role_comments.pk,
                                        ('%s-role' % category_c.pk):
                                        role_full.pk,
                                        ('%s-role' % forum_d.pk):
                                        role_full.pk,
                                    })
        self.assertEqual(response.status_code, 302)

        # Check that roles were assigned
        self.assertEqual(
            test_role.forums_acls.get(forum=category_a).forum_role_id,
            role_comments.pk)
        self.assertEqual(
            test_role.forums_acls.get(forum=forum_b).forum_role_id,
            role_comments.pk)
        self.assertEqual(
            test_role.forums_acls.get(forum=category_c).forum_role_id,
            role_full.pk)
        self.assertEqual(
            test_role.forums_acls.get(forum=forum_d).forum_role_id,
            role_full.pk)