redash-ui-tests/tests/test_queries.py

239 строки
7.1 KiB
Python
Исходник Обычный вид История

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-10-01 18:28:15 +03:00
("Default Query", "Test default 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-10-01 18:28:15 +03:00
("Default Query", "Test default 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,
org: str,
2018-08-16 21:12:54 +03:00
user: User,
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,
org: str,
2018-08-16 21:12:54 +03:00
user: User,
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,
org: str,
2018-08-16 21:12:54 +03:00
user: User,
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: str,
2018-08-16 21:12:54 +03:00
selenium,
root_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=root_user.email, password=root_user.password)
2018-08-03 22:28:25 +03:00
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: str,
2018-08-16 21:12:54 +03:00
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("2")
2018-08-07 17:36:55 +03:00
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: str,
2018-08-16 21:12:54 +03:00
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")
assert len(search.queries) == 2
2018-08-16 21:12:54 +03:00
assert search.queries[0].link.text == "Default Query"
def test_change_query_title(
create_queries: typing.Callable[..., None],
login_page: LoginPage,
server_url: str,
selenium,
root_user: User,
variables: typing.Dict,
) -> None:
page = login_page.login(email=root_user.email, password=root_user.password)
query_specs = variables["default"]["queries"]["edit-query"]
query_name = query_specs["name"]
search = page.search(query_name)
query = search.queries[0].click()
assert query.title == query_name
query.edit_title("NEW")
assert query.title == f"{query_name} NEW"
def test_change_query_description(
create_queries: typing.Callable[..., None],
login_page: LoginPage,
server_url: str,
selenium,
root_user: User,
) -> None:
page = login_page.login(email=root_user.email, password=root_user.password)
search = page.search("Blank Query")
query = search.queries[0].click()
query.edit_description("This is a description")
assert query.description == "This is a description"
def test_edit_query_description(
create_queries: typing.Callable[..., None],
login_page: LoginPage,
server_url: str,
selenium,
root_user: User,
variables: typing.Dict,
) -> None:
default_description = variables["default"]["queries"]["default"]["description"]
page = login_page.login(email=root_user.email, password=root_user.password)
search = page.search("Default Query")
query = search.queries[0].click()
assert query.description == default_description
query.edit_description(" NEW NEW")
assert query.description == f"{default_description} NEW NEW"
def test_edit_query_source(
create_queries: typing.Callable[..., None],
login_page: LoginPage,
server_url: str,
selenium,
root_user: User,
variables: typing.Dict,
) -> None:
page = login_page.login(email=root_user.email, password=root_user.password)
search = page.search("Default Query")
query = search.queries[0].click()
query.edit_source_button.click()
assert "/source" in selenium.current_url
def test_query_fork(
create_queries: typing.Callable[..., None],
login_page: LoginPage,
server_url: str,
selenium,
root_user: User,
variables: typing.Dict,
) -> None:
page = login_page.login(email=root_user.email, password=root_user.password)
search = page.search("Default Query")
query = search.queries[0].click()
fork_query = query.click_dropdown_menu(text="Fork")
selenium.switch_to.window(selenium.window_handles[-1])
assert "Copy of (#4)" in fork_query.title
def test_query_archive(
create_queries: typing.Callable[..., None],
login_page: LoginPage,
server_url: str,
selenium,
root_user: User,
variables: typing.Dict,
) -> None:
page = login_page.login(email=root_user.email, password=root_user.password)
search = page.search("Archive Query")
query = search.queries[0].click()
query.click_dropdown_menu(text="Archive")
assert query.query_tag == "Archived"