2018-06-28 14:47:23 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""UI tests for the queries page."""
|
|
|
|
|
2018-08-16 21:15:46 +03:00
|
|
|
import typing
|
|
|
|
|
2018-06-26 00:47:21 +03:00
|
|
|
import pytest
|
|
|
|
|
2018-06-28 14:47:23 +03:00
|
|
|
from models.user import User
|
2018-08-03 22:28:25 +03:00
|
|
|
from pages.home import HomePage
|
2018-06-28 14:47:23 +03:00
|
|
|
from pages.login import LoginPage
|
|
|
|
|
2018-06-26 00:47:21 +03:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"search_term, description",
|
|
|
|
[
|
2018-09-24 17:27:53 +03:00
|
|
|
("Default Query", "Test query for redash UI tests."),
|
2018-06-26 00:47:21 +03:00
|
|
|
("Ashleys Query", "Query created by Ashley."),
|
|
|
|
],
|
|
|
|
)
|
2018-08-03 22:28:25 +03:00
|
|
|
def test_query_by_username(
|
2018-08-16 21:12:54 +03:00
|
|
|
create_queries: typing.Callable[..., None],
|
2018-06-28 14:47:23 +03:00
|
|
|
login_page: LoginPage,
|
|
|
|
search_term: str,
|
|
|
|
description: str,
|
|
|
|
user: User,
|
|
|
|
) -> None:
|
2018-08-07 17:36:55 +03:00
|
|
|
"""Search for query by username."""
|
2018-06-26 00:47:21 +03:00
|
|
|
page = login_page.login(email=user.email, password=user.password)
|
|
|
|
search = page.search(search_term)
|
|
|
|
query = search.queries[0].click()
|
|
|
|
assert query.description == description
|
2018-08-03 22:28:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"search_term, description",
|
|
|
|
[
|
2018-09-24 17:27:53 +03:00
|
|
|
("Default Query", "Test query for redash UI tests."),
|
2018-08-03 22:28:25 +03:00
|
|
|
("Ashleys Query", "Query created by Ashley."),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_query_by_description(
|
2018-08-16 21:12:54 +03:00
|
|
|
create_queries: typing.Callable[..., None],
|
2018-08-03 22:28:25 +03:00
|
|
|
login_page: LoginPage,
|
|
|
|
search_term: str,
|
|
|
|
description: str,
|
|
|
|
user: User,
|
|
|
|
) -> None:
|
2018-08-07 17:36:55 +03:00
|
|
|
"""Search for query using description."""
|
2018-08-03 22:28:25 +03:00
|
|
|
page = login_page.login(email=user.email, password=user.password)
|
|
|
|
search = page.search(description)
|
|
|
|
query = search.queries[0].click()
|
|
|
|
assert query.description == description
|
|
|
|
|
|
|
|
|
|
|
|
def test_query_by_weird_capitalization(
|
2018-08-16 21:12:54 +03:00
|
|
|
create_queries: typing.Callable[..., None],
|
|
|
|
login_page: LoginPage,
|
2018-08-17 10:14:30 +03:00
|
|
|
org: str,
|
2018-08-16 21:12:54 +03:00
|
|
|
user: User,
|
2018-08-17 10:14:30 +03:00
|
|
|
variables: typing.Dict,
|
2018-08-03 22:28:25 +03:00
|
|
|
) -> None:
|
2018-08-07 17:36:55 +03:00
|
|
|
"""Search for query with weird capitalization."""
|
2018-08-03 22:28:25 +03:00
|
|
|
term = variables[org]["queries"]["capitalization"]
|
|
|
|
page = login_page.login(email=user.email, password=user.password)
|
|
|
|
search = page.search(term["name"])
|
|
|
|
query = search.queries[0].click()
|
|
|
|
assert query.description == term["description"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_query_by_number(
|
2018-08-16 21:12:54 +03:00
|
|
|
create_queries: typing.Callable[..., None],
|
|
|
|
login_page: LoginPage,
|
2018-08-17 10:14:30 +03:00
|
|
|
org: str,
|
2018-08-16 21:12:54 +03:00
|
|
|
user: User,
|
2018-08-17 10:14:30 +03:00
|
|
|
variables: typing.Dict,
|
2018-08-03 22:28:25 +03:00
|
|
|
) -> None:
|
2018-08-07 17:36:55 +03:00
|
|
|
"""Search for query with numbers in the name."""
|
2018-08-03 22:28:25 +03:00
|
|
|
term = variables[org]["queries"]["numbers"]
|
|
|
|
page = login_page.login(email=user.email, password=user.password)
|
2018-08-07 17:51:47 +03:00
|
|
|
search = page.search(term["name"])
|
2018-08-03 22:28:25 +03:00
|
|
|
query = search.queries[0].click()
|
|
|
|
assert query.description == term["description"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_query_by_special_char(
|
2018-08-16 21:12:54 +03:00
|
|
|
create_queries: typing.Callable[..., None],
|
|
|
|
login_page: LoginPage,
|
2018-08-17 10:14:30 +03:00
|
|
|
org: str,
|
2018-08-16 21:12:54 +03:00
|
|
|
user: User,
|
2018-08-17 10:14:30 +03:00
|
|
|
variables: typing.Dict,
|
2018-08-03 22:28:25 +03:00
|
|
|
) -> None:
|
2018-08-07 17:36:55 +03:00
|
|
|
"""Search for query wioth special characters in name."""
|
2018-08-03 22:28:25 +03:00
|
|
|
term = variables[org]["queries"]["special-char"]
|
|
|
|
page = login_page.login(email=user.email, password=user.password)
|
2018-08-07 17:51:47 +03:00
|
|
|
search = page.search(term["name"])
|
2018-08-03 22:28:25 +03:00
|
|
|
query = search.queries[0].click()
|
|
|
|
assert query.description == term["description"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_search_for_unpublished_query(
|
2018-08-16 21:12:54 +03:00
|
|
|
create_queries: typing.Callable[..., None],
|
|
|
|
login_page: LoginPage,
|
|
|
|
server_url,
|
|
|
|
selenium,
|
2018-08-16 21:28:54 +03:00
|
|
|
user: User,
|
2018-08-03 22:28:25 +03:00
|
|
|
) -> None:
|
|
|
|
"""Publish a query and then search for the unpublished one."""
|
|
|
|
page = login_page.login(email=user.email, password=user.password)
|
|
|
|
search = page.search("Publish Query")
|
|
|
|
query = search.queries[0].click()
|
|
|
|
query.publish()
|
|
|
|
page = HomePage(selenium, server_url).open()
|
|
|
|
search = page.search("Ashleys Query")
|
|
|
|
query = search.queries[0].click()
|
|
|
|
assert query.description == "Query created by Ashley."
|
2018-08-07 17:36:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_search_for_query_by_id(
|
2018-08-16 21:12:54 +03:00
|
|
|
create_queries: typing.Callable[..., None],
|
|
|
|
login_page: LoginPage,
|
|
|
|
server_url,
|
|
|
|
selenium,
|
2018-08-16 21:28:54 +03:00
|
|
|
user: User,
|
2018-08-07 17:36:55 +03:00
|
|
|
) -> None:
|
|
|
|
"""Search for a query by its id."""
|
|
|
|
page = login_page.login(email=user.email, password=user.password)
|
|
|
|
search = page.search("1")
|
|
|
|
query = search.queries[0].click()
|
|
|
|
assert query.description == "Query created by Ashley."
|
2018-08-16 21:12:54 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_search_for_query_only_includes_search_result(
|
|
|
|
create_queries: typing.Callable[..., None],
|
|
|
|
login_page: LoginPage,
|
|
|
|
server_url,
|
|
|
|
selenium,
|
2018-08-16 21:28:54 +03:00
|
|
|
user: User,
|
2018-08-16 21:12:54 +03:00
|
|
|
) -> None:
|
|
|
|
page = login_page.login(email=user.email, password=user.password)
|
|
|
|
search = page.search("Default Query")
|
2018-08-17 10:32:22 +03:00
|
|
|
assert len(search.queries) == 2
|
2018-08-16 21:12:54 +03:00
|
|
|
assert search.queries[0].link.text == "Default Query"
|