diff --git a/camayoc/tests/qcs/ui/__init__.py b/camayoc/tests/qcs/ui/__init__.py new file mode 100644 index 00000000..f5406008 --- /dev/null +++ b/camayoc/tests/qcs/ui/__init__.py @@ -0,0 +1 @@ +"""Tests for quipucords' UI.""" diff --git a/camayoc/tests/qcs/ui/conftest.py b/camayoc/tests/qcs/ui/conftest.py new file mode 100644 index 00000000..a8663560 --- /dev/null +++ b/camayoc/tests/qcs/ui/conftest.py @@ -0,0 +1,12 @@ +"""Test utilities for quipucords' UI tests.""" +import pytest +from widgetastic.browser import Browser + +from camayoc.utils import get_qcs_url + + +@pytest.fixture +def browser(selenium): + """Widgetastic browser fixture.""" + selenium.get(get_qcs_url()) + return Browser(selenium) diff --git a/camayoc/tests/qcs/ui/test_login.py b/camayoc/tests/qcs/ui/test_login.py new file mode 100644 index 00000000..98883335 --- /dev/null +++ b/camayoc/tests/qcs/ui/test_login.py @@ -0,0 +1,37 @@ +# coding=utf-8 +"""Tests for UI login and logout. + +:caseautomation: automated +:casecomponent: ui +:caseimportance: high +:caselevel: integration +:requirement: Sonar +:testtype: functional +:upstream: yes +""" +from .views import LoginView, DashboardView + + +def test_login_logout(browser): + """Login and logout using the default user. + + :id: 88bbf267-d32e-44b1-934f-e69c84e5c99d + :description: Login and logout using the default user. + :steps: + 1) Access the login page and fill the username and password fields + using the default user credentials. + 2) Check if the dashboard page is displayed. + 3) Logout and assert that the login page is shown. + :expectedresults: Both login and logout must work. + """ + login = LoginView(browser) + login.username.fill('admin') + login.password.fill('pass') + login.login.click() + + assert browser.selenium.title == 'Red Hat Entitlements Reporting' + + dashboard = DashboardView(browser) + dashboard.user_dropdown.select_item('Logout') + + login.login.wait_displayed() diff --git a/camayoc/tests/qcs/ui/views.py b/camayoc/tests/qcs/ui/views.py new file mode 100644 index 00000000..090cd66d --- /dev/null +++ b/camayoc/tests/qcs/ui/views.py @@ -0,0 +1,20 @@ +"""Quipucords views.""" +from smartloc import Locator +from widgetastic.widget import TextInput, View +from widgetastic_patternfly import Button, NavDropdown + + +class LoginView(View): + """Login view.""" + + login = Button('Log In', classes=[Button.PRIMARY]) + username = TextInput(locator='#id_username') + password = TextInput(locator='#id_password') + + +class DashboardView(View): + """Dashboard view.""" + + user_dropdown = NavDropdown( + locator=Locator(css='li.dropdown:nth-child(2)')) + logout = Button('Logout') diff --git a/camayoc/utils.py b/camayoc/utils.py index 18f94d94..247e522c 100644 --- a/camayoc/utils.py +++ b/camayoc/utils.py @@ -5,12 +5,33 @@ import shutil import tempfile import uuid +from urllib.parse import urlunparse + +from camayoc import exceptions +from camayoc.config import get_config _XDG_ENV_VARS = ('XDG_DATA_HOME', 'XDG_CONFIG_HOME', 'XDG_CACHE_HOME') """Environment variables related to the XDG Base Directory specification.""" +def get_qcs_url(): + """Return the base url for the qcs server.""" + cfg = get_config().get('qcs', {}) + hostname = cfg.get('hostname') + + if not hostname: + raise exceptions.QCSBaseUrlNotFound( + 'Make sure you have a "qcs" section and `hostname`is specified in ' + 'the camayoc config file' + ) + + scheme = 'https' if cfg.get('https', False) else 'http' + port = str(cfg.get('port', '')) + netloc = hostname + ':{}'.format(port) if port else hostname + return urlunparse((scheme, netloc, '', '', '', '')) + + def uuid4(): """Return a random UUID, as a unicode string.""" return str(uuid.uuid4()) diff --git a/docs/api.rst b/docs/api.rst index ff26d6c3..259a04db 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -44,6 +44,10 @@ reference for developers, not a gospel. api/camayoc.tests.qcs.cli.test_sources api/camayoc.tests.qcs.cli.utils api/camayoc.tests.qcs.conftest + api/camayoc.tests.qcs.ui + api/camayoc.tests.qcs.ui.conftest + api/camayoc.tests.qcs.ui.test_login + api/camayoc.tests.qcs.ui.views api/camayoc.tests.qcs.utils api/camayoc.tests.remote api/camayoc.tests.remote.rho diff --git a/docs/api/camayoc.tests.qcs.rst b/docs/api/camayoc.tests.qcs.rst index 09d57944..9d1a4962 100644 --- a/docs/api/camayoc.tests.qcs.rst +++ b/docs/api/camayoc.tests.qcs.rst @@ -13,6 +13,7 @@ Subpackages camayoc.tests.qcs.api camayoc.tests.qcs.cli + camayoc.tests.qcs.ui Submodules ---------- diff --git a/docs/api/camayoc.tests.qcs.ui.conftest.rst b/docs/api/camayoc.tests.qcs.ui.conftest.rst new file mode 100644 index 00000000..88b38fb3 --- /dev/null +++ b/docs/api/camayoc.tests.qcs.ui.conftest.rst @@ -0,0 +1,7 @@ +camayoc\.tests\.qcs\.ui\.conftest module +======================================== + +.. automodule:: camayoc.tests.qcs.ui.conftest + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/api/camayoc.tests.qcs.ui.rst b/docs/api/camayoc.tests.qcs.ui.rst new file mode 100644 index 00000000..93b8cabe --- /dev/null +++ b/docs/api/camayoc.tests.qcs.ui.rst @@ -0,0 +1,17 @@ +camayoc\.tests\.qcs\.ui package +=============================== + +.. automodule:: camayoc.tests.qcs.ui + :members: + :undoc-members: + :show-inheritance: + +Submodules +---------- + +.. toctree:: + + camayoc.tests.qcs.ui.conftest + camayoc.tests.qcs.ui.test_login + camayoc.tests.qcs.ui.views + diff --git a/docs/api/camayoc.tests.qcs.ui.test_login.rst b/docs/api/camayoc.tests.qcs.ui.test_login.rst new file mode 100644 index 00000000..d00bb3a1 --- /dev/null +++ b/docs/api/camayoc.tests.qcs.ui.test_login.rst @@ -0,0 +1,7 @@ +camayoc\.tests\.qcs\.ui\.test\_login module +=========================================== + +.. automodule:: camayoc.tests.qcs.ui.test_login + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/api/camayoc.tests.qcs.ui.views.rst b/docs/api/camayoc.tests.qcs.ui.views.rst new file mode 100644 index 00000000..964d5f39 --- /dev/null +++ b/docs/api/camayoc.tests.qcs.ui.views.rst @@ -0,0 +1,7 @@ +camayoc\.tests\.qcs\.ui\.views module +===================================== + +.. automodule:: camayoc.tests.qcs.ui.views + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/conf.py b/docs/conf.py index 44bef5cf..43141921 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -42,6 +42,7 @@ ('py:class', 'object'), ('py:class', 'tuple'), ('py:class', 'unittest.case.TestCase'), + ('py:class', 'widgetastic.widget.View'), ] nitpicky = True pygments_style = 'sphinx' diff --git a/setup.py b/setup.py index b4ebda8e..c24b9e6c 100644 --- a/setup.py +++ b/setup.py @@ -52,10 +52,12 @@ install_requires=[ 'pexpect', 'plumbum', + 'pytest', + 'pyvmomi', 'pyxdg', 'pyyaml', - 'pyvmomi', - 'pytest', + 'widgetastic.core', + 'widgetastic.patternfly', ], license='GPLv3', long_description=long_description,