blob: 875a1d98be1ddf723d4dc54119490f2819bb1068 [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
Matthew Treinish6c072292014-01-29 19:15:52 +000020from tempest import config
Julie Pichond1017642013-07-24 16:37:23 +010021from tempest.scenario import manager
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090022from tempest import test
Julie Pichond1017642013-07-24 16:37:23 +010023
Matthew Treinish6c072292014-01-29 19:15:52 +000024CONF = config.CONF
25
Julie Pichond1017642013-07-24 16:37:23 +010026
Masayuki Igawa2675f8f2014-07-17 13:46:26 +020027class TestDashboardBasicOps(manager.ScenarioTest):
Julie Pichond1017642013-07-24 16:37:23 +010028
29 """
30 This is a basic scenario test:
31 * checks that the login page is available
32 * logs in as a regular user
33 * checks that the user home page loads without error
34 """
35
36 @classmethod
Andrea Frittoliac20b5e2014-09-15 13:31:14 +010037 def resource_setup(cls):
Matthew Treinish6c072292014-01-29 19:15:52 +000038 if not CONF.service_available.horizon:
Julie Pichond1017642013-07-24 16:37:23 +010039 raise cls.skipException("Horizon support is required")
Masayuki Igawa60ea6c52014-10-15 17:32:14 +090040 cls.set_network_resources()
41 super(TestDashboardBasicOps, cls).resource_setup()
Julie Pichond1017642013-07-24 16:37:23 +010042
43 def check_login_page(self):
Matthew Treinish6c072292014-01-29 19:15:52 +000044 response = urllib2.urlopen(CONF.dashboard.dashboard_url)
Julie Pichond1017642013-07-24 16:37:23 +010045 self.assertIn("<h3>Log In</h3>", response.read())
46
47 def user_login(self):
48 self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
Matthew Treinish6c072292014-01-29 19:15:52 +000049 response = self.opener.open(CONF.dashboard.dashboard_url).read()
Julie Pichond1017642013-07-24 16:37:23 +010050
51 # Grab the CSRF token and default region
52 csrf_token = html.fromstring(response).xpath(
53 '//input[@name="csrfmiddlewaretoken"]/@value')[0]
54 region = html.fromstring(response).xpath(
55 '//input[@name="region"]/@value')[0]
56
57 # Prepare login form request
Matthew Treinish6c072292014-01-29 19:15:52 +000058 req = urllib2.Request(CONF.dashboard.login_url)
Julie Pichond1017642013-07-24 16:37:23 +010059 req.add_header('Content-type', 'application/x-www-form-urlencoded')
Matthew Treinish6c072292014-01-29 19:15:52 +000060 req.add_header('Referer', CONF.dashboard.dashboard_url)
61 params = {'username': CONF.identity.username,
62 'password': CONF.identity.password,
Julie Pichond1017642013-07-24 16:37:23 +010063 'region': region,
64 'csrfmiddlewaretoken': csrf_token}
65 self.opener.open(req, urllib.urlencode(params))
66
67 def check_home_page(self):
Matthew Treinish6c072292014-01-29 19:15:52 +000068 response = self.opener.open(CONF.dashboard.dashboard_url)
Julie Pichond1017642013-07-24 16:37:23 +010069 self.assertIn('Overview', response.read())
70
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090071 @test.services('dashboard')
Julie Pichond1017642013-07-24 16:37:23 +010072 def test_basic_scenario(self):
73 self.check_login_page()
74 self.user_login()
75 self.check_home_page()