Skip to content

Instantly share code, notes, and snippets.

@hvdklauw
Forked from sh4nks/test_permissions.py
Last active August 29, 2015 13:57
Show Gist options
  • Save hvdklauw/9686872 to your computer and use it in GitHub Desktop.
Save hvdklauw/9686872 to your computer and use it in GitHub Desktop.
import pytest
from flaskbb.user.models import User
from flaskbb.forum.models import Forum, Category
@pytest.fixture
def category(database):
category = Category(title="Test Category")
category.save()
return category
@pytest.fixture
def forum(category):
forum = Forum(title="Test Forum", category_id=category.id)
forum.save()
return forum
@pytest.fixture
def moderator_user(forum, default_groups):
"""Creates a test user for whom the permissions should be checked"""
# This should be moved to own fixture which you then use to link the user to the forum
user = User(username="test_mod", email="test_mod@example.org",
password="test", primary_group_id=default_groups[2].id)
user.save()
forum.moderators.append(user)
forum.save()
return user
@pytest.fixture
def normal_user(default_groups):
"""Creates a user with normal permissions"""
user = User(username="test_normal", email="test_normal@example.org",
password="test", primary_group_id=default_groups[3].id)
user.save()
return user
@pytest.fixture
def admin_user(default_groups):
"""Creates a admin user"""
user = User(username="test_admin", email="test_admin@example.org",
password="test", primary_group_id=default_groups[0].id)
user.save()
return user
def test_moderator_permissions(forum, moderator_user):
"""Test that the default groups are created correctly."""
assert moderator_user in forum.moderators
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment