~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to benchmarks/test_auth.py

  • Committer: Ursula Junque
  • Date: 2009-08-07 05:44:55 UTC
  • mto: This revision was merged to the branch mainline in revision 9077.
  • Revision ID: ursinha@canonical.com-20090807054455-cn2t968h3l382b05
Adding the functions that actually do the test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
        self.logd("setUp")
21
21
        self.server_url = self.conf_get('main', 'url')
22
22
 
23
 
        _error_re = re.compile('(?s)class="error message">(.*?)</')
 
23
    _error_re = re.compile('(?s)class="error message">(.*?)</')
 
24
 
 
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)
 
29
        if match is not None:
 
30
            self.fail('Form contained error: %s' % match.group(1))
24
31
 
25
32
    def test_auth(self):
26
33
        """Runs the steps of a simple Launchpad login."""
27
 
        pass
 
34
 
 
35
        server_url = self.server_url
 
36
 
 
37
        # Get the login page
 
38
        response = self.get(server_url + "/+login", description="GET /+login")
 
39
        self.assertNoFormErrors(response)
 
40
 
 
41
        # The credentials of foo user, the loginator
 
42
        email = 'foo@mailinator.com'
 
43
        password = 'test'
 
44
 
 
45
        # Get only the first form of the page, the login one,
 
46
        # and fill it
 
47
        fields = response.extractForm(path=[('form',0)], include_submit=True)
 
48
        fields['loginpage_email'] = email
 
49
        fields['loginpage_password'] = password
 
50
 
 
51
        # Submit the login form.
 
52
        response = self.post(
 
53
            self.absolute_url(response, '/+login'),
 
54
            fields, "POST /+login")
 
55
        self.assertNoFormErrors(response)
 
56
 
 
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)
28
61
 
29
62
    def tearDown(self):
30
63
        """Finishes the test."""
31
 
        pass
 
64
        self.logd("tearDown.\n")
32
65
 
33
66
 
34
67
if __name__ in ('main', '__main__'):