test_uploading_media.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os
  2. import pytest
  3. from django.urls import reverse
  4. TESTS_DIR = os.path.dirname(os.path.abspath(__file__))
  5. @pytest.fixture
  6. def font_file():
  7. return os.path.join(TESTS_DIR, "font", "Lato.ttf")
  8. @pytest.fixture
  9. def text_file():
  10. return os.path.join(TESTS_DIR, "font", "OFL.txt")
  11. @pytest.fixture
  12. def png_file():
  13. return os.path.join(TESTS_DIR, "images", "test.png")
  14. @pytest.fixture
  15. def svg_file():
  16. return os.path.join(TESTS_DIR, "images", "test.svg")
  17. @pytest.fixture
  18. def upload(admin_client):
  19. def post_upload(theme, asset_files):
  20. url = reverse(
  21. "misago:admin:appearance:themes:upload-media", kwargs={"pk": theme.pk}
  22. )
  23. if asset_files:
  24. data = asset_files if isinstance(asset_files, list) else [asset_files]
  25. else:
  26. data = None
  27. return admin_client.post(url, {"assets": data})
  28. return post_upload
  29. def test_font_file_can_be_uploaded(upload, theme, font_file):
  30. with open(font_file, "rb") as fp:
  31. upload(theme, fp)
  32. assert theme.media.exists()
  33. def test_text_file_can_be_uploaded(upload, theme, text_file):
  34. with open(text_file) as fp:
  35. upload(theme, fp)
  36. assert theme.media.exists()
  37. def test_png_file_can_be_uploaded(upload, theme, png_file):
  38. with open(png_file, "rb") as fp:
  39. upload(theme, fp)
  40. assert theme.media.exists()
  41. def test_svg_file_can_be_uploaded(upload, theme, svg_file):
  42. with open(svg_file) as fp:
  43. upload(theme, fp)
  44. assert theme.media.exists()