Moe/Ursula status page: Updated unit tests for ursula status page

Hooked up pytest-dash/selenium for UI test
Removed extra logging
remotes/upstream/doubtfire
derekpierre 2019-05-10 10:37:57 -04:00 committed by Kieran R. Prasch
parent 59ad08de86
commit 9106231ccb
4 changed files with 50 additions and 17 deletions

View File

@ -39,7 +39,7 @@ class NetworkStatusPage:
html.Img(src='/assets/nucypher_logo.png'),
], className='banner'),
html.Div([
html.H1(title, className='app_name'),
html.H1(title, id='status-title', className='app_name'),
], className='row'),
html.Div(f'v{nucypher.__version__}', className='row')
]),
@ -171,8 +171,6 @@ class MoeStatusPage(NetworkStatusPage):
**kwargs) -> None:
NetworkStatusPage.__init__(self, title, flask_server, route_url, args, kwargs)
print(">>>> Derek ", self.dash_app.index_string)
# modify index_string page template so that the websocket port for hendrix
# updates can be directly provided included in javascript snippet
self.dash_app.index_string = '''

View File

@ -1,2 +1,5 @@
[pytest]
addopts = -v --runslow --junitxml=./reports/pytest-results.xml --strict-markers --durations=0 --cov=nucypher --cov-report xml:reports/coverage.xml
markers =
slow: marks tests as slow (skipped by default, use '--runslow' to include these tests)
webdriver = Chrome

View File

@ -14,19 +14,17 @@ GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import os
import pytest
from instapy_chromedriver import binary_path
from selenium.webdriver.chrome.options import Options
from nucypher.characters.control.emitters import WebEmitter
from nucypher.cli.config import NucypherClickConfig
from nucypher.crypto.powers import TransactingPower
from nucypher.utilities.logging import GlobalLoggerSettings
# Logger Configuration
#
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
# Disable click sentry and file logging
NucypherClickConfig.log_to_sentry = False
NucypherClickConfig.log_to_file = True
@ -128,3 +126,15 @@ def pytest_collection_modifyitems(config, items):
GlobalLoggerSettings.set_log_level(log_level_name)
GlobalLoggerSettings.start_text_file_logging()
GlobalLoggerSettings.start_json_file_logging()
# pytest-dash selenium hook
def pytest_setup_selenium(driver_name):
options = Options()
options.add_argument('--window-size=1920,1080') # required to make elements visible to selenium
options.add_argument('--start-maximized')
options.add_argument('--headless')
return {
'executable_path': binary_path,
'options': options,
}

View File

@ -1,24 +1,46 @@
from flask import Flask
from pytest_dash import wait_for
from nucypher.config.characters import UrsulaConfiguration
from nucypher.network.server import status_template
from nucypher.network.status.status_page import UrsulaStatusPage
def test_render_lonely_ursula_status_page(tmpdir):
def test_render_lonely_ursula_status_page(tmpdir, dash_threaded):
ursula_config = UrsulaConfiguration(dev_mode=True, federated_only=True)
ursula = ursula_config()
rendering = status_template.render(this_node=ursula, known_nodes=ursula.known_nodes)
assert '<!DOCTYPE html>' in rendering
assert ursula.nickname in rendering
server = Flask("ursula-status")
status_page = UrsulaStatusPage(ursula=ursula,
title=ursula.nickname,
flask_server=server,
route_url='/')
dash_threaded(status_page.dash_app, start_timeout=30)
dash_driver = dash_threaded.driver
title = dash_driver.find_element_by_id("status-title").text
assert title == ursula.nickname
def test_render_ursula_status_page_with_known_nodes(tmpdir, federated_ursulas):
def test_render_ursula_status_page_with_known_nodes(tmpdir, federated_ursulas, dash_threaded):
ursula_config = UrsulaConfiguration(dev_mode=True, federated_only=True, known_nodes=federated_ursulas)
ursula = ursula_config()
rendering = status_template.render(this_node=ursula, known_nodes=ursula.known_nodes)
assert '<!DOCTYPE html>' in rendering
assert ursula.nickname in rendering
server = Flask("ursula-status")
status_page = UrsulaStatusPage(ursula=ursula,
title=ursula.nickname,
flask_server=server,
route_url='/')
dash_threaded(status_page.dash_app, start_timeout=30)
dash_driver = dash_threaded.driver
title = dash_driver.find_element_by_id("status-title").text
assert title == ursula.nickname
node_table = wait_for.wait_for_element_by_id(dash_driver, 'node-table', 10) # wait for maximum 10s
node_table_info = node_table.get_attribute('innerHTML')
# Every known nodes address is rendered
for known_ursula in federated_ursulas:
assert known_ursula.checksum_address in rendering
assert known_ursula.checksum_public_address[:10] in node_table_info
assert known_ursula.nickname in node_table_info
assert known_ursula.rest_url() in node_table_info