Webtests now correctly follow responses

`maybe_follow` does not fail the test if the response isn't a redirect.
The webtests were changed to use `follow` instead, which correctly fails the test if the response can't be followed. This meant that the login test didn't fail if the form failed to validate or submit.
master
Nick Johnstone 11 years ago
parent 2344a88650
commit 831705d3c2
  1. 8
      {{cookiecutter.app_name}}/{{cookiecutter.app_name}}/tests/webtest_tests.py

@ -27,7 +27,7 @@ class TestLoggingIn(DbTestCase):
form['username'] = self.user.username form['username'] = self.user.username
form['password'] = 'myprecious' form['password'] = 'myprecious'
# Submits # Submits
res = form.submit().maybe_follow() res = form.submit().follow()
assert_equal(res.status_code, 200) assert_equal(res.status_code, 200)
def _login(self, username, password): def _login(self, username, password):
@ -37,12 +37,12 @@ class TestLoggingIn(DbTestCase):
form['username'] = username form['username'] = username
form['password'] = password form['password'] = password
# Submits # Submits
res = form.submit().maybe_follow() res = form.submit().follow()
return res return res
def test_sees_alert_on_log_out(self): def test_sees_alert_on_log_out(self):
res = self._login(self.user.username, 'myprecious') res = self._login(self.user.username, 'myprecious')
res = self.w.get(url_for('public.logout')).maybe_follow() res = self.w.get(url_for('public.logout')).follow()
# sees alert # sees alert
assert_in('You are logged out.', res) assert_in('You are logged out.', res)
@ -88,7 +88,7 @@ class TestRegistering(DbTestCase):
form['password'] = 'secret' form['password'] = 'secret'
form['confirm'] = 'secret' form['confirm'] = 'secret'
# Submits # Submits
res = form.submit().maybe_follow() res = form.submit().follow()
assert_equal(res.status_code, 200) assert_equal(res.status_code, 200)
# A new user was created # A new user was created
assert_equal(len(User.query.all()), 1) assert_equal(len(User.query.all()), 1)

Loading…
Cancel
Save