Skip to content

Commit

Permalink
Merge pull request #631 from antip00/master
Browse files Browse the repository at this point in the history
Adding tests for default values.
  • Loading branch information
Slach authored Oct 1, 2024
2 parents 6562289 + cc4158f commit 453760e
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
python3
-u ./regression.py --before=0.1 --after=0.1
--log raw.log
-o nice-new-fails
-o classic

- name: Create reports
if: always()
Expand Down
10 changes: 10 additions & 0 deletions docker/clickhouse/init_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ CREATE TABLE IF NOT EXISTS default.test_interval
INSERT INTO default.test_interval(d,x) SELECT toDateTime(now()-(number*10)) AS d, rand() AS x FROM numbers(1000);


DROP TABLE IF EXISTS default.test_interval_64;
CREATE TABLE IF NOT EXISTS default.test_interval_64
(
d64 DateTime64,
x UInt32
) ENGINE = MergeTree() ORDER BY (d64);

INSERT INTO default.test_interval_64(d64,x) SELECT toDateTime(now()-(number*10)) AS d64, rand() AS x FROM numbers(1000);


DROP TABLE IF EXISTS default.test_array_join_nested;
CREATE TABLE IF NOT EXISTS default.test_array_join_nested(
d DateTime,
Expand Down
3 changes: 3 additions & 0 deletions tests/testflows/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def argparser(parser):
"/Grafana Datasource Plugin For Clickhouse/e2e/mixed data sources/*": [
(Fail, "https://github.com/Altinity/clickhouse-grafana/issues/604")
],
"/Grafana Datasource Plugin For Clickhouse/data source setup/check default values datetime64/": [
(Error, "https://github.com/Altinity/clickhouse-grafana/issues/630")
]
}

