conftest.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import pytest
  2. from .acl import ACL_CACHE, useracl
  3. from .admin.auth import authorize_admin
  4. from .categories.models import Category
  5. from .conf import SETTINGS_CACHE
  6. from .conf.dynamicsettings import DynamicSettings
  7. from .conf.staticsettings import StaticSettings
  8. from .themes import THEME_CACHE
  9. from .users import BANS_CACHE
  10. from .users.models import AnonymousUser
  11. from .users.test import create_test_superuser, create_test_user
  12. def get_cache_versions():
  13. return {
  14. ACL_CACHE: "abcdefgh",
  15. BANS_CACHE: "abcdefgh",
  16. SETTINGS_CACHE: "abcdefgh",
  17. THEME_CACHE: "abcdefgh",
  18. }
  19. @pytest.fixture
  20. def cache_versions():
  21. return get_cache_versions()
  22. @pytest.fixture
  23. def dynamic_settings(db, cache_versions):
  24. return DynamicSettings(cache_versions)
  25. @pytest.fixture
  26. def settings():
  27. return StaticSettings()
  28. @pytest.fixture
  29. def user_password():
  30. return "p4ssw0rd!"
  31. @pytest.fixture
  32. def anonymous_user():
  33. return AnonymousUser()
  34. @pytest.fixture
  35. def user(db, user_password):
  36. return create_test_user("User", "user@example.com", user_password)
  37. @pytest.fixture
  38. def user_acl(user, cache_versions):
  39. return useracl.get_user_acl(user, cache_versions)
  40. @pytest.fixture
  41. def other_user(db, user_password):
  42. return create_test_user("OtherUser", "otheruser@example.com", user_password)
  43. @pytest.fixture
  44. def other_user_acl(other_user, cache_versions):
  45. return useracl.get_user_acl(other_user, cache_versions)
  46. @pytest.fixture
  47. def staffuser(db, user_password):
  48. user = create_test_superuser("Staffuser", "staffuser@example.com", user_password)
  49. user.is_superuser = False
  50. user.save()
  51. return user
  52. @pytest.fixture
  53. def staffuser_acl(staffuser, cache_versions):
  54. return useracl.get_user_acl(staffuser, cache_versions)
  55. @pytest.fixture
  56. def superuser(db, user_password):
  57. return create_test_superuser("Superuser", "superuser@example.com", user_password)
  58. @pytest.fixture
  59. def superuser_acl(superuser, cache_versions):
  60. return useracl.get_user_acl(superuser, cache_versions)
  61. @pytest.fixture
  62. def admin_client(mocker, client, superuser):
  63. client.force_login(superuser)
  64. session = client.session
  65. authorize_admin(mocker.Mock(session=session, user=superuser))
  66. session.save()
  67. return client
  68. @pytest.fixture
  69. def root_category(db):
  70. return Category.objects.root_category()
  71. @pytest.fixture
  72. def default_category(db):
  73. return Category.objects.get(slug="first-category")