コード例 #1
0
ファイル: tests.py プロジェクト: LucasNoga/Python
 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')
コード例 #2
0
 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)
コード例 #3
0
    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
コード例 #4
0
 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__=[]))
コード例 #5
0
 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())
コード例 #6
0
    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')
コード例 #7
0
    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')
コード例 #8
0
    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')
コード例 #9
0
    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')
コード例 #10
0
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
コード例 #11
0
ファイル: tests.py プロジェクト: thibaudcolas/django
    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")
コード例 #12
0
ファイル: tests.py プロジェクト: thibaudcolas/django
    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")
コード例 #13
0
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 }}"
コード例 #14
0
 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']))
コード例 #15
0
ファイル: tests.py プロジェクト: thibaudcolas/django
 def test_repr(self):
     ac = AppConfig("label", Stub(__path__=["a"]))
     self.assertEqual(repr(ac), "<AppConfig: label>")
コード例 #16
0
 def test_repr(self):
     ac = AppConfig('label', Stub(__path__=['a']))
     self.assertEqual(repr(ac), '<AppConfig: label>')
コード例 #17
0
ファイル: microdjango.py プロジェクト: xoreaxebx/microdjango
 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