From e65cb1572ba2d740e29cb04716a55bc9c3abd0f0 Mon Sep 17 00:00:00 2001 From: antip00 Date: Mon, 23 Sep 2024 17:22:42 +0300 Subject: [PATCH 1/2] Adding tests for default values. --- docker/clickhouse/init_schema.sql | 10 ++ tests/testflows/regression.py | 3 + tests/testflows/steps/actions.py | 37 +++++- .../datasources/altinity_edit/locators.py | 31 +++++ .../datasources/altinity_edit/view.py | 115 ++++++++++++++++++ .../tests/automated/data_source_setup.py | 92 ++++++++++++++ 6 files changed, 286 insertions(+), 2 deletions(-) diff --git a/docker/clickhouse/init_schema.sql b/docker/clickhouse/init_schema.sql index d7f0f6889..2ed96d6c5 100644 --- a/docker/clickhouse/init_schema.sql +++ b/docker/clickhouse/init_schema.sql @@ -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, diff --git a/tests/testflows/regression.py b/tests/testflows/regression.py index c983f2b41..1addfb648 100755 --- a/tests/testflows/regression.py +++ b/tests/testflows/regression.py @@ -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 = "" diff --git a/tests/testflows/steps/actions.py b/tests/testflows/steps/actions.py index 2106a4007..b242e6468 100644 --- a/tests/testflows/steps/actions.py +++ b/tests/testflows/steps/actions.py @@ -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"): diff --git a/tests/testflows/steps/connections/datasources/altinity_edit/locators.py b/tests/testflows/steps/connections/datasources/altinity_edit/locators.py index b922a7948..f3cbf0b63 100644 --- a/tests/testflows/steps/connections/datasources/altinity_edit/locators.py +++ b/tests/testflows/steps/connections/datasources/altinity_edit/locators.py @@ -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() diff --git a/tests/testflows/steps/connections/datasources/altinity_edit/view.py b/tests/testflows/steps/connections/datasources/altinity_edit/view.py index 037017123..73e1e6539 100644 --- a/tests/testflows/steps/connections/datasources/altinity_edit/view.py +++ b/tests/testflows/steps/connections/datasources/altinity_edit/view.py @@ -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') diff --git a/tests/testflows/tests/automated/data_source_setup.py b/tests/testflows/tests/automated/data_source_setup.py index d2938ea23..b00eb9ad8 100644 --- a/tests/testflows/tests/automated/data_source_setup.py +++ b/tests/testflows/tests/automated/data_source_setup.py @@ -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 @@ -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"), From cc4158f45ecf6e111c1e84d5d4e2eefdedf7b3f9 Mon Sep 17 00:00:00 2001 From: antip00 Date: Mon, 23 Sep 2024 17:36:05 +0300 Subject: [PATCH 2/2] Update. --- .github/workflows/testflows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testflows.yml b/.github/workflows/testflows.yml index 213344f48..2d676faa4 100644 --- a/.github/workflows/testflows.yml +++ b/.github/workflows/testflows.yml @@ -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()