Skip to content
Merged
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
47 changes: 47 additions & 0 deletions minder-tests/api-history.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
*** Settings ***
Resource resources/keywords.robot
Resource resources/variables.robot

Library resources.helpers
Library resources.profiles.Profiles
Library resources.github.GitHub

Suite Setup Set Rest Base URL From Config

Test Setup Default Setup
Test Teardown Default Teardown

*** Keywords ***
Default Setup
Set Provider as Environment Variable with Test Name
Set Project as Environment Variable with Test Name
Ruletypes are ready
Ruletypes are created
${MINDER_TEST_ORG}= Get Environment Variable MINDER_TEST_ORG
Set Suite Variable $MINDER_TEST_ORG

Default Teardown
Remove Provider Environment Variable for Test
Remove Project Environment Variable for Test

*** Test Cases ***
Test Evaluation History By ID API
[Documentation] Test that we can retrieve and verify evaluation history by ID

Given Client Adds A Profile test-profile

${test_repo}= Given random repo name ${MINDER_TEST_ORG} smoke-test-python
Given a copy of repo stacklok/demo-repo-python ${test_repo}
Given repo is registered ${test_repo}

When Client Retrieves Non Empty Eval History
Given History Format Is Valid
Then History Is Not Empty

${history_id}= Get First Evaluation History ID
${record}= Client Retrieves Eval History By ID ${history_id}

[Teardown] Run Keywords Cleanup Minder Profiles
... AND Cleanup Minder Repos
... AND Cleanup GitHub Repos
... AND Default Teardown
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ robotframework-requests==0.9.7
robotframework-datadriver==1.11.2
pyyaml==6.0.2
sh==2.0.7
tenacity==9.0.0
112 changes: 112 additions & 0 deletions resources/eval_history_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from robot.api.deco import keyword
from resources.minder_restapi_lib import MinderRestApiLib
from resources.errors import ConfigurationError, APIError
from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_exception_type


class EvalHistoryService:
Expand Down Expand Up @@ -72,3 +73,114 @@ def history_is_empty(self):
"""
if self.history["data"]:
raise ValueError("history should be empty")

@keyword
def history_is_not_empty(self):
"""
Verifies that the evaluation history is not empty.

Raises:
ValueError: If the history is empty.
"""
if not self.history or not self.history.get("data"):
raise ValueError("history should not be empty")

@keyword
@retry(
stop=stop_after_attempt(3),
wait=wait_exponential(multiplier=1, min=1, max=10),
retry=(retry_if_exception_type(APIError) | retry_if_exception_type(ValueError)),
reraise=True
)
def client_retrieves_non_empty_eval_history(self):
"""
Retrieves non-empty evaluation history from the Minder API with retries.
Retries up to 3 times with exponential backoff between 1 and 10 seconds.

Returns:
dict: The JSON response from the API.

Raises:
ConfigurationError: If required configuration is missing.
APIError: If the API request fails after maximum retries.
ValueError: If the history is empty after retrieval attempt.
"""
project = os.getenv("MINDER_PROJECT")
if not project:
raise ConfigurationError("MINDER_PROJECT environment variable is not set")

provider = os.getenv("MINDER_PROVIDER")
if not provider:
raise ConfigurationError("MINDER_PROVIDER environment variable is not set")

params = {
"provider": provider,
"context.project": project
}

try:
rest_api = MinderRestApiLib()
self.history = rest_api.get_request('/history', params=params)
if not self.history or not self.history.get("data"):
raise ValueError("Retrieved history is empty")
except Exception as e:
raise APIError(f"API request failed: {str(e)}")

@keyword
def get_first_evaluation_history_id(self):
"""
Retrieves the ID of the first evaluation history record.

Returns:
str: The ID of the first evaluation history record.

Raises:
ValueError: If the history is empty or no ID is found.
"""
if not self.history or not self.history.get("data"):
raise ValueError("No evaluation history data available")

# Assuming 'data' is a list of EvaluationHistory objects
first_record = self.history["data"][0]
history_id = first_record.get("id")

if not history_id:
raise ValueError("No ID found in the first evaluation history record")

return history_id

@keyword
def client_retrieves_eval_history_by_id(self, history_id):
"""
Retrieves evaluation history by ID from the Minder API.

Args:
history_id (str): The ID of the history to retrieve.

Returns:
dict: The JSON response from the API.

Raises:
ConfigurationError: If required environment variables are not set.
APIError: If the API request fails.
"""

project = os.getenv("MINDER_PROJECT")
if not project:
raise ConfigurationError("MINDER_PROJECT environment variable is not set")

provider = os.getenv("MINDER_PROVIDER")
if not provider:
raise ConfigurationError("MINDER_PROVIDER environment variable is not set")

params = {
"provider": provider,
"context.project": project
}

try:
rest_api = MinderRestApiLib()
response = rest_api.get_request(f'/history/{history_id}', params=params)
return response
except Exception as e:
raise APIError(f"API request failed: {str(e)}")