blob: 9a4557293666822ca1dd63ef34ac0044a842b9af [file] [log] [blame]
Julie Pichond1017642013-07-24 16:37:23 +01001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17import urllib
18import urllib2
19
20from lxml import html
21
22from tempest.scenario import manager
23
24
25class TestDashboardBasicOps(manager.OfficialClientTest):
26
27 """
28 This is a basic scenario test:
29 * checks that the login page is available
30 * logs in as a regular user
31 * checks that the user home page loads without error
32 """
33
34 @classmethod
35 def setUpClass(cls):
36 super(TestDashboardBasicOps, cls).setUpClass()
37
38 if not cls.config.service_available.horizon:
39 raise cls.skipException("Horizon support is required")
40
41 def check_login_page(self):
42 response = urllib2.urlopen(self.config.dashboard.dashboard_url)
43 self.assertIn("<h3>Log In</h3>", response.read())
44
45 def user_login(self):
46 self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
47 response = self.opener.open(self.config.dashboard.dashboard_url).read()
48
49 # Grab the CSRF token and default region
50 csrf_token = html.fromstring(response).xpath(
51 '//input[@name="csrfmiddlewaretoken"]/@value')[0]
52 region = html.fromstring(response).xpath(
53 '//input[@name="region"]/@value')[0]
54
55 # Prepare login form request
56 req = urllib2.Request(self.config.dashboard.login_url)
57 req.add_header('Content-type', 'application/x-www-form-urlencoded')
58 req.add_header('Referer', self.config.dashboard.dashboard_url)
59 params = {'username': self.config.identity.username,
60 'password': self.config.identity.password,
61 'region': region,
62 'csrfmiddlewaretoken': csrf_token}
63 self.opener.open(req, urllib.urlencode(params))
64
65 def check_home_page(self):
66 response = self.opener.open(self.config.dashboard.dashboard_url)
67 self.assertIn('Overview', response.read())
68
69 def test_basic_scenario(self):
70 self.check_login_page()
71 self.user_login()
72 self.check_home_page()