Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

customisation_tests.py 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 TestForkAppFunction(TestCase):
  8. def setUp(self):
  9. self.tmp_folder = tempfile.mkdtemp()
  10. def test_raises_exception_for_nonexistant_app_label(self):
  11. with self.assertRaises(ValueError):
  12. customisation.fork_app('sillytown', 'somefolder')
  13. def test_raises_exception_for_nonexistant_folder(self):
  14. assert not os.path.exists('does_not_exist')
  15. with self.assertRaises(ValueError):
  16. customisation.fork_app('order', 'does_not_exist')
  17. def test_raises_exception_if_app_has_alredy_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. assert 'tests._site.apps.partner' in 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_creates_models_and_admin_file(self):
  33. customisation.fork_app('order', self.tmp_folder)
  34. for module in ['models', 'admin']:
  35. filepath = os.path.join(self.tmp_folder, 'order', '%s.py' % module)
  36. self.assertTrue(os.path.exists(filepath))
  37. contents = open(filepath).read()
  38. expected_string = 'from oscar.apps.order.%s import *' % module
  39. self.assertTrue(expected_string in contents)
  40. def test_copies_in_migrations_when_needed(self):
  41. for app, has_models in [('order', True), ('search', False)]:
  42. customisation.fork_app(app, self.tmp_folder)
  43. migration_path = os.path.join(self.tmp_folder, app, 'migrations')
  44. self.assertEqual(has_models, os.path.exists(migration_path))