forum.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """Fixtures for the forum models."""
  2. import datetime
  3. import pytest
  4. from flaskbb.forum.models import Forum, Category, Topic, Post, ForumsRead
  5. @pytest.fixture
  6. def category(database):
  7. """A single category."""
  8. category = Category(title="Test Category")
  9. category.save()
  10. return category
  11. @pytest.fixture
  12. def forum(category, default_settings):
  13. """A single forum in a category."""
  14. forum = Forum(title="Test Forum", category_id=category.id)
  15. forum.save()
  16. return forum
  17. @pytest.fixture
  18. def topic(forum, user):
  19. """A topic by a normal user without any extra permissions."""
  20. topic = Topic(title="Test Topic Normal")
  21. post = Post(content="Test Content Normal")
  22. return topic.save(forum=forum, user=user, post=post)
  23. @pytest.fixture
  24. def topic_moderator(forum, moderator_user):
  25. """A topic by a user with moderator permissions."""
  26. topic = Topic(title="Test Topic Moderator")
  27. post = Post(content="Test Content Moderator")
  28. return topic.save(forum=forum, user=moderator_user, post=post)
  29. @pytest.fixture
  30. def forumsread_last_read():
  31. """The datetime of the formsread last_read."""
  32. return datetime.datetime.utcnow() - datetime.timedelta(hours=1)
  33. @pytest.fixture
  34. def forumsread(user, forum, forumsread_last_read):
  35. """Create a forumsread object for the user and a forum."""
  36. forumsread = ForumsRead()
  37. forumsread.user_id = user.id
  38. forumsread.forum_id = forum.id
  39. forumsread.last_read = forumsread_last_read
  40. forumsread.save()
  41. return forumsread