
This is a patch to start work on re-writing the integration tests using pytest syntax and several improvements, as proposed on the upstream meeting, and summarized at https://etherpad.opendev.org/p/horizon-pytest The new tests are to eventually replace the existing integration tests. At the moment they don't run automatically, you have to explicitly run them using tox or pytest. When the new tests are complete, we will switch to them on the gate. Change-Id: Iea38e4f9771ff3cae7ae8675863e9c488f3f6d8a
91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
from unittest import mock
|
|
import warnings
|
|
|
|
from django.test import testcases
|
|
import pytest
|
|
import requests
|
|
|
|
from keystoneauth1.identity import v3 as v3_auth
|
|
from keystoneclient.v3 import client as client_v3
|
|
from openstack_auth.tests import data_v3
|
|
from openstack_dashboard import api
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def no_warnings():
|
|
warnings.simplefilter("ignore")
|
|
yield
|
|
warnings.simplefilter("default")
|
|
|
|
|
|
@pytest.fixture()
|
|
def auth_data():
|
|
return data_v3.generate_test_data()
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def disable_requests(monkeypatch):
|
|
class MockRequestsSession:
|
|
adapters = []
|
|
|
|
def request(self, *args, **kwargs):
|
|
raise RuntimeError("External request attempted, missed a mock?")
|
|
|
|
monkeypatch.setattr(requests, 'Session', MockRequestsSession)
|
|
# enable request logging
|
|
monkeypatch.setattr(testcases, 'QuietWSGIRequestHandler',
|
|
testcases.WSGIRequestHandler)
|
|
|
|
# prevent pytest-django errors due to no database
|
|
@pytest.fixture()
|
|
def _django_db_helper():
|
|
pass
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_openstack_auth(settings, auth_data):
|
|
with mock.patch.object(client_v3, 'Client') as mock_client, \
|
|
mock.patch.object(v3_auth, 'Token') as mock_token, \
|
|
mock.patch.object(v3_auth, 'Password') as mock_password:
|
|
|
|
keystone_url = settings.OPENSTACK_KEYSTONE_URL
|
|
auth_password = mock.Mock(auth_url=keystone_url)
|
|
mock_password.return_value = auth_password
|
|
auth_password.get_access.return_value = auth_data.unscoped_access_info
|
|
auth_token_unscoped = mock.Mock(auth_url=keystone_url)
|
|
auth_token_scoped = mock.Mock(auth_url=keystone_url)
|
|
mock_token.return_value = auth_token_scoped
|
|
auth_token_unscoped.get_access.return_value = (
|
|
auth_data.federated_unscoped_access_info
|
|
)
|
|
auth_token_scoped.get_access.return_value = (
|
|
auth_data.unscoped_access_info
|
|
)
|
|
client_unscoped = mock.Mock()
|
|
mock_client.return_value = client_unscoped
|
|
projects = [auth_data.project_one, auth_data.project_two]
|
|
client_unscoped.projects.list.return_value = projects
|
|
yield
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_keystoneclient():
|
|
with mock.patch.object(api.keystone, 'keystoneclient') as mock_client:
|
|
keystoneclient = mock_client.return_value
|
|
endpoint_data = mock.Mock()
|
|
endpoint_data.api_version = (3, 10)
|
|
keystoneclient.session.get_endpoint_data.return_value = endpoint_data
|
|
yield
|