Unit test example for web froms

5 views
Skip to first unread message

Mario Gudelj

unread,
Feb 12, 2012, 2:41:02 AM2/12/12
to django...@googlegroups.com
Hi guys,

I was wandering if anyone has a good example of a unit test where they have a view which processes a web form. I'm not sure how you'd test something like that.

Thanks,

mario

veearrsix

unread,
Feb 12, 2012, 4:31:34 AM2/12/12
to Django users
Coming from a non python/django background (my experience is groovy/
grails), but when we test our controllers (I think this is equivalent
to django views). We simply set up mock params on the request and set
expectations on the controller properties.

Simple example:

given:
request.params = [ param1: 'valid', param2: 'invalid' ]

when:
controller.submit() // the method called when the webform is
posted

then:
controller.hasErrors == true

and:
controller.param2.error == 'this is invalid'

The above example is obviously simplified, but hopefully it shows the
general idea.
Reply all
Reply to author
Forward
0 new messages