blob: 1081a3e6954a273cb48a18c93235847a6c543b87 [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
Matthew Treinish2153ec02013-09-09 20:57:30 +000023from tempest.test import services
Julie Pichond1017642013-07-24 16:37:23 +010024
25
26class TestDashboardBasicOps(manager.OfficialClientTest):
27
28 """
29 This is a basic scenario test:
30 * checks that the login page is available
31 * logs in as a regular user
32 * checks that the user home page loads without error
33 """
34
35 @classmethod
36 def setUpClass(cls):
37 super(TestDashboardBasicOps, cls).setUpClass()
38
39 if not cls.config.service_available.horizon:
40 raise cls.skipException("Horizon support is required")
41
42 def check_login_page(self):
43 response = urllib2.urlopen(self.config.dashboard.dashboard_url)
44 self.assertIn("<h3>Log In</h3>", response.read())
45
46 def user_login(self):
47 self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
48 response = self.opener.open(self.config.dashboard.dashboard_url).read()
49
50 # Grab the CSRF token and default region
51 csrf_token = html.fromstring(response).xpath(
52 '//input[@name="csrfmiddlewaretoken"]/@value')[0]
53 region = html.fromstring(response).xpath(
54 '//input[@name="region"]/@value')[0]
55
56 # Prepare login form request
57 req = urllib2.Request(self.config.dashboard.login_url)
58 req.add_header('Content-type', 'application/x-www-form-urlencoded')
59 req.add_header('Referer', self.config.dashboard.dashboard_url)
60 params = {'username': self.config.identity.username,
61 'password': self.config.identity.password,
62 'region': region,
63 'csrfmiddlewaretoken': csrf_token}
64 self.opener.open(req, urllib.urlencode(params))
65
66 def check_home_page(self):
67 response = self.opener.open(self.config.dashboard.dashboard_url)
68 self.assertIn('Overview', response.read())
69
Matthew Treinish2153ec02013-09-09 20:57:30 +000070 @services('dashboard')
Julie Pichond1017642013-07-24 16:37:23 +010071 def test_basic_scenario(self):
72 self.check_login_page()
73 self.user_login()
74 self.check_home_page()