Re: TestClient assertFormError method.

2008-02-22 Thread Russell Keith-Magee

On Sat, Feb 23, 2008 at 9:43 AM, Ian Macdonald <[EMAIL PROTECTED]> wrote:
>
> If I separate the form out from the dictionary however, the test
> works, so it appears that it's the secondary lookup that this
> assertion cannot handle. Does anyone know if that's correct, and/or if
> there's a work-around or something I'm doing wrong?

You've pretty much identified the problem: assertFormError doesn't
expand context dot notation in the same way that templates do. The
name that is provided to the second argument of assertFormError is
used directly as a key on the top level of the context dictionary.This
also yields the immediate workaround - put the form in the top level
of the context.

There is some merit to the suggestion that the dot notation should be
expanded in this case. Feel free to open a ticket to suggest this
enhancement. If you're feeling particularly enthusiastic, the
definition for assertFormError is in
django/trunk/django/test/testcases.py; adding this functionality
shouldn't be too difficult (remembering that the dot notation can
represent a number of possible lookup alternatives).

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



TestClient assertFormError method.

2008-02-22 Thread Ian Macdonald

I'm fairly new to Django, but seem to be getting the hang of it.

I do have a small issue that's been bugging me a bit with the test  
client: I've been writing tests for a form on a small site using the  
TestClient. When I test for invalid data in the form I'm getting odd  
errors. The problem seems to be that I'm passing the form to the  
template in a dictionary, like so:

context['feedback'] = {
   'form' : ContactUsForm(),
   'message' : "Thanks for the feedback!",
   'with_email' : True
}

The template adds the message and does a bit of special processing if  
the 'with_email' key is set, but nothing fancy.
When I try and run the following line in a test though

self.assertFormError(response, 'feedback.form', 'reply_to', [u"Enter a  
valid e-mail address."])

I get this error
  "AssertionError: The form 'contactus.form' was not used to render  
the response"

I tried different approaches to the form name ('form' or 'contactus')  
but each generated an error

If I separate the form out from the dictionary however, the test  
works, so it appears that it's the secondary lookup that this  
assertion cannot handle. Does anyone know if that's correct, and/or if  
there's a work-around or something I'm doing wrong? I'd rather not  
take apart the dictionary just for the sake of getting the tests to  
run (that seems a bit backward) but I also really like having a test  
suite I can rely on.

Any ideas or suggestions greatly appreciated.
Thanks

Ian.
  

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---