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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import os
  2. import tempfile
  3. import unittest
  4. import django
  5. from django.test import TestCase
  6. from django.conf import settings
  7. from oscar.core import customisation
  8. VALID_FOLDER_PATH = 'tests/_site/apps'
  9. class TestForkAppFunction(TestCase):
  10. def setUp(self):
  11. self.tmp_folder = tempfile.mkdtemp()
  12. def test_raises_exception_for_nonexistant_app_label(self):
  13. with self.assertRaises(ValueError):
  14. customisation.fork_app('sillytown', 'somefolder')
  15. def test_raises_exception_for_nonexistant_folder(self):
  16. assert not os.path.exists('does_not_exist')
  17. with self.assertRaises(ValueError):
  18. customisation.fork_app('order', 'does_not_exist')
  19. def test_raises_exception_if_app_has_already_been_forked(self):
  20. # We piggyback on another test which means a custom app is already in
  21. # the settings we use for the test suite. We just check that's still
  22. # the case here.
  23. assert 'tests._site.apps.partner' in settings.INSTALLED_APPS
  24. with self.assertRaises(ValueError):
  25. customisation.fork_app('partner', VALID_FOLDER_PATH)
  26. def test_creates_new_folder(self):
  27. customisation.fork_app('order', self.tmp_folder)
  28. new_folder_path = os.path.join(self.tmp_folder, 'order')
  29. self.assertTrue(os.path.exists(new_folder_path))
  30. def test_creates_init_file(self):
  31. customisation.fork_app('order', self.tmp_folder)
  32. filepath = os.path.join(self.tmp_folder, 'order', '__init__.py')
  33. self.assertTrue(os.path.exists(filepath))
  34. def test_creates_models_and_admin_file(self):
  35. customisation.fork_app('order', self.tmp_folder)
  36. for module, expected_string in [
  37. ('models', 'from oscar.apps.order.models import *'),
  38. ('admin', 'from oscar.apps.order.admin import *'),
  39. ('config', 'OrderConfig')]:
  40. filepath = os.path.join(self.tmp_folder, 'order', '%s.py' % module)
  41. self.assertTrue(os.path.exists(filepath))
  42. contents = open(filepath).read()
  43. self.assertTrue(expected_string in contents)
  44. def test_copies_in_migrations_when_needed(self):
  45. for app, has_models in [('order', True), ('search', False)]:
  46. customisation.fork_app(app, self.tmp_folder)
  47. native_migration_path = os.path.join(
  48. self.tmp_folder, app, 'migrations')
  49. self.assertEqual(has_models, os.path.exists(native_migration_path))
  50. south_migration_path = os.path.join(
  51. self.tmp_folder, app, 'south_migrations')
  52. self.assertEqual(has_models, os.path.exists(south_migration_path))