Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

customisation_tests.py 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import pytest
  2. from django.conf import settings
  3. from django.test import TestCase
  4. from oscar.core import customisation
  5. VALID_FOLDER_PATH = 'tests/_site/apps'
  6. class TestUtilities(TestCase):
  7. def test_subfolder_extraction(self):
  8. folders = list(customisation.subfolders('/var/www/eggs'))
  9. self.assertEqual(folders, ['/var', '/var/www', '/var/www/eggs'])
  10. def test_raises_exception_for_nonexistant_app_label():
  11. with pytest.raises(ValueError):
  12. customisation.fork_app('sillytown', 'somefolder')
  13. def test_raises_exception_if_app_has_already_been_forked():
  14. # We piggyback on another test which means a custom app is already in
  15. # the settings we use for the test suite. We just check that's still
  16. # the case here.
  17. assert 'tests._site.apps.partner' in settings.INSTALLED_APPS
  18. with pytest.raises(ValueError):
  19. customisation.fork_app('partner', VALID_FOLDER_PATH)
  20. def test_creates_new_folder(tmpdir):
  21. path = tmpdir.mkdir('fork')
  22. customisation.fork_app('order', str(path))
  23. path.join('order').ensure_dir()
  24. def test_creates_init_file(tmpdir):
  25. path = tmpdir.mkdir('fork')
  26. customisation.fork_app('order', str(path))
  27. path.join('order').join('__init__.py').ensure()
  28. def test_handles_dashboard_app(tmpdir):
  29. # Dashboard apps are fiddly as they aren't identified by a single app
  30. # label.
  31. path = tmpdir.mkdir('fork')
  32. customisation.fork_app('dashboard.catalogue', str(path))
  33. # Check __init__.py created (and supporting folders)
  34. path.join('dashboard').join('catalogue').join('__init__.py').ensure()
  35. def test_creates_models_and_admin_file(tmpdir):
  36. path = tmpdir.mkdir('fork')
  37. customisation.fork_app('order', str(path))
  38. for module, expected_string in [
  39. ('models', 'from oscar.apps.order.models import *'),
  40. ('admin', 'from oscar.apps.order.admin import *'),
  41. ('config', 'OrderConfig')
  42. ]:
  43. filepath = path.join('order').join('%s.py' % module)
  44. filepath.ensure()
  45. contents = filepath.read()
  46. assert expected_string in contents
  47. def test_copies_in_migrations_when_needed(tmpdir):
  48. path = tmpdir.mkdir('fork')
  49. for app, has_models in [('order', True), ('search', False)]:
  50. customisation.fork_app(app, str(path))
  51. native_migration_path = path.join(app).join('migrations')
  52. assert has_models == native_migration_path.check()
  53. def test_dashboard_app_config(tmpdir, monkeypatch):
  54. path = tmpdir.mkdir('fork')
  55. customisation.fork_app('dashboard', str(path))
  56. path.join('__init__.py').write('')
  57. monkeypatch.syspath_prepend(str(tmpdir))
  58. config_module = __import__(
  59. '%s.dashboard.config' % path.basename, fromlist=['DashboardConfig']
  60. )
  61. assert hasattr(config_module, 'DashboardConfig')