21
21
self.server_url = self.conf_get('main', 'url')
23
_error_re = re.compile('(?s)class="error message">(.*?)</')
23
_error_re = re.compile('(?s)class="error message">(.*?)</')
25
def assertNoFormErrors(self, response):
26
"""Checks if the page returned ok and the login was sucessful."""
27
self.assertEquals(response.code, 200)
28
match = self._error_re.search(response.body)
30
self.fail('Form contained error: %s' % match.group(1))
25
32
def test_auth(self):
26
33
"""Runs the steps of a simple Launchpad login."""
35
server_url = self.server_url
38
response = self.get(server_url + "/+login", description="GET /+login")
39
self.assertNoFormErrors(response)
41
# The credentials of foo user, the loginator
42
email = 'foo@mailinator.com'
45
# Get only the first form of the page, the login one,
47
fields = response.extractForm(path=[('form',0)], include_submit=True)
48
fields['loginpage_email'] = email
49
fields['loginpage_password'] = password
51
# Submit the login form.
53
self.absolute_url(response, '/+login'),
54
fields, "POST /+login")
55
self.assertNoFormErrors(response)
57
def absolute_url(self, response, path):
58
"""Calculate an absolute URL using the response and the path."""
59
return '%s://%s:%s%s' % (
60
response.protocol, response.server, response.port, path)
29
62
def tearDown(self):
30
63
"""Finishes the test."""
64
self.logd("tearDown.\n")
34
67
if __name__ in ('main', '__main__'):