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

test_customisation.py 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from os.path import exists, join
  2. import pytest
  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', 'sillytown')
  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 apps directory we use for the test suite. We just check that's still
  16. # the case here.
  17. assert exists(join(VALID_FOLDER_PATH, 'partner'))
  18. with pytest.raises(ValueError):
  19. customisation.fork_app('partner', VALID_FOLDER_PATH, 'partner')
  20. def test_creates_new_folder(tmpdir):
  21. path = tmpdir.mkdir('fork')
  22. customisation.fork_app('order', str(path), 'order')
  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), 'order')
  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('catalogue_dashboard', str(path), 'dashboard.catalogue')
  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), 'order')
  38. for module, expected_string in [
  39. ('models', 'from oscar.apps.order.models import *'),
  40. ('admin', 'from oscar.apps.order.admin import *'),
  41. ('apps', '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), app)
  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), 'dashboard')
  56. path.join('__init__.py').write('')
  57. monkeypatch.syspath_prepend(str(tmpdir))
  58. config_module = __import__(
  59. '%s.dashboard.apps' % path.basename, fromlist=['DashboardConfig']
  60. )
  61. assert hasattr(config_module, 'DashboardConfig')