Ticket #7198: 7198_fix_with_tests.diff

File 7198_fix_with_tests.diff, 2.5 KB (added by Gabriel Hurley, 8 years ago)

fixes string interpolation, adds tests (with improvements by carljm)

  • tests/modeltests/empty/no_models/tests.py

     1from django.test import TestCase
     3class NoModelTests(TestCase):
     4    """ A placeholder test case. See modeltests.empty.tests for more info. """
     5    pass
  • tests/modeltests/empty/tests.py

     1from __future__ import with_statement
     3from django.conf import settings
     4from django.core.exceptions import ImproperlyConfigured
     5from django.db.models.loading import get_app
    16from django.test import TestCase
     7from django.test.utils import override_settings
    39from models import Empty
    1319        self.assertTrue(m.id is not None)
    1420        existing = Empty(m.id)
    1521        existing.save()
     23class NoModelTests(TestCase):
     24    """
     25    Test for #7198 to ensure that the proper error message is raised
     26    when attempting to load an app with no models.py file.
     28    Becuase the test runner won't currently load a test module with no
     29    models.py file, this TestCase instead lives in this module.
     31    It seemed like an appropriate home for it.
     32    """
     33    @override_settings(INSTALLED_APPS=("modeltests.empty.no_models",))
     34    def test_no_models(self):
     35        with self.assertRaisesRegexp(ImproperlyConfigured,
     36                    'App with label no_models is missing a models.py module.'):
     37            get_app('no_models')
  • django/db/models/loading.py

    146146                    if mod is None:
    147147                        if emptyOK:
    148148                            return None
    149                         raise ImproperlyConfigured("App with label %s is missing a models.py module.")
     149                        raise ImproperlyConfigured("App with label %s is missing a models.py module." % app_label)
    150150                    else:
    151151                        return mod
    152152            raise ImproperlyConfigured("App with label %s could not be found" % app_label)
Back to Top