Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 7eb4827dc7
Fetching contributors…

Cannot retrieve contributors at this time

76 lines (52 sloc) 1.812 kb


Integration testing views

<!SLIDE antipattern>

@@@ python
url = "/case/edit/{0}".format(
step = case.steps.get()
response =, {
    "description": case.description,
    "steps-TOTAL_FORMS": 2,
    "steps-INITIAL_FORMS": 1,
    "steps-MAX_NUM_FORMS": 3,
    "steps-0-step": step.step,
    "steps-0-expected": step.expected,
    "steps-1-step": "Click link.",
    "steps-1-expected": "Account active.",
    "status": case.status,





@@@ python
url = "/case/edit/{0}".format(
form =["case-form"]
form["steps-1-step"] = "Click link."
form["steps-1-expected"] = "Account active."

response = form.submit()

.notes WebTest parses the form HTML and can submit it like a browser would.

<!SLIDE incremental>

The markup matters.

  • If it can break, it should be tested.
  • It can especially break forms.
  • The output of your view is an HTTP response; the template + context is an implementation detail.

.notes Have to know which markup matters, of course.

<!SLIDE incremental>

WebTest > django.test.Client

  • System tests are easier and faster to write.
  • Tests give you more confidence that the view works.
  • (django-webtest provides integration.)

.notes Django test client is in the "sour spot" - not a unit test, not a full system test. Could gain these features.


@@@ python
   response.json, ["one", "two", "three"])

    resp.html.find("a", title="Login").href,

.notes Automatically parses JSON or HTML responses (BeautifulSoup or lxml).

Jump to Line
Something went wrong with that request. Please try again.