forum.py 2.6 KB

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