Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -417,17 +417,20 @@ def test_module():
Perform basic get request to get item samples
"""
try:
params = demisto.params()
google_service_creds = (
demisto.params().get("credentials_google_service", {}).get("password") or demisto.params()["google_service_creds"]
params.get("credentials_google_service", {}).get("password") or demisto.params()["google_service_creds"]
)
region = params.get("region")
bigquery_client = start_and_return_bigquery_client(google_service_creds)
query_job = bigquery_client.query(TEST_QUERY)
demisto.debug(f"[BigQuery Debug] test-module with {region=}")
query_job = bigquery_client.query("SELECT 1", location=region)
query_results = query_job.result()
results_rows_iterator = iter(query_results)
next(results_rows_iterator)
demisto.results("ok")
except Exception as ex:
return_error(f"Authentication error: credentials JSON provided is invalid.\n Exception recieved:{ex}")
return_error(f"Authentication error. Exception received:{ex}")


""" COMMANDS MANAGER / SWITCH PANEL """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,42 @@ configuration:
type: 9
required: false
section: Connect
- display: Region
name: region
options:
- us-central1
- us-east1
- us-east4
- us-east5
- us-south1
- us-west1
- us-west2
- us-west3
- us-west4
- northamerica-northeast1
- northamerica-northeast2
- southamerica-east1
- europe-west1
- europe-west2
- europe-west3
- europe-west4
- europe-west6
- europe-west8
- europe-west9
- europe-north1
- europe-central2
- asia-east1
- asia-east2
- asia-northeast1
- asia-northeast2
- asia-northeast3
- asia-south1
- asia-southeast1
- australia-southeast1
type: 15
section: Connect
advanced: true
required: false
- display: First fetch timestamp (<number> <time unit>. For example, 12 hours, 7 days)
name: first_fetch
defaultvalue: '1 days'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,45 @@ def test_query_command_with_date_only_format(mocker):
assert return_outputs_mock.call_count == 1
_, kwargs = return_outputs_mock.call_args
assert kwargs["outputs"]["BigQuery(val.Query && val.Query == obj.Query)"]["Row"][0]["Date"] == "2023-01-30"


def test_test_module_success(mocker):
"""
Given:
- Valid credentials and a region in the integration parameters.

When:
- Calling test_module.

Then:
- Ensure the bigquery client is initialized.
- Ensure the query is called with the correct SQL and location (region).
- Ensure the result is "ok".
"""
from GoogleBigQuery import test_module

# Mock demisto.params
mock_params = {"credentials_google_service": {"password": '{"project_id": "test-project"}'}, "region": "us-central1"}
mocker.patch.object(demisto, "params", return_value=mock_params)

# Mock bigquery client and its methods
mock_client = mocker.Mock()
mock_query_job = mocker.Mock()
mock_query_results = ["row1"] # Iterator will return this

mocker.patch("GoogleBigQuery.bigquery.Client", return_value=mock_client)
mock_client.query.return_value = mock_query_job
mock_query_job.result.return_value = mock_query_results

# Mock demisto.results
results_mock = mocker.patch.object(demisto, "results")

# Mock start_and_return_bigquery_client to avoid actual file operations
mocker.patch("GoogleBigQuery.start_and_return_bigquery_client", return_value=mock_client)

test_module()

# Verify query was called with correct parameters
mock_client.query.assert_called_once_with("SELECT 1", location="us-central1")
# Verify results
results_mock.assert_called_once_with("ok")
Loading