Skip to content

Commit

Permalink
Add initial UI test
Browse files Browse the repository at this point in the history
Close #106
  • Loading branch information
elyezer committed Feb 21, 2018
1 parent c5f4798 commit 01a0d41
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 2 deletions.
1 change: 1 addition & 0 deletions camayoc/tests/qcs/ui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for quipucords' UI."""
12 changes: 12 additions & 0 deletions camayoc/tests/qcs/ui/conftest.py
Original file line number Diff line number Diff line change
@@ -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)
37 changes: 37 additions & 0 deletions camayoc/tests/qcs/ui/test_login.py
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 20 additions & 0 deletions camayoc/tests/qcs/ui/views.py
Original file line number Diff line number Diff line change
@@ -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')
21 changes: 21 additions & 0 deletions camayoc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
5 changes: 5 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,3 +64,4 @@ reference for developers, not a gospel.
api/tests.test_api
api/tests.test_cli
api/tests.test_config
api/tests.test_utils
1 change: 1 addition & 0 deletions docs/api/camayoc.tests.qcs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Subpackages

camayoc.tests.qcs.api
camayoc.tests.qcs.cli
camayoc.tests.qcs.ui

Submodules
----------
Expand Down
7 changes: 7 additions & 0 deletions docs/api/camayoc.tests.qcs.ui.conftest.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
camayoc\.tests\.qcs\.ui\.conftest module
========================================

.. automodule:: camayoc.tests.qcs.ui.conftest
:members:
:undoc-members:
:show-inheritance:
17 changes: 17 additions & 0 deletions docs/api/camayoc.tests.qcs.ui.rst
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions docs/api/camayoc.tests.qcs.ui.test_login.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
camayoc\.tests\.qcs\.ui\.test\_login module
===========================================

.. automodule:: camayoc.tests.qcs.ui.test_login
:members:
:undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/api/camayoc.tests.qcs.ui.views.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
camayoc\.tests\.qcs\.ui\.views module
=====================================

.. automodule:: camayoc.tests.qcs.ui.views
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/api/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ Submodules
tests.test_api
tests.test_cli
tests.test_config
tests.test_utils

1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@
install_requires=[
'pexpect',
'plumbum',
'pytest',
'pyvmomi',
'pyxdg',
'pyyaml',
'pyvmomi',
'pytest',
'widgetastic.core',
'widgetastic.patternfly',
],
license='GPLv3',
long_description=long_description,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# coding=utf-8
"""Unit tests for :mod:`camayoc.utils`."""
from unittest import mock

from camayoc import utils


def test_get_qcs_url():
"""Test ``camayoc.utils.get_qcs_url``."""
with mock.patch('camayoc.utils.get_config') as get_config:
get_config.return_value = {
'qcs': {
'hostname': 'server.example.com',
'https': True,
'port': 443,
}
}
assert utils.get_qcs_url() == 'https://server.example.com:443'

0 comments on commit 01a0d41

Please sign in to comment.