~ursinha/launchpad/add-all-fl-tests

« back to all changes in this revision

Viewing changes to benchmarks/test_accesspackagequeue.py

  • Committer: Ursula Junque
  • Date: 2009-08-20 21:46:15 UTC
  • Revision ID: ursinha@canonical.com-20090820214615-17bktuq6qu7e1qbw
Adding fl tests: soyuz package queue and repository size 'applet' and browsing a bug flow.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2009 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Access ubuntu/karmic/+queue test."""
 
5
 
 
6
__metaclass__ = type
 
7
__all__ = []
 
8
 
 
9
import cgi
 
10
import re
 
11
import threading
 
12
import unittest
 
13
import urllib
 
14
import urllib2
 
15
from random import randint
 
16
 
 
17
from funkload.FunkLoadTestCase import FunkLoadTestCase
 
18
 
 
19
counter = 1
 
20
counter_lock = threading.Lock()
 
21
 
 
22
 
 
23
class AccessPackageQueue(FunkLoadTestCase):
 
24
 
 
25
    def setUp(self):
 
26
        """Setting up test."""
 
27
        self.logd("setUp")
 
28
 
 
29
        self.server_url = self.conf_get('main', 'url')
 
30
        self.username_pattern = self.conf_get("main", "login")
 
31
        self.password = self.conf_get("main", "password")
 
32
 
 
33
        self.series_list = self.conf_get("main", "series").split()
 
34
 
 
35
        global counter
 
36
        counter_lock.acquire()
 
37
        self.counter = counter
 
38
        counter = counter + 1
 
39
        if counter == 10000:
 
40
            counter = 1
 
41
        counter_lock.release()
 
42
 
 
43
        self.username = self.username_pattern % self.counter
 
44
 
 
45
    _error_re = re.compile('(?s)class="error message">(.*?)</')
 
46
 
 
47
 
 
48
    def assertNoFormErrors(self, response):
 
49
        self.assertEquals(response.code, 200)
 
50
        match = self._error_re.search(response.body)
 
51
        if match is not None:
 
52
            self.fail('Form contained error "%s"' % match.group(1))
 
53
 
 
54
    def assertLoggedUser(self, response):
 
55
        self.assertEquals(response.code, 200)
 
56
        match = response.body.find('value="Log Out"')
 
57
        if match == -1:
 
58
            self.fail('This user is not logged in.')
 
59
 
 
60
    def absolute_url(self, response, path):
 
61
        """Calculate an absolute URL using the response and the path."""
 
62
        return '%s://%s:%s%s' % (
 
63
            response.protocol, response.server, response.port, path)
 
64
 
 
65
    def login(self):
 
66
        self.logd("logging in as user %s" % self.username)
 
67
 
 
68
        server_url = self.server_url
 
69
 
 
70
        # Get the login page
 
71
        response = self.get(server_url + "/+login", description="GET /")
 
72
        self.assertNoFormErrors(response)
 
73
 
 
74
        # User posts form with username/password.
 
75
        fields = response.extractForm(path=[('form',0)], include_submit=True)
 
76
        fields['loginpage_email'] = self.username
 
77
        fields['loginpage_password'] = self.password
 
78
        response = self.post(
 
79
            self.absolute_url(response, '/+login'),
 
80
            fields, "POST /+login")
 
81
        self.assertNoFormErrors(response)
 
82
 
 
83
        self.assertLoggedUser(response)
 
84
        self.logd("Logged in sucessfully")
 
85
 
 
86
 
 
87
    def test_accesspackagequeue(self):
 
88
        self.logd("access code started")
 
89
 
 
90
        server_url = self.server_url
 
91
 
 
92
        try:
 
93
            self.login()
 
94
        except Exception, e:
 
95
            print e
 
96
            self.fail(e)
 
97
 
 
98
        # Get a random serie to access
 
99
        series = self.series_list[randint(0,len(self.series_list)-1)]
 
100
 
 
101
        # Go to launchpad.net/ubuntu/serie/+queue
 
102
        response = self.get(server_url + "/ubuntu/" + series + "/+queue",
 
103
            description="GET /ubuntu/" + series + "/+queue")
 
104
        self.assertNoFormErrors(response)
 
105
 
 
106
        self.logd("access +queue completed successfully")
 
107
 
 
108
    def tearDown(self):
 
109
        """Setting up test."""
 
110
        self.logd("tearDown.\n")
 
111
 
 
112
 
 
113
if __name__ in ('main', '__main__'):
 
114
    unittest.main()