callable(fudge.Fake()) returns true even without using is_callable()

Create issue
Issue #15 new
cburgmer created an issue

I am using fudge to test Django templates. I am faking model instances like this:

{{{

instance = (fudge.Fake('page') ... .has_attr(pk='test title') ... .has_attr(content='test content')) }}} The Django template code does some magic, and while it tries to guess parameters specified in templates, this fake object fails:

{{{ Traceback (most recent call last): File "/tmp/django-wikify/example/wikify/tests.py", line 156, in test_version_template_has_user_of_last_change response = render(request, self.template, context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/shortcuts/init.py", line 44, in render return HttpResponse(loader.render_to_string(args, *kwargs), File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/loader.py", line 188, in render_to_string return t.render(context_instance) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/base.py", line 123, in render return self._render(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/test/utils.py", line 57, in instrumented_test_render return self.nodelist.render(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render bits.append(self.render_node(node, context)) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/debug.py", line 73, in render_node result = node.render(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/loader_tags.py", line 127, in render return compiled_parent._render(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/test/utils.py", line 57, in instrumented_test_render return self.nodelist.render(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render bits.append(self.render_node(node, context)) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/debug.py", line 73, in render_node result = node.render(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/loader_tags.py", line 64, in render result = block.nodelist.render(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/base.py", line 744, in render bits.append(self.render_node(node, context)) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/debug.py", line 73, in render_node result = node.render(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/debug.py", line 90, in render output = self.filter_expression.resolve(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/base.py", line 510, in resolve obj = self.var.resolve(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/base.py", line 653, in resolve value = self._resolve_lookup(context) File "/tmp/django-wikify/env/lib/python2.7/site-packages/django/template/base.py", line 698, in _resolve_lookup current = current() File "/tmp/django-wikify/env/lib/python2.7/site-packages/fudge/init.py", line 671, in call "%s.is_callable() ?)" % (self, self.class.name)) TemplateSyntaxError: Caught RuntimeError while rendering: fake:revision object cannot be called (maybe you want Fake.is_callable() ?) }}}

A quick workaround is making the fake callable returning itself: {{{

fake_revision.is_callable().returns(fake_revision) }}}

Django might be trying to be overly smart, however I believe there are valid cases where one would want to test callable() (or now {{{ hasattr(instance, 'call') }}} ), so I would like Fudge to accommodate for that.

Comments (1)

  1. Log in to comment