def test_duplicate_dunder_path_no_dunder_file(self): """ If the __path__ attr contains duplicate paths and there is no __file__, they duplicates should be deduplicated (#25246). """ ac = AppConfig('label', Stub(__path__=['a', 'a'])) self.assertEqual(ac.path, 'a')
def test_eve_client_get_instance_app_config(self, mock_app_config): mock_app_config.return_value = AppConfig( app_name='django_eveonline_connector', app_module=django_eveonline_connector) mock_app_config.return_value.ESI_CLIENT_ID = "MOCKED" mock_app_config.return_value.ESI_SECRET_KEY = "MOCKED" mock_app_config.return_value.ESI_CALLBACK_URL = "MOCKED" mock_app_config.return_value.ESI_BASE_URL = "MOCKED" client = EveClient.get_instance() self.assertTrue("MOCKED" == client.esi_callback_url)
def setup(self, verbosity, testLabels): # Force declaring available_apps in TransactionTestCase for faster # tests. def noAvailableApps(self): raise Exception('Please define available_apps in' ' TransactionTestCase and its subclasses.') TransactionTestCase.available_apps = property(noAvailableApps) TestCase.available_apps = None state = self.prepareSettings(settings) if verbosity > 0: # Ensure any warnings captured to logging are piped through a # verbose logging handler. If any -W options were passed # explicitly on command line, warnings are not captured, and # this has no effect. logger = logging.getLogger('py.warnings') handler = logging.StreamHandler() logger.addHandler(handler) # Load all the self.alwaysInstalledApps. django.setup() # Reduce given test labels to just the app module path appNames = set(l.split('.', 1)[0] for l in testLabels) # Load all the test model apps. if verbosity >= 2: self.stream.writeln('Importing applications ...') for name in appNames: if verbosity >= 2: self.stream.writeln('Importing application {0}'.format(name)) module = importlib.import_module(name) config = AppConfig(name, module) config.label = '_'.join((config.label.strip('_'), 'tests')) settings.INSTALLED_APPS.append(config) apps.set_installed_apps(settings.INSTALLED_APPS) return state
def test_empty_dunder_path_no_dunder_file(self): """If the __path__ attr is empty and there is no __file__, raise.""" with self.assertRaises(ImproperlyConfigured): AppConfig('label', Stub(__path__=[]))
def test_no_dunder_path_or_dunder_file(self): """If there is no __path__ or __file__, raise ImproperlyConfigured.""" with self.assertRaises(ImproperlyConfigured): AppConfig('label', Stub())
def test_multiple_dunder_path_fallback_to_dunder_file(self): """If the __path__ attr is length>1, use __file__ if set.""" ac = AppConfig('label', Stub(__path__=['a', 'b'], __file__='c/__init__.py')) self.assertEqual(ac.path, 'c')
def test_empty_dunder_path_fallback_to_dunder_file(self): """If the __path__ attr is empty, use __file__ if set.""" ac = AppConfig('label', Stub(__path__=[], __file__='b/__init__.py')) self.assertEqual(ac.path, 'b')
def test_no_dunder_path_fallback_to_dunder_file(self): """If there is no __path__ attr, use __file__.""" ac = AppConfig('label', Stub(__file__='b/__init__.py')) self.assertEqual(ac.path, 'b')
def test_dunder_path(self): """If single element in __path__, use it (in preference to __file__).""" ac = AppConfig('label', Stub(__path__=['a'], __file__='b/__init__.py')) self.assertEqual(ac.path, 'a')
from django.apps import AppConfig class {{ cookiecutter.project_slug.title().replace('_', '') }}AppConfig(AppConfig): name = '{{ cookiecutter.project_slug }}' def ready(self): # noinspection PyUnresolvedReferences from {{ cookiecutter.project_slug }} import celery # noqa
def test_multiple_dunder_path_fallback_to_dunder_file(self): """If the __path__ attr is length>1, use __file__ if set.""" ac = AppConfig("label", Stub(__path__=["a", "b"], __file__="c/__init__.py")) self.assertEqual(ac.path, "c")
def test_dunder_path(self): """If single element in __path__, use it (in preference to __file__).""" ac = AppConfig("label", Stub(__path__=["a"], __file__="b/__init__.py")) self.assertEqual(ac.path, "a")
from django.apps import AppConfig class Wagtail{{ cookiecutter.project_name_camel }}AppConfig(AppConfig): label = "wagtail_{{ cookiecutter.project_name_snake }}" name = "wagtail_{{ cookiecutter.project_name_snake }}" verbose_name = "Wagtail {{ cookiecutter.project_name }}"
def test_multiple_dunder_path_no_dunder_file(self): """If the __path__ attr is length>1 and there is no __file__, raise.""" with self.assertRaises(ImproperlyConfigured): AppConfig('label', Stub(__path__=['a', 'b']))
def test_repr(self): ac = AppConfig("label", Stub(__path__=["a"])) self.assertEqual(repr(ac), "<AppConfig: label>")
def test_repr(self): ac = AppConfig('label', Stub(__path__=['a'])) self.assertEqual(repr(ac), '<AppConfig: label>')
def _create_app_config(self, app_module): from django.apps import apps, AppConfig from django.conf import settings app = AppConfig(app_module.__name__, app_module) apps.populate(list(settings.INSTALLED_APPS) + [app]) return app