test_requirements.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. from flaskbb.utils import requirements as r
  2. from flaskbb.utils.datastructures import SimpleNamespace
  3. from flaskbb.user.models import User
  4. def test_Fred_IsNotAdmin(Fred):
  5. assert not r.IsAdmin().fulfill(Fred, None)
  6. def test_IsAdmin_with_admin(admin_user):
  7. assert r.IsAdmin().fulfill(admin_user, None)
  8. def test_IsAtleastModerator_with_mod(moderator_user):
  9. assert r.IsAtleastModerator.fulfill(moderator_user, None)
  10. def test_IsAtleastModerator_with_supermod(super_moderator_user):
  11. assert r.IsAtleastModerator.fulfill(super_moderator_user, None)
  12. def test_IsAtleastModerator_with_admin(admin_user):
  13. assert r.IsAtleastModerator.fulfill(admin_user, None)
  14. def test_IsAtleastSuperModerator_with_not_smod(moderator_user):
  15. assert not r.IsAtleastSuperModerator.fulfill(moderator_user, None)
  16. def test_CanBanUser_with_admin(admin_user):
  17. assert r.CanBanUser.fulfill(admin_user, None)
  18. def test_CanBanUser_with_smod(super_moderator_user):
  19. assert r.CanBanUser.fulfill(super_moderator_user, None)
  20. def test_CanBanUser_with_mod(moderator_user):
  21. assert r.CanBanUser.fulfill(moderator_user, None)
  22. def test_Fred_CannotBanUser(Fred):
  23. assert not r.CanBanUser.fulfill(Fred, None)
  24. def test_CanEditTopic_with_member(user, topic):
  25. request = SimpleNamespace(view_args={'topic_id': topic.id})
  26. assert r.CanEditPost.fulfill(user, request)
  27. def test_Fred_cannot_edit_other_members_post(user, Fred, topic):
  28. request = SimpleNamespace(view_args={'topic_id': topic.id})
  29. assert not r.CanEditPost(Fred, request)
  30. def test_Fred_CannotEditLockedTopic(Fred, topic_locked):
  31. request = SimpleNamespace(view_args={'topic_id': topic_locked.id})
  32. assert not r.CanEditPost.fulfill(Fred, request)
  33. def test_Moderator_in_Forum_CanEditLockedTopic(moderator_user, topic_locked):
  34. request = SimpleNamespace(view_args={'topic_id': topic_locked.id})
  35. assert r.CanEditPost.fulfill(moderator_user, request)
  36. def test_FredIsAMod_but_still_cant_edit_topic_in_locked_forum(Fred, topic_locked, default_groups):
  37. request = SimpleNamespace(view_args={'topic_id': topic_locked.id})
  38. Fred.primary_group = default_groups[2]
  39. assert not r.CanEditPost.fulfill(Fred, request)
  40. def test_Fred_cannot_reply_to_locked_topic(Fred, topic_locked):
  41. request = SimpleNamespace(view_args={'topic_id': topic_locked.id})
  42. assert not r.CanPostReply.fulfill(Fred, request)
  43. def test_Fred_cannot_delete_others_post(Fred, topic):
  44. request = SimpleNamespace(view_args={'post_id': topic.first_post.id})
  45. assert not r.CanDeletePost.fulfill(Fred, request)
  46. def test_Mod_can_delete_others_post(moderator_user, topic):
  47. request = SimpleNamespace(view_args={'post_id': topic.first_post.id})
  48. assert r.CanDeletePost.fulfill(moderator_user, request)