Opened 7 years ago

Closed 4 years ago

#6644 closed Bug (fixed)

FormPreview doesn't pass tests

Reported by: alfred.einstein@… Owned by: simeon
Component: contrib.formtools Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

adding 'django.contrib.formtools' to the installed apps and run:

./manage.py test

got:

..EEE.
======================================================================
ERROR: test_form_get (django.contrib.formtools.tests.PreviewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/tests.py", line 48, in test_form_get
    response = self.client.get('/test1/')
  File "/home/visi/Devel/django/djtrunk/django/test/client.py", line 217, in get
    return self.request(**r)
  File "/home/visi/Devel/django/djtrunk/django/core/handlers/base.py", line 82, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/preview.py", line 31, in __call__
    return method(request)
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/preview.py", line 54, in preview_get
    context_instance=RequestContext(request))
  File "/home/visi/djtrunk/django/shortcuts/__init__.py", line 18, in render_to_response
  File "/home/visi/djtrunk/django/template/loader.py", line 106, in render_to_string
  File "/home/visi/Devel/django/djtrunk/django/test/utils.py", line 21, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/visi/Devel/django/djtrunk/django/template/__init__.py", line 748, in render
    bits.append(self.render_node(node, context))
  File "/home/visi/Devel/django/djtrunk/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/home/visi/Devel/django/djtrunk/django/template/loader_tags.py", line 71, in render
    compiled_parent = self.get_parent(context)
  File "/home/visi/Devel/django/djtrunk/django/template/loader_tags.py", line 66, in get_parent
    raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
TemplateSyntaxError: Template u'base.html' cannot be extended, because it doesn't exist

======================================================================
ERROR: test_form_preview (django.contrib.formtools.tests.PreviewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/tests.py", line 64, in test_form_preview
    response = self.client.post('/test1/', test_data)
  File "/home/visi/Devel/django/djtrunk/django/test/client.py", line 236, in post
    return self.request(**r)
  File "/home/visi/Devel/django/djtrunk/django/core/handlers/base.py", line 82, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/preview.py", line 31, in __call__
    return method(request)
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/preview.py", line 63, in preview_post
    return render_to_response(self.preview_template, context, context_instance=RequestContext(request))
  File "/home/visi/djtrunk/django/shortcuts/__init__.py", line 18, in render_to_response
  File "/home/visi/djtrunk/django/template/loader.py", line 106, in render_to_string
  File "/home/visi/Devel/django/djtrunk/django/test/utils.py", line 21, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/visi/Devel/django/djtrunk/django/template/__init__.py", line 748, in render
    bits.append(self.render_node(node, context))
  File "/home/visi/Devel/django/djtrunk/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/home/visi/Devel/django/djtrunk/django/template/loader_tags.py", line 71, in render
    compiled_parent = self.get_parent(context)
  File "/home/visi/Devel/django/djtrunk/django/template/loader_tags.py", line 66, in get_parent
    raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
TemplateSyntaxError: Template u'base.html' cannot be extended, because it doesn't exist

======================================================================
ERROR: test_form_submit (django.contrib.formtools.tests.PreviewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/tests.py", line 82, in test_form_submit
    response = self.client.post('/test1/', test_data)
  File "/home/visi/Devel/django/djtrunk/django/test/client.py", line 236, in post
    return self.request(**r)
  File "/home/visi/Devel/django/djtrunk/django/core/handlers/base.py", line 82, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/preview.py", line 31, in __call__
    return method(request)
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/preview.py", line 72, in post_post
    return self.failed_hash(request) # Security hash failed.
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/preview.py", line 116, in failed_hash
    return self.preview_post(request)
  File "/home/visi/Devel/django/djtrunk/django/contrib/formtools/preview.py", line 63, in preview_post
    return render_to_response(self.preview_template, context, context_instance=RequestContext(request))
  File "/home/visi/djtrunk/django/shortcuts/__init__.py", line 18, in render_to_response
  File "/home/visi/djtrunk/django/template/loader.py", line 106, in render_to_string
  File "/home/visi/Devel/django/djtrunk/django/test/utils.py", line 21, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/visi/Devel/django/djtrunk/django/template/__init__.py", line 748, in render
    bits.append(self.render_node(node, context))
  File "/home/visi/Devel/django/djtrunk/django/template/debug.py", line 71, in render_node
    result = node.render(context)
  File "/home/visi/Devel/django/djtrunk/django/template/loader_tags.py", line 71, in render
    compiled_parent = self.get_parent(context)
  File "/home/visi/Devel/django/djtrunk/django/template/loader_tags.py", line 66, in get_parent
    raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent
TemplateSyntaxError: Template u'base.html' cannot be extended, because it doesn't exist

----------------------------------------------------------------------
Ran 6 tests in 0.623s

FAILED (errors=3)

Attachments (2)

formtools.diff (1.5 KB) - added by simeon 7 years ago.
Add tests/base.html to templates dir and hacks TEMPLATE_DIRS in testrunner to load
ticket-6644-r8233.diff (1.3 KB) - added by mcroydon 7 years ago.
Updated patch to apply against r8233.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 7 years ago by PJCrosier

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Make sure TEMPLATE_DIRS is setup correctly, I can recreate the output above by purposely breaking my TEMPLATE_DIRS setting.

comment:2 Changed 7 years ago by James Zhu <james@…>

  • Needs documentation set
  • Needs tests set
  • Resolution invalid deleted
  • Status changed from closed to reopened

It seems that formtools tests assume there's a "base.html" in the TEMPLATE_DIRS, which contains a template block named "content". So the tests will fail if your project don't meet such requirements.

comment:3 Changed 7 years ago by Simon Greenhill

  • Triage Stage changed from Unreviewed to Accepted

Can someone write up a patch?

Changed 7 years ago by simeon

Add tests/base.html to templates dir and hacks TEMPLATE_DIRS in testrunner to load

comment:4 Changed 7 years ago by simeon

  • Has patch set
  • Needs tests unset
  • Owner changed from nobody to simeon
  • Status changed from reopened to new

Added patch (as per suggestion by Malcolm during sprint) to hack TEMPLATE_DIRS setting in testrunner only and supply a base.html template for the tests. Still not sure about requiring a base.html with content block, but this patch affects patch only, not the app itself.

comment:5 Changed 7 years ago by simeon

but this patch affects test only, not the app itself...

comment:6 Changed 7 years ago by mcroydon

  • Owner changed from simeon to mcroydon
  • Status changed from new to assigned

Changed 7 years ago by mcroydon

Updated patch to apply against r8233.

comment:7 Changed 7 years ago by mcroydon

  • Owner changed from mcroydon to nobody
  • Status changed from assigned to new

comment:8 Changed 7 years ago by simeon

  • Owner changed from nobody to simeon

comment:9 Changed 4 years ago by julien

  • Type set to Bug

comment:10 Changed 4 years ago by julien

  • Severity set to Normal

comment:11 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [16616]:

Fixed #6644 -- Fixed django.contrib.formtools tests to be better isolated when running outside of the Django test suite. Also moved around the new wizard's templates a bit to better fit the common app layout.

Note: See TracTickets for help on using tickets.
Back to Top