Skip to content

Commit

Permalink
fix(#3333): Improve test condition
Browse files Browse the repository at this point in the history
  • Loading branch information
nico-stefani committed Apr 18, 2023
1 parent f1fc530 commit e799389
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
21 changes: 7 additions & 14 deletions deps/wazuh_testing/wazuh_testing/modules/aws/db_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,18 @@ def get_multiple_s3_db_row(table_name: str) -> Iterator[S3CloudTrailRow]:
yield row_type(*row)


def table_exists(table_name: str) -> bool:
"""Check if the given table name exists.
def table_exists_or_has_values(table_name: str) -> bool:
"""Check if the given table name exists. If exists check if has values.
Args:
table_name (str): Table name to search for.
Returns:
bool: True if exists else False.
bool: True if exists or has values else False.
"""
connection = get_db_connection(S3_CLOUDTRAIL_DB_PATH)
cursor = connection.cursor()
query = """
SELECT
name
FROM
sqlite_master
WHERE
type ='table' AND
name NOT LIKE 'sqlite_%';
"""

return table_name in [result[0] for result in cursor.execute(query).fetchall()]
try:
return bool(cursor.execute(SELECT_QUERY_TEMPLATE.format(table_name=table_name)).fetchall())
except sqlite3.OperationalError:
return False
4 changes: 2 additions & 2 deletions tests/integration/test_aws/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from wazuh_testing import T_10, T_20, global_parameters
from wazuh_testing.modules.aws import event_monitor
from wazuh_testing.modules.aws.db_utils import get_s3_db_row, s3_db_exists, table_exists
from wazuh_testing.modules.aws.db_utils import get_s3_db_row, s3_db_exists, table_exists_or_has_values
from wazuh_testing.tools.configuration import (
get_test_cases_data,
load_configuration_template,
Expand Down Expand Up @@ -150,4 +150,4 @@ def test_path(
assert f"{bucket_name}/{path}/" == data.bucket_path
assert data.log_key.startswith(f"{path}/")
else:
assert not table_exists(table_name=bucket_type)
assert not table_exists_or_has_values(table_name=bucket_type)
4 changes: 2 additions & 2 deletions tests/integration/test_aws/test_path_suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from wazuh_testing import T_10, T_20, global_parameters
from wazuh_testing.modules.aws import event_monitor
from wazuh_testing.modules.aws.db_utils import get_s3_db_row, s3_db_exists, table_exists
from wazuh_testing.modules.aws.db_utils import get_s3_db_row, s3_db_exists, table_exists_or_has_values
from wazuh_testing.tools.configuration import (
get_test_cases_data,
load_configuration_template,
Expand Down Expand Up @@ -153,4 +153,4 @@ def test_path_suffix(
assert f"{bucket_name}/{path_suffix}/" == data.bucket_path
assert data.log_key.startswith(f"AWSLogs/{path_suffix}/")
else:
assert not table_exists(table_name=bucket_type)
assert not table_exists_or_has_values(table_name=bucket_type)
4 changes: 2 additions & 2 deletions tests/integration/test_aws/test_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from wazuh_testing.modules.aws.db_utils import (
get_multiple_s3_db_row,
s3_db_exists,
table_exists,
table_exists_or_has_values,
)
from wazuh_testing.tools.configuration import (
get_test_cases_data,
Expand Down Expand Up @@ -160,4 +160,4 @@ def test_regions(
else:
assert row.log_key.split("/")[3] in regions_list
else:
assert not table_exists(table_name=bucket_type)
assert not table_exists_or_has_values(table_name=bucket_type)

0 comments on commit e799389

Please sign in to comment.