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 2.8KB

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