|
1 | 1 | """Implementation of common test steps.""" |
2 | 2 |
|
| 3 | +import json |
3 | 4 | from behave import then # pyright: ignore[reportAttributeAccessIssue] |
4 | 5 | from behave.runner import Context |
5 | 6 |
|
@@ -97,3 +98,64 @@ def check_shield_structure(context: Context) -> None: |
97 | 98 | assert ( |
98 | 99 | found_shield["identifier"] == "llama-guard-shield" |
99 | 100 | ), "identifier should be 'llama-guard-shield'" |
| 101 | + |
| 102 | + |
| 103 | +@then("The response contains {count:d} tools listed for provider {provider_name}") |
| 104 | +def check_tool_count(context: Context, count: int, provider_name: str) -> None: |
| 105 | + """Check that the number of tools for defined provider is correct.""" |
| 106 | + response_json = context.response.json() |
| 107 | + assert response_json is not None, "Response is not valid JSON" |
| 108 | + |
| 109 | + assert "tools" in response_json, "Response missing 'tools' field" |
| 110 | + tools = response_json["tools"] |
| 111 | + assert len(tools) > 0, "Response has empty list of tools" |
| 112 | + |
| 113 | + provider_tools = [] |
| 114 | + |
| 115 | + for tool in tools: |
| 116 | + if tool["provider_id"] == provider_name: |
| 117 | + provider_tools.append(tool) |
| 118 | + |
| 119 | + assert len(provider_tools) == count |
| 120 | + |
| 121 | + |
| 122 | +@then("The body of the response has proper structure for provider {provider_name}") |
| 123 | +def check_tool_structure(context: Context, provider_name: str) -> None: |
| 124 | + """Check that the first listed tool for defined provider has the correct structure.""" |
| 125 | + response_json = context.response.json() |
| 126 | + assert response_json is not None, "Response is not valid JSON" |
| 127 | + |
| 128 | + expected_json = json.loads(context.text) |
| 129 | + |
| 130 | + assert "tools" in response_json, "Response missing 'tools' field" |
| 131 | + tools = response_json["tools"] |
| 132 | + assert len(tools) > 0, "Response has empty list of tools" |
| 133 | + |
| 134 | + provider_tool = None |
| 135 | + |
| 136 | + for tool in tools: |
| 137 | + if tool["provider_id"] == provider_name: |
| 138 | + provider_tool = tool |
| 139 | + break |
| 140 | + |
| 141 | + assert provider_tool is not None, "No tool found in response" |
| 142 | + |
| 143 | + # Validate structure and values |
| 144 | + assert ( |
| 145 | + provider_tool["identifier"] == expected_json["identifier"] |
| 146 | + ), f"identifier should be {expected_json["identifier"]}, but was {provider_tool["identifier"]}" |
| 147 | + assert ( |
| 148 | + provider_tool["description"] == expected_json["description"] |
| 149 | + ), f"description should be {expected_json["description"]}" |
| 150 | + assert ( |
| 151 | + provider_tool["provider_id"] == expected_json["provider_id"] |
| 152 | + ), f"provider_id should be {expected_json["provider_id"]}" |
| 153 | + assert ( |
| 154 | + provider_tool["toolgroup_id"] == expected_json["toolgroup_id"] |
| 155 | + ), f"toolgroup_id should be {expected_json["toolgroup_id"]}" |
| 156 | + assert ( |
| 157 | + provider_tool["server_source"] == expected_json["server_source"] |
| 158 | + ), f"server_source should be {expected_json["server_source"]}" |
| 159 | + assert ( |
| 160 | + provider_tool["type"] == expected_json["type"] |
| 161 | + ), f"type should be {expected_json["type"]}" |
0 commit comments