You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

customisation_tests.py 3.3KB

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