blob: 98efcfbbbf754afe52bf8688cfc1b01ea0ed2e58 [file] [log] [blame]
Julie Pichond1017642013-07-24 16:37:23 +01001# All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import urllib
16import urllib2
17
18from lxml import html
19
20from tempest.scenario import manager
Matthew Treinish2153ec02013-09-09 20:57:30 +000021from tempest.test import services
Julie Pichond1017642013-07-24 16:37:23 +010022
23
24class TestDashboardBasicOps(manager.OfficialClientTest):
25
26 """
27 This is a basic scenario test:
28 * checks that the login page is available
29 * logs in as a regular user
30 * checks that the user home page loads without error
31 """
32
33 @classmethod
34 def setUpClass(cls):
Sylvain Afchain92064772014-01-16 02:45:57 +010035 cls.set_network_resources()
Julie Pichond1017642013-07-24 16:37:23 +010036 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
Matthew Treinish2153ec02013-09-09 20:57:30 +000069 @services('dashboard')
Julie Pichond1017642013-07-24 16:37:23 +010070 def test_basic_scenario(self):
71 self.check_login_page()
72 self.user_login()
73 self.check_home_page()