forum.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 forum_locked(category, default_settings):
  19. """A single locked forum in a category."""
  20. forum = Forum(title="Test Forum", category_id=category.id)
  21. forum.locked = True
  22. forum.save()
  23. return forum
  24. @pytest.fixture
  25. def topic(forum, user):
  26. """A topic by a normal user without any extra permissions."""
  27. topic = Topic(title="Test Topic Normal")
  28. post = Post(content="Test Content Normal")
  29. return topic.save(forum=forum, user=user, post=post)
  30. @pytest.fixture
  31. def topic_moderator(forum, moderator_user):
  32. """A topic by a user with moderator permissions."""
  33. topic = Topic(title="Test Topic Moderator")
  34. post = Post(content="Test Content Moderator")
  35. return topic.save(forum=forum, user=moderator_user, post=post)
  36. @pytest.fixture
  37. def topic_locked(forum, user):
  38. """A locked topic by a user with normal permissions."""
  39. topic = Topic(title="Test Topic Locked")
  40. topic.locked = True
  41. post = Post(content="Test Content Locked")
  42. return topic.save(forum=forum, user=user, post=post)
  43. @pytest.fixture
  44. def topic_in_locked_forum(forum_locked, user):
  45. """A locked topic by a user with normal permissions."""
  46. topic = Topic(title="Test Topic Forum Locked")
  47. post = Post(content="Test Content Forum Locked")
  48. return topic.save(forum=forum_locked, user=user, post=post)
  49. @pytest.fixture
  50. def forumsread_last_read():
  51. """The datetime of the formsread last_read."""
  52. return datetime.datetime.utcnow() - datetime.timedelta(hours=1)
  53. @pytest.fixture
  54. def forumsread(user, forum, forumsread_last_read):
  55. """Create a forumsread object for the user and a forum."""
  56. forumsread = ForumsRead()
  57. forumsread.user_id = user.id
  58. forumsread.forum_id = forum.id
  59. forumsread.last_read = forumsread_last_read
  60. forumsread.save()
  61. return forumsread