Re: Unit Testing forms with hidden fields

2008-12-08 Thread Jason Sidabras

Sounds good. I will probably work with Twill.

Thanks!

On Dec 8, 10:34 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-12-08 at 20:16 -0800, Jason Sidabras wrote:
> > Sorry, I guess I missed that part.
>
> > In my template it checks if there is a user logged in or not. If there
> > is not a user, it defaults the hidden field to send_id=1 and has a
> > form to place an email address. If the user is logged in the template
> > uses the pk_id from the user (in the case of non-admin pk=2 and up)
> > and then places the username a hidden field also.
>
> > So when the send button is pushed it sends both the sender_id="2" (or
> > whichever user) and the username="test_userwith_pk2"
>
> > So when I am testing and I have an anonymous user a simple post will
> > work to test my views, but when the user is logged in data comes from
> > the template so just "post" won't do. I would need to simulate
> > clicking the submit button.
>
> > Twill seems to do this similar to Perl's mechanize module. I am
> > familiar with this 'find forum' submit type of coding but I was
> > wondering if django has a way to grab these hidden fields and place
> > them in the post data when i run a
>
> > c = Client()
> > c.post('/contact-us/', {'some': 'variables' [+ hidden variables from
> > template]})
>
> No, Django's test.client.Client is simulating only the HTTP side of
> things. It doesn't parse any HTML. Twill goes partway by parsing the
> HTML, but then if you have modifications made by other purposes (e.g.
> Javascript, it doesn't pick those up). Short of using a web browser (the
> Selenium approach), there isn't an ideal way here.
>
> Probably wouldn't be too hard to write a subclass that did twill-like
> parsing (even using Twill) if you were sufficiently motivated.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Unit Testing forms with hidden fields

2008-12-08 Thread Malcolm Tredinnick


On Mon, 2008-12-08 at 20:16 -0800, Jason Sidabras wrote:
> Sorry, I guess I missed that part.
> 
> In my template it checks if there is a user logged in or not. If there
> is not a user, it defaults the hidden field to send_id=1 and has a
> form to place an email address. If the user is logged in the template
> uses the pk_id from the user (in the case of non-admin pk=2 and up)
> and then places the username a hidden field also.
> 
> So when the send button is pushed it sends both the sender_id="2" (or
> whichever user) and the username="test_userwith_pk2"
> 
> So when I am testing and I have an anonymous user a simple post will
> work to test my views, but when the user is logged in data comes from
> the template so just "post" won't do. I would need to simulate
> clicking the submit button.
> 
> Twill seems to do this similar to Perl's mechanize module. I am
> familiar with this 'find forum' submit type of coding but I was
> wondering if django has a way to grab these hidden fields and place
> them in the post data when i run a
> 
> c = Client()
> c.post('/contact-us/', {'some': 'variables' [+ hidden variables from
> template]})

No, Django's test.client.Client is simulating only the HTTP side of
things. It doesn't parse any HTML. Twill goes partway by parsing the
HTML, but then if you have modifications made by other purposes (e.g.
Javascript, it doesn't pick those up). Short of using a web browser (the
Selenium approach), there isn't an ideal way here.

Probably wouldn't be too hard to write a subclass that did twill-like
parsing (even using Twill) if you were sufficiently motivated.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Unit Testing forms with hidden fields

2008-12-08 Thread Jason Sidabras

Sorry, I guess I missed that part.

In my template it checks if there is a user logged in or not. If there
is not a user, it defaults the hidden field to send_id=1 and has a
form to place an email address. If the user is logged in the template
uses the pk_id from the user (in the case of non-admin pk=2 and up)
and then places the username a hidden field also.

So when the send button is pushed it sends both the sender_id="2" (or
whichever user) and the username="test_userwith_pk2"

So when I am testing and I have an anonymous user a simple post will
work to test my views, but when the user is logged in data comes from
the template so just "post" won't do. I would need to simulate
clicking the submit button.

Twill seems to do this similar to Perl's mechanize module. I am
familiar with this 'find forum' submit type of coding but I was
wondering if django has a way to grab these hidden fields and place
them in the post data when i run a

c = Client()
c.post('/contact-us/', {'some': 'variables' [+ hidden variables from
template]})

Thanks.

Jason

On Dec 8, 6:54 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Mon, 2008-12-08 at 15:00 -0800, Jason Sidabras wrote:
> > Hello,
>
> > I am working on adding unit testing to my code and the snag I have
> > come across is in regards to unit fields.
>
> > When user.is_anonymous() I have a hidden field sender_id = 1 which is
> > easy to test by:
>
> > from django.test.client import Client
>
> > c = Client()
> > c.post('sender_id': '1', 'post', '')
>
> > but when setting up unit tests for the form when a user is logged in,
> > I am not clear on how to use the hidden fields.
>
> What do you mean by "how to use"? Hidden fields are just form variables.
> The 'hidden' designation is only relevant for a web browser displaying
> the data. You just submit values normally in your tests.
>
> Could you explain what you are getting stuck on here? How does the
> logged in situation differ from the non-logged-in case?
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Unit Testing forms with hidden fields

2008-12-08 Thread Malcolm Tredinnick


On Mon, 2008-12-08 at 15:00 -0800, Jason Sidabras wrote:
> Hello,
> 
> I am working on adding unit testing to my code and the snag I have
> come across is in regards to unit fields.
> 
> When user.is_anonymous() I have a hidden field sender_id = 1 which is
> easy to test by:
> 
> from django.test.client import Client
> 
> c = Client()
> c.post('sender_id': '1', 'post', '')
> 
> but when setting up unit tests for the form when a user is logged in,
> I am not clear on how to use the hidden fields.

What do you mean by "how to use"? Hidden fields are just form variables.
The 'hidden' designation is only relevant for a web browser displaying
the data. You just submit values normally in your tests.

Could you explain what you are getting stuck on here? How does the
logged in situation differ from the non-logged-in case?

Regards,
Malcolm



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---