Skip to content

Commit c5a2d1a

Browse files
committed
feat: POC automation test for AI using python
JIRA: QA-23855 risk: nonprod
1 parent 40b351c commit c5a2d1a

19 files changed

+1025
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ docs/resources/_gen
1616
docs/tmp/
1717
docs/versioned_docs
1818
docs/.hugo_build.lock
19+
20+
integration_tests/**/__pycache__

gooddata-sdk/gooddata_sdk/compute/service.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,21 @@ def ai_chat_history_reset(self, workspace_id: str) -> None:
105105
Args:
106106
workspace_id: workspace identifier
107107
"""
108-
chat_history_request = ChatHistoryRequest(reset=True)
108+
chat_history_request = ChatHistoryRequest(
109+
reset=True,
110+
)
111+
self._actions_api.ai_chat_history(workspace_id, chat_history_request, _check_return_type=False)
112+
113+
def ai_chat_history_user_feedback(
114+
self, workspace_id: str, chat_history_interaction_id: int = 0, user_feedback: str = "POSITIVE"
115+
) -> None:
116+
"""
117+
Reset chat history with AI in GoodData workspace.
118+
119+
Args:
120+
workspace_id: workspace identifier
121+
"""
122+
chat_history_request = ChatHistoryRequest(
123+
chat_history_interaction_id=chat_history_interaction_id, user_feedback=user_feedback
124+
)
109125
self._actions_api.ai_chat_history(workspace_id, chat_history_request, _check_return_type=False)

integration_tests/.env.template

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# (C) 2024 GoodData Corporation
2+
HOST=
3+
TOKEN=
4+
DATASOURCE_ID=
5+
WORKSPACE_ID=
6+
LLM_TOKEN=

integration_tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# (C) 2021 GoodData Corporation

integration_tests/conftest.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# (C) 2024 GoodData Corporation
2+
# filepath: /Users/tubui/Documents/CODE/gooddata-python-sdk-1/gooddata-sdk/integration_tests/scripts/conftest.py
3+
import os
4+
5+
import pytest
6+
from dotenv import load_dotenv
7+
8+
# Load the .env file from the current directory
9+
load_dotenv()
10+
11+
12+
@pytest.fixture(scope="session", autouse=True)
13+
def setup_env():
14+
# Ensure that the environment variables are set
15+
os.environ["HOST"] = os.getenv("HOST", "https://checklist.staging.stg11.panther.intgdc.com")
16+
os.environ["TOKEN"] = os.getenv("TOKEN", "")
17+
os.environ["DATASOURCE_ID"] = os.getenv("DATASOURCE_ID", "")
18+
os.environ["WORKSPACE_ID"] = os.getenv("WORKSPACE_ID", "")
19+
os.environ["DATASOURCE_TYPE"] = os.getenv("DATASOURCE_TYPE", "")
20+
os.environ["DATASOURCE_PASSWORD"] = os.getenv("DATASOURCE_PASSWORD", "")
21+
22+
# Check if the necessary environment variables are set
23+
if not os.environ["HOST"]:
24+
raise OSError("\nHOST environment variable is not set.")
25+
if not os.environ["TOKEN"]:
26+
raise OSError("\nTOKEN environment variable is not set.")
27+
if not os.environ["DATASOURCE_ID"]:
28+
print("\nWarning: DATA_SOURCE_ID environment variable is not set.")
29+
if not os.environ["WORKSPACE_ID"]:
30+
print("\nWarning: WORKSPACE_ID environment variable is not set.")
31+
if not os.environ["DATASOURCE_TYPE"]:
32+
print("\nWarning: DATASOURCE_TYPE environment variable is not set.")
33+
if not os.environ["DATASOURCE_PASSWORD"]:
34+
print("\nWarning: DATASOURCE_PASSWORD environment variable is not set.")
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"id": "total_returns_per_month",
3+
"title": "Total Returns per Month",
4+
"visualizationType": "COLUMN",
5+
"metrics": [
6+
{
7+
"id": "total_returns",
8+
"type": "metric",
9+
"title": "Total Returns"
10+
}
11+
],
12+
"dimensionality": [
13+
{
14+
"id": "return_date.month",
15+
"type": "attribute",
16+
"title": "Return date - Month/Year"
17+
}
18+
],
19+
"filters": [],
20+
"suggestions": [
21+
{
22+
"query": "Switch to a line chart to better visualize the trend of total returns over the months.",
23+
"label": "Line Chart for Trends"
24+
},
25+
{
26+
"query": "Filter the data to show total returns for this year only.",
27+
"label": "This Year's Returns"
28+
}
29+
]
30+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"id": "number_of_order_ids",
3+
"title": "Number of Order IDs",
4+
"visualizationType": "HEADLINE",
5+
"metrics": [
6+
{
7+
"id": "order_id",
8+
"type": "attribute",
9+
"title": "Number of Order IDs",
10+
"aggFunction": "COUNT"
11+
}
12+
],
13+
"dimensionality": [],
14+
"filters": [],
15+
"suggestions": [
16+
{
17+
"query": "Show the number of orders by year",
18+
"label": "Show by Year"
19+
}
20+
]
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"question": "What is number of order id, show as HEADLINE chart?",
4+
"expected_objects_file": "headline_count_of_order.json"
5+
},
6+
{
7+
"question": "What is total returns per month? show as COLUMN chart",
8+
"expected_objects_file": "column_total_returns_by_month.json"
9+
}
10+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# (C) 2021 GoodData Corporation

integration_tests/scenarios/aiChat.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# (C) 2024 GoodData Corporation
2+
import os
3+
import sys
4+
from pprint import pprint
5+
6+
import pytest
7+
from dotenv import load_dotenv
8+
from gooddata_sdk import GoodDataSdk
9+
10+
SCRIPTS_DIR = os.path.dirname(os.path.abspath(__file__))
11+
sys.path.append(SCRIPTS_DIR)
12+
13+
# Load environment variables from the .env file
14+
load_dotenv()
15+
16+
# Create the test_config dictionary with the loaded environment variables
17+
test_config = {"host": os.getenv("HOST"), "token": os.getenv("TOKEN")}
18+
workspace_id = os.getenv("WORKSPACE_ID")
19+
20+
questions = ["What is number of order line id ?"]
21+
sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"])
22+
23+
24+
def test_reset_chat_history():
25+
sdk.compute.ai_chat_history_reset(workspace_id)
26+
27+
28+
@pytest.mark.parametrize("question", questions)
29+
def test_ask_ai(question):
30+
chat_ai_res = sdk.compute.ai_chat(workspace_id, question=question)
31+
pprint(chat_ai_res.to_dict())
32+
assert chat_ai_res["created_visualizations"] is not None, "Created visualizations should not be None"
33+
assert chat_ai_res["routing"] is not None, "Routing should not be None"
34+
35+
36+
def test_ai_chat_history():
37+
chat_ai_res = sdk.compute.ai_chat(workspace_id, question="show me a headline generating net sales and net order")
38+
chat_ai_res.to_dict()
39+
chat_history_interaction_id = chat_ai_res["chat_history_interaction_id"]
40+
pprint(chat_history_interaction_id)
41+
chat_history_res = sdk.compute.ai_chat_history(workspace_id, chat_history_interaction_id)
42+
sdk.compute.ai_chat_history_user_feedback(workspace_id, chat_history_interaction_id, "POSITIVE")
43+
pprint(chat_history_res.to_dict())
44+
45+
46+
def test_get_chat_history():
47+
chat_history_res = sdk.compute.ai_chat_history(workspace_id)
48+
pprint(chat_history_res.to_dict())
49+
assert chat_history_res["interactions"] is not None, "Interactions should not be None"
50+
assert (
51+
chat_history_res["interactions"][0]["question"] == "What is number of order line id ?"
52+
), "First interaction question should match"
53+
54+
55+
if __name__ == "__main__":
56+
pytest.main()

0 commit comments

Comments
 (0)