grafana_version = ""
Expand Down
37 changes: 35 additions & 2 deletions tests/testflows/steps/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,41 @@ def create_new_altinity_datasource(

if use_default_values:
with delay():
with By("clicking "):
pass
with By("clicking use default values toggle"):
datasources_altinity_edit.click_use_default_values_toggle()

with delay():
if not(default_column_timestamp_type is None):
with By("setting up default timestamp type"):
datasources_altinity_edit.enter_column_timestamp_type(column_timestamp_type=default_column_timestamp_type)

with delay():
if not (default_datetime_field is None):
with By("setting up default datetime field"):
datasources_altinity_edit.enter_datetime_field(
datetime=default_datetime_field)

with delay():
if not (default_timestamp_field is None):
with By("setting up default timestamp field"):
datasources_altinity_edit.enter_timestamp_field(
timestamp=default_timestamp_field)

with delay():
if not (default_datetime64_field is None):
with By("setting up default datetime64 type"):
datasources_altinity_edit.enter_datetime64_field(
datetime64=default_datetime64_field)

with delay():
if not (default_date_field is None):
with By("setting up default date field"):
datasources_altinity_edit.enter_date_field(
date=default_date_field)

with delay():
with By("clicking save and test button"):
datasources_altinity_edit.click_save_and_test_button()

if successful_connection:
with And("checking save and test button returns green alert"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,36 @@ def use_default_values_toggle(self):
return driver.find_element(SelectBy.CSS_SELECTOR,
"[for='useDefaultConfiguration']")

@property
def column_timestamp_type_field(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[./text()="Column timestamp type"]/..//input[contains(@id, "react-select")]')

@property
def datetime_field(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[./text()="Datetime Field"]/..//input[contains(@id, "react-select")]')

@property
def timestamp_field(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[./text()="Timestamp (Uint32) Field"]/..//input[contains(@id, "react-select")]')

@property
def datetime64_field(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[./text()="Datetime64 Field"]/..//input[contains(@id, "react-select")]')

@property
def date_field(self):
driver: WebDriver = current().context.driver
return driver.find_element(SelectBy.XPATH,
f'//*[./text()="Date Field"]/..//input[contains(@id, "react-select")]')



locators = Locators()
115 changes: 115 additions & 0 deletions tests/testflows/steps/connections/datasources/altinity_edit/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,118 @@ def enter_server_name(self, server_name=None):
server_name = self.context.server_name

locators.server_name_textfield.send_keys(server_name)


@TestStep(When)
def enter_column_timestamp_type(self, column_timestamp_type):
"""Enter column timestamp type."""

locators.column_timestamp_type_field.click()
locators.column_timestamp_type_field.send_keys(column_timestamp_type)
locators.column_timestamp_type_field.send_keys(Keys.ENTER)


@TestStep(When)
def enter_datetime_field(self, datetime):
"""Enter datetime field."""

locators.datetime_field.click()
locators.datetime_field.send_keys(datetime)
locators.datetime_field.send_keys(Keys.ENTER)


@TestStep(When)
def enter_timestamp_field(self, timestamp):
"""Enter timestamp field."""

locators.timestamp_field.click()
locators.timestamp_field.send_keys(timestamp)
locators.timestamp_field.send_keys(Keys.ENTER)


@TestStep(When)
def enter_datetime64_field(self, datetime64):
"""Enter datetime64 field."""

locators.datetime64_field.click()
locators.datetime64_field.send_keys(datetime64)
locators.datetime64_field.send_keys(Keys.ENTER)


@TestStep(When)
def enter_date_field(self, date):
"""Enter datetime64 field."""

locators.date_field.click()
locators.date_field.send_keys(date)
locators.date_field.send_keys(Keys.ENTER)


@TestStep(Then)
def get_column_timestamp_type(self):
"""Get column timestamp type value."""

return locators.column_timestamp_type_field.get_attribute('value')


@TestStep(Then)
def get_datetime_field(self):
"""Get datetime field value."""

return locators.datetime_field.get_attribute('value')


@TestStep(Then)
def get_timestamp_field(self):
"""Get timestamp field value."""

return locators.timestamp_field.get_attribute('value')


@TestStep(Then)
def get_datetime64_field(self):
"""Get datetime64 field value."""

return locators.datetime64_field.get_attribute('value')


@TestStep(Then)
def get_date_field(self):
"""Get date field value."""

return locators.date_field.get_attribute('value')


@TestStep(Then)
def get_column_timestamp_type_placeholder(self):
"""Get column timestamp type value."""

return locators.column_timestamp_type_field.get_attribute('placeholder')


@TestStep(Then)
def get_datetime_field_placeholder(self):
"""Get datetime field value."""

return locators.datetime_field.get_attribute('placeholder')


@TestStep(Then)
def get_timestamp_field_placeholder(self):
"""Get timestamp field value."""

return locators.timestamp_field.get_attribute('placeholder')


@TestStep(Then)
def get_datetime64_field_placeholder(self):
"""Get datetime64 field value."""

return locators.datetime64_field.get_attribute('placeholder')


@TestStep(Then)
def get_date_field_placeholder(self):
"""Get date field value."""

return locators.date_field.get_attribute('placeholder')
92 changes: 92 additions & 0 deletions tests/testflows/tests/automated/data_source_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import steps.actions as actions
import steps.panel.view as panel
import steps.dashboard.view as dashboard
import steps.panel.sql_editor.view as sql_editor
import steps.connections.datasources.view as datasources
import steps.connections.datasources.altinity_edit.view as datasources_altinity_edit

Expand Down Expand Up @@ -432,6 +433,97 @@ def check_success_browser_access(self):
)


@TestOutline
def check_default_values(
self,
default_column_timestamp_type="DateTime",
default_datetime_field="EventTime",
default_timestamp_field="level",
default_datetime64_field=None,
default_date_field="EventDate",
check_reformatted_query="SELECT 'EventDate', 'EventTime'",
):
"""Check that plugin supports setting up default values."""
with Given("I create new altinity datasource"):
actions.create_new_altinity_datasource(
datasource_name="default_values",
url="http://clickhouse:8123",
use_default_values=True,
default_column_timestamp_type=default_column_timestamp_type,
default_datetime_field=default_datetime_field,
default_timestamp_field=default_timestamp_field,
default_datetime64_field=default_datetime64_field,
default_date_field=default_date_field,
)

with And("I create new dashboard"):
actions.create_dashboard(dashboard_name="default_values")

with When("I add visualization for panel"):
dashboard.add_visualization()

with And("I select datasource"):
with delay():
panel.select_datasource_in_panel_view(datasource_name="default_values")

with And("I open SQL editor"):
with delay():
panel.go_to_sql_editor()

with And("I enter query to SQL editor"):
panel.enter_sql_editor_input(query="SELECT '$dateCol', '$dateTimeCol'")

with Then("I click Show generated SQL button",
description="opened to check reformatted queries in scenarios"):
with delay():
sql_editor.click_show_generated_sql_button(query_name='A')

with And("I check reformatted query"):
assert check_reformatted_query in sql_editor.get_reformatted_query(query_name='A'), error()


@TestScenario
def check_default_values_datetime(self):
"""Check that plugin supports setting up default values with DateTime timestamp type."""

check_default_values(
default_column_timestamp_type="DateTime",
default_datetime_field="EventTime",
default_timestamp_field=None,
default_datetime64_field=None,
default_date_field="EventDate",
check_reformatted_query="SELECT 'EventDate', 'EventTime'",
)


@TestScenario
def check_default_values_timestamp(self):
"""Check that plugin supports setting up default values with timestamp default timestamp type."""

check_default_values(
default_column_timestamp_type="timestamp",
default_datetime_field=None,
default_timestamp_field="level",
default_datetime64_field=None,
default_date_field="EventDate",
check_reformatted_query="SELECT 'EventDate', 'level'",
)


@TestScenario
def check_default_values_datetime64(self):
"""Check that plugin supports setting up default values with DateTime64 timestamp type."""

check_default_values(
default_column_timestamp_type="DateTime64",
default_datetime_field=None,
default_timestamp_field=None,
default_datetime64_field="d",
default_date_field="EventDate",
check_reformatted_query="SELECT 'EventDate', 'd'",
)


@TestFeature
@Requirements(
RQ_SRS_Plugin_DataSourceSetupView("1.0"),
Expand Down

0 comments on commit 453760e

Please sign in to comment.