Add user login mocking to the pytest UI tests
This way we can run the tests in any order. Change-Id: Ifdc89b650540cc632f7c6ec2005a429b89a5b9f0
This commit is contained in:
parent
d42e40ab30
commit
d2af1e6e1a
@ -19,22 +19,35 @@ import requests
|
|||||||
|
|
||||||
from keystoneauth1.identity import v3 as v3_auth
|
from keystoneauth1.identity import v3 as v3_auth
|
||||||
from keystoneclient.v3 import client as client_v3
|
from keystoneclient.v3 import client as client_v3
|
||||||
|
import openstack_auth
|
||||||
from openstack_auth.tests import data_v3
|
from openstack_auth.tests import data_v3
|
||||||
|
from openstack_auth import utils as auth_utils
|
||||||
from openstack_dashboard import api
|
from openstack_dashboard import api
|
||||||
|
from openstack_dashboard.test.test_data import utils as test_utils
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True, scope='session')
|
||||||
def no_warnings():
|
def no_warnings():
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
yield
|
yield
|
||||||
warnings.simplefilter("default")
|
warnings.simplefilter("default")
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture(autouse=True)
|
||||||
|
def settings_debug(settings):
|
||||||
|
settings.DEBUG = True
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
def auth_data():
|
def auth_data():
|
||||||
return data_v3.generate_test_data()
|
return data_v3.generate_test_data()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def dashboard_data():
|
||||||
|
return test_utils.load_test_data()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def disable_requests(monkeypatch):
|
def disable_requests(monkeypatch):
|
||||||
class MockRequestsSession:
|
class MockRequestsSession:
|
||||||
@ -48,6 +61,7 @@ def disable_requests(monkeypatch):
|
|||||||
monkeypatch.setattr(testcases, 'QuietWSGIRequestHandler',
|
monkeypatch.setattr(testcases, 'QuietWSGIRequestHandler',
|
||||||
testcases.WSGIRequestHandler)
|
testcases.WSGIRequestHandler)
|
||||||
|
|
||||||
|
|
||||||
# prevent pytest-django errors due to no database
|
# prevent pytest-django errors due to no database
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def _django_db_helper():
|
def _django_db_helper():
|
||||||
@ -88,3 +102,20 @@ def mock_keystoneclient():
|
|||||||
endpoint_data.api_version = (3, 10)
|
endpoint_data.api_version = (3, 10)
|
||||||
keystoneclient.session.get_endpoint_data.return_value = endpoint_data
|
keystoneclient.session.get_endpoint_data.return_value = endpoint_data
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def user(monkeypatch, dashboard_data, mock_keystoneclient):
|
||||||
|
def get_user(request):
|
||||||
|
new_user = openstack_auth.user.User(
|
||||||
|
id=dashboard_data.user.id,
|
||||||
|
token=dashboard_data.token,
|
||||||
|
user=dashboard_data.user.name,
|
||||||
|
domain_id=dashboard_data.domain.id,
|
||||||
|
tenant_id=dashboard_data.tenant.id,
|
||||||
|
service_catalog=dashboard_data.service_catalog,
|
||||||
|
authorized_tenants=dashboard_data.tenants.list(),
|
||||||
|
)
|
||||||
|
new_user._is_system_user = False
|
||||||
|
return new_user
|
||||||
|
monkeypatch.setattr(auth_utils, 'get_user', get_user)
|
||||||
|
@ -30,8 +30,8 @@ def test_login(live_server, driver, mock_openstack_auth, mock_keystoneclient):
|
|||||||
assert driver.title != "Login - OpenStack Dashboard"
|
assert driver.title != "Login - OpenStack Dashboard"
|
||||||
|
|
||||||
|
|
||||||
def test_languages(live_server, driver, mock_openstack_auth,
|
def test_languages(live_server, driver, user):
|
||||||
mock_keystoneclient):
|
driver.get(live_server.url + '/settings')
|
||||||
user_settings = driver.find_element_by_id('user_settings_modal')
|
user_settings = driver.find_element_by_id('user_settings_modal')
|
||||||
language_options = user_settings.find_element_by_id('id_language')
|
language_options = user_settings.find_element_by_id('id_language')
|
||||||
language_options.click()
|
language_options.click()
|
||||||
@ -40,4 +40,3 @@ def test_languages(live_server, driver, mock_openstack_auth,
|
|||||||
messages = widgets.get_and_dismiss_messages(driver)
|
messages = widgets.get_and_dismiss_messages(driver)
|
||||||
assert "Success: Settings saved." in messages
|
assert "Success: Settings saved." in messages
|
||||||
assert "Error" not in messages
|
assert "Error" not in messages
|
||||||
# ToDo - mock API switch page language.
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user