blob: 4fcc70a8fc8566020e069af221e3036633c8bbd6 [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
37 def setUpClass(cls):
Sylvain Afchain92064772014-01-16 02:45:57 +010038 cls.set_network_resources()
Julie Pichond1017642013-07-24 16:37:23 +010039 super(TestDashboardBasicOps, cls).setUpClass()
40
Matthew Treinish6c072292014-01-29 19:15:52 +000041 if not CONF.service_available.horizon:
Julie Pichond1017642013-07-24 16:37:23 +010042 raise cls.skipException("Horizon support is required")
43
44 def check_login_page(self):
Matthew Treinish6c072292014-01-29 19:15:52 +000045 response = urllib2.urlopen(CONF.dashboard.dashboard_url)
Julie Pichond1017642013-07-24 16:37:23 +010046 self.assertIn("<h3>Log In</h3>", response.read())
47
48 def user_login(self):
49 self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
Matthew Treinish6c072292014-01-29 19:15:52 +000050 response = self.opener.open(CONF.dashboard.dashboard_url).read()
Julie Pichond1017642013-07-24 16:37:23 +010051
52 # Grab the CSRF token and default region
53 csrf_token = html.fromstring(response).xpath(
54 '//input[@name="csrfmiddlewaretoken"]/@value')[0]
55 region = html.fromstring(response).xpath(
56 '//input[@name="region"]/@value')[0]
57
58 # Prepare login form request
Matthew Treinish6c072292014-01-29 19:15:52 +000059 req = urllib2.Request(CONF.dashboard.login_url)
Julie Pichond1017642013-07-24 16:37:23 +010060 req.add_header('Content-type', 'application/x-www-form-urlencoded')
Matthew Treinish6c072292014-01-29 19:15:52 +000061 req.add_header('Referer', CONF.dashboard.dashboard_url)
62 params = {'username': CONF.identity.username,
63 'password': CONF.identity.password,
Julie Pichond1017642013-07-24 16:37:23 +010064 'region': region,
65 'csrfmiddlewaretoken': csrf_token}
66 self.opener.open(req, urllib.urlencode(params))
67
68 def check_home_page(self):
Matthew Treinish6c072292014-01-29 19:15:52 +000069 response = self.opener.open(CONF.dashboard.dashboard_url)
Julie Pichond1017642013-07-24 16:37:23 +010070 self.assertIn('Overview', response.read())
71
Masayuki Igawa4ded9f02014-02-17 15:05:59 +090072 @test.services('dashboard')
Julie Pichond1017642013-07-24 16:37:23 +010073 def test_basic_scenario(self):
74 self.check_login_page()
75 self.user_login()
76 self.check_home_page()