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

« back to all changes in this revision

Viewing changes to benchmarks/test_accessrepositorysite.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
from funkload.Lipsum import Lipsum
 
19
 
 
20
counter = 1
 
21
counter_lock = threading.Lock()
 
22
 
 
23
 
 
24
class AccessRepositorySize(FunkLoadTestCase):
 
25
 
 
26
    def setUp(self):
 
27
        """Setting up test."""
 
28
        self.logd("setUp")
 
29
 
 
30
        self.server_url = self.conf_get('main', 'url')
 
31
        self.username_pattern = self.conf_get("main", "login")
 
32
        self.password = self.conf_get("main", "password")
 
33
 
 
34
        self.ppas_list = self.conf_get("main", "ppas").split()
 
35
 
 
36
        global counter
 
37
        counter_lock.acquire()
 
38
        self.counter = counter
 
39
        counter = counter + 1
 
40
        if counter == 10000:
 
41
            counter = 1
 
42
        counter_lock.release()
 
43
 
 
44
        self.username = self.username_pattern % self.counter
 
45
 
 
46
        self.lipsum = Lipsum()
 
47
 
 
48
    _error_re = re.compile('(?s)class="error message">(.*?)</')
 
49
 
 
50
 
 
51
    def assertNoFormErrors(self, response):
 
52
        self.assertEquals(response.code, 200)
 
53
        match = self._error_re.search(response.body)
 
54
        if match is not None:
 
55
            self.fail('Form contained error "%s"' % match.group(1))
 
56
 
 
57
    def assertLoggedUser(self, response):
 
58
        self.assertEquals(response.code, 200)
 
59
        match = response.body.find('value="Log Out"')
 
60
        if match == -1:
 
61
            self.fail('This user is not logged in.')
 
62
 
 
63
    def absolute_url(self, response, path):
 
64
        """Calculate an absolute URL using the response and the path."""
 
65
        return '%s://%s:%s%s' % (
 
66
            response.protocol, response.server, response.port, path)
 
67
 
 
68
    def login(self):
 
69
        self.logd("logging in as user %s" % self.username)
 
70
 
 
71
        server_url = self.server_url
 
72
 
 
73
        # Get the login page
 
74
        response = self.get(server_url + "/+login", description="GET /")
 
75
        self.assertNoFormErrors(response)
 
76
 
 
77
        # User posts form with username/password.
 
78
        fields = response.extractForm(path=[('form',0)], include_submit=True)
 
79
        fields['loginpage_email'] = self.username
 
80
        fields['loginpage_password'] = self.password
 
81
        response = self.post(
 
82
            self.absolute_url(response, '/+login'),
 
83
            fields, "POST /+login")
 
84
        self.assertNoFormErrors(response)
 
85
 
 
86
        self.assertLoggedUser(response)
 
87
        self.logd("Logged in sucessfully")
 
88
 
 
89
 
 
90
    def test_accessrepositorysize(self):
 
91
        self.logd("access repository size started")
 
92
 
 
93
        server_url = self.server_url
 
94
 
 
95
        self.login()
 
96
 
 
97
        # Get a random ppa page to access
 
98
        ppa = self.ppas_list[randint(0,len(self.ppas_list)-1)]
 
99
 
 
100
        # Go to launchpad.net/ubuntu/serie/+queue
 
101
        response = self.get(server_url + "/~" + ppa +
 
102
                "/+archive/ppa/+repository-size",
 
103
            description="GET /~" + ppa + "/+archive/ppa/+repository-size")
 
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()