Re: How can I print form errors from inside the test

2012-03-15 Thread Mario Gudelj
All I had to do is to change initial=base_data to data=base_data and the
thing worked. is_valid() and is_bound now work.

Cheers,

-m

On 15 March 2012 12:20, Daniel Roseman  wrote:

> On Wednesday, 14 March 2012 16:43:12 UTC-7, somecallitblues wrote:
>>
>> Thanks Daniel and Karen,
>>
>> Karen, I;'m not entirely sure what an unbound form is. :)
>>
>
> Then you must not have read the documentation[1], which goes into great
> detail about bound and unbound forms. That's pretty much a prerequisite
> before asking for help, I'm afraid.
>
>
>>
>> Anyway, this is my test code:
>>
>> def test_appointment_form(self):
>>
>> c = Client()
>>
>> base_data = {
>> 'name':'Foo name',
>> 'slug':'foo-session',
>> 'short_descr':'foo tagline',
>> 'long_descr':'long foo description',
>> 'staff':self.staff,
>> 'business':self.business,
>> 'start_date':'2012-07-24',
>> 'end_date':'2012-07-24',
>> }
>> self.form = AppointmentForm(business=self.**
>> business,staff=self.staff,**initial=base_data)
>>
>
> As that documentation points out, `initial` does not bind the form.
>
>
>> self.failUnless(self.form.is_**valid()) #< This fails
>>
>> print self.form.errors #>
>> response = c.post('/console/appointments/**add',
>> {'form':self.form})
>>
>
> Not the cause of your current problem, but this makes no sense: you can't
> POST a form object.
>
>  [1]:
> https://docs.djangoproject.com/en/1.3/topics/forms/#using-a-form-in-a-view
>
> --
> DR.
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/r8lcpGOgA5gJ.
>
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How can I print form errors from inside the test

2012-03-14 Thread Daniel Roseman
On Wednesday, 14 March 2012 16:43:12 UTC-7, somecallitblues wrote:
>
> Thanks Daniel and Karen,
>
> Karen, I;'m not entirely sure what an unbound form is. :)
>

Then you must not have read the documentation[1], which goes into great 
detail about bound and unbound forms. That's pretty much a prerequisite 
before asking for help, I'm afraid.
 

>
> Anyway, this is my test code:
>
> def test_appointment_form(self):
>
> c = Client()
>
> base_data = {
> 'name':'Foo name',
> 'slug':'foo-session',
> 'short_descr':'foo tagline',
> 'long_descr':'long foo description',
> 'staff':self.staff,
> 'business':self.business,
> 'start_date':'2012-07-24',
> 'end_date':'2012-07-24',
> }
> self.form = 
> AppointmentForm(business=self.business,staff=self.staff,initial=base_data)
>

As that documentation points out, `initial` does not bind the form.
 

> self.failUnless(self.form.is_valid()) #< This fails
>
> print self.form.errors #
> response = c.post('/console/appointments/add', {'form':self.form})
>

Not the cause of your current problem, but this makes no sense: you can't 
POST a form object.

 [1]: https://docs.djangoproject.com/en/1.3/topics/forms/#using-a-form-in-a-view

--
DR.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/r8lcpGOgA5gJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How can I print form errors from inside the test

2012-03-14 Thread Mario Gudelj
Thanks Daniel and Karen,

Karen, I;'m not entirely sure what an unbound form is. :)

Anyway, this is my test code:

def test_appointment_form(self):

c = Client()

base_data = {
'name':'Foo name',
'slug':'foo-session',
'short_descr':'foo tagline',
'long_descr':'long foo description',
'staff':self.staff,
'business':self.business,
'start_date':'2012-07-24',
'end_date':'2012-07-24',
}
self.form =
AppointmentForm(business=self.business,staff=self.staff,initial=base_data)

self.failUnless(self.form.is_valid()) #< This fails

print self.form.errors # wrote:

> The most common reason I have seen for is_valid() to return False but
> errors to be empty is for the form to be unbound. Unbound forms are
> never valid, but they also don't have any errors. Which goes to
> Daniel's question: how exactly have you "preloaded" the form with
> data?
>
> Karen
> --
> http://tracey.org/kmt/
>
> --
> 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
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How can I print form errors from inside the test

2012-03-14 Thread Karen Tracey
The most common reason I have seen for is_valid() to return False but
errors to be empty is for the form to be unbound. Unbound forms are
never valid, but they also don't have any errors. Which goes to
Daniel's question: how exactly have you "preloaded" the form with
data?

Karen
-- 
http://tracey.org/kmt/

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: How can I print form errors from inside the test

2012-03-13 Thread Daniel Roseman
On Tuesday, 13 March 2012 19:06:13 UTC-7, somecallitblues wrote:
>
> I preload the data into the form and when I validate it returns False.
>
>
*How* do you "preload" the data? How do you validate it?
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/fgnY0UjeJSQJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How can I print form errors from inside the test

2012-03-13 Thread Mario Gudelj
Hi djangoers,

I have a problem where I'm running some form tests, the form validation is
failing, and I'm not sure why it's failing and I can't figure out how to
print the errors.

I preload the data into the form and when I validate it returns False.

>>> form.is_valid()
False

If I print the form and look at the HTML code everything looks fine as it
would on the front end

>>> print form

But if I try

>>> print form.errors

I get nothing.

I also tried all individual files with

>>> print form['is_recur'].errors

and I still get nothing.

There are no custom validation functions in this form, so I really don't
knoyw why it wouldn't validate.

Any help will be greatly appreciated.

Thanks!

-m

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.