Ticket #9005: 9005-with-tests.diff

File 9005-with-tests.diff, 3.2 KB (added by Eric Holscher, 16 years ago)

Patch with tests. Fails on trunk with above-mentioned error, passed with patch with correct lack of url resolution.

  • django/core/management/__init__.py

    diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
    index 4b40009..151b94e 100644
    a b def setup_environ(settings_mod, original_settings_path=None):  
    323323    else:
    324324        os.environ['DJANGO_SETTINGS_MODULE'] = '%s.%s' % (project_name, settings_name)
    325325
    326     # Import the project module. We add the parent directory to PYTHONPATH to 
     326    # Import the project module. We add the parent directory to PYTHONPATH to
    327327    # avoid some of the path errors new users can have.
    328328    sys.path.append(os.path.join(project_directory, os.pardir))
    329329    project_module = import_module(project_name)
  • django/template/defaulttags.py

    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index c08ecc4..e5b2101 100644
    a b class URLNode(Node):  
    371371        try:
    372372            url = reverse(self.view_name, args=args, kwargs=kwargs)
    373373        except NoReverseMatch:
    374             project_name = settings.SETTINGS_MODULE.split('.')[0]
    375             try:
    376                 url = reverse(project_name + '.' + self.view_name,
    377                               args=args, kwargs=kwargs)
    378             except NoReverseMatch:
     374            if settings.SETTINGS_MODULE is None:
     375                # SETTINGS_MODULE is not set, so we can't guess the "main" app.
    379376                if self.asvar is None:
    380377                    raise
     378            else:
     379                project_name = settings.SETTINGS_MODULE.split('.')[0]
     380                try:
     381                    url = reverse(project_name + '.' + self.view_name,
     382                              args=args, kwargs=kwargs)
     383                except NoReverseMatch:
     384                    if self.asvar is None:
     385                        raise
    381386
    382387        if self.asvar:
    383388            context[self.asvar] = url
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index c511222..c45daf3 100644
    a b class Templates(unittest.TestCase):  
    152152        split = token.split_contents()
    153153        self.assertEqual(split, ["sometag", '_("Page not found")', 'value|yesno:_("yes,no")'])
    154154
     155    def test_url_reverse_no_settings_module(self):
     156        #Regression test for #9005
     157        from django.template import Template, Context, TemplateSyntaxError
     158        old_settings_module = settings.SETTINGS_MODULE
     159        settings.SETTINGS_MODULE = None
     160        t = Template('{% url will_not_match %}')
     161        c = Context()
     162        try:
     163            rendered = t.render(c)
     164        except TemplateSyntaxError, e:
     165            #Assert that we are getting the template syntax error and not the
     166            #string encoding error.
     167            self.assertEquals(e.message, "Caught an exception while rendering: Reverse for 'will_not_match' with arguments '()' and keyword arguments '{}' not found.")
     168        settings.SETTINGS_MODULE = old_settings_module
     169
    155170    def test_templates(self):
    156171        template_tests = self.get_template_tests()
    157172        filter_tests = filters.get_filter_tests()
Back to Top