forum.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. """Fixtures for the forum models."""
  2. import datetime
  3. import pytest
  4. from flaskbb.forum.models import Forum, Category, Topic, Post, ForumsRead, \
  5. TopicsRead
  6. @pytest.fixture
  7. def category(database):
  8. """A single category."""
  9. category = Category(title="Test Category")
  10. category.save()
  11. return category
  12. @pytest.fixture
  13. def forum(category, default_settings, default_groups):
  14. """A single forum in a category."""
  15. forum = Forum(title="Test Forum", category_id=category.id)
  16. forum.groups = default_groups
  17. forum.save()
  18. return forum
  19. @pytest.fixture
  20. def forum_locked(category, default_settings):
  21. """A single locked forum in a category."""
  22. forum = Forum(title="Test Forum", category_id=category.id)
  23. forum.locked = True
  24. forum.save()
  25. return forum
  26. @pytest.fixture
  27. def topic(forum, user):
  28. """A topic by a normal user without any extra permissions."""
  29. topic = Topic(title="Test Topic Normal")
  30. post = Post(content="Test Content Normal")
  31. return topic.save(forum=forum, user=user, post=post)
  32. @pytest.fixture
  33. def topic_moderator(forum, moderator_user):
  34. """A topic by a user with moderator permissions."""
  35. topic = Topic(title="Test Topic Moderator")
  36. post = Post(content="Test Content Moderator")
  37. return topic.save(forum=forum, user=moderator_user, post=post)
  38. @pytest.fixture
  39. def topic_locked(forum, user):
  40. """A locked topic by a user with normal permissions."""
  41. topic = Topic(title="Test Topic Locked")
  42. topic.locked = True
  43. post = Post(content="Test Content Locked")
  44. return topic.save(forum=forum, user=user, post=post)
  45. @pytest.fixture
  46. def topic_in_locked_forum(forum_locked, user):
  47. """A locked topic by a user with normal permissions."""
  48. topic = Topic(title="Test Topic Forum Locked")
  49. post = Post(content="Test Content Forum Locked")
  50. return topic.save(forum=forum_locked, user=user, post=post)
  51. @pytest.fixture
  52. def last_read():
  53. """The datetime of the formsread last_read."""
  54. return datetime.datetime.utcnow() - datetime.timedelta(hours=1)
  55. @pytest.fixture
  56. def forumsread(user, forum, last_read):
  57. """Create a forumsread object for the user and a forum."""
  58. forumsread = ForumsRead()
  59. forumsread.user_id = user.id
  60. forumsread.forum_id = forum.id
  61. forumsread.last_read = last_read
  62. forumsread.save()
  63. return forumsread
  64. @pytest.fixture
  65. def topicsread(user, topic, last_read):
  66. """Create a topicsread object for the user and a topic."""
  67. topicsread = TopicsRead()
  68. topicsread.user_id = user.id
  69. topicsread.topic_id = topic.id
  70. topicsread.forum_id = topic.forum_id
  71. topicsread.last_read = last_read
  72. topicsread.save()
  73. return topicsread