Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 1 | # 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 | |
| 15 | import urllib |
| 16 | import urllib2 |
| 17 | |
| 18 | from lxml import html |
| 19 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 20 | from tempest import config |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 21 | from tempest.scenario import manager |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 22 | from tempest import test |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 23 | |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 24 | CONF = config.CONF |
| 25 | |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 26 | |
Masayuki Igawa | 2675f8f | 2014-07-17 13:46:26 +0200 | [diff] [blame] | 27 | class TestDashboardBasicOps(manager.ScenarioTest): |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 28 | |
| 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 Frittoli | ac20b5e | 2014-09-15 13:31:14 +0100 | [diff] [blame] | 37 | def resource_setup(cls): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 38 | if not CONF.service_available.horizon: |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 39 | raise cls.skipException("Horizon support is required") |
Masayuki Igawa | 60ea6c5 | 2014-10-15 17:32:14 +0900 | [diff] [blame] | 40 | cls.set_network_resources() |
| 41 | super(TestDashboardBasicOps, cls).resource_setup() |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 42 | |
| 43 | def check_login_page(self): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 44 | response = urllib2.urlopen(CONF.dashboard.dashboard_url) |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 45 | self.assertIn("<h3>Log In</h3>", response.read()) |
| 46 | |
| 47 | def user_login(self): |
| 48 | self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 49 | response = self.opener.open(CONF.dashboard.dashboard_url).read() |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 50 | |
| 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 Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 58 | req = urllib2.Request(CONF.dashboard.login_url) |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 59 | req.add_header('Content-type', 'application/x-www-form-urlencoded') |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 60 | req.add_header('Referer', CONF.dashboard.dashboard_url) |
| 61 | params = {'username': CONF.identity.username, |
| 62 | 'password': CONF.identity.password, |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 63 | 'region': region, |
| 64 | 'csrfmiddlewaretoken': csrf_token} |
| 65 | self.opener.open(req, urllib.urlencode(params)) |
| 66 | |
| 67 | def check_home_page(self): |
Matthew Treinish | 6c07229 | 2014-01-29 19:15:52 +0000 | [diff] [blame] | 68 | response = self.opener.open(CONF.dashboard.dashboard_url) |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 69 | self.assertIn('Overview', response.read()) |
| 70 | |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 71 | @test.services('dashboard') |
Julie Pichon | d101764 | 2013-07-24 16:37:23 +0100 | [diff] [blame] | 72 | def test_basic_scenario(self): |
| 73 | self.check_login_page() |
| 74 | self.user_login() |
| 75 | self.check_home_page() |