Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 7a72d63

Browse files
committed
Re-use call_provider for calling both codegate and the provider
Signed-off-by: Radoslav Dimitrov <[email protected]>
1 parent 2da3a74 commit 7a72d63

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

tests/integration/integration_tests.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,12 @@
1616
logger = structlog.get_logger("codegate")
1717

1818

19-
# call_directly is a function to call the model directly bypassing codegate
20-
def call_directly(url: str, headers: dict, data: dict) -> Optional[requests.Response]:
21-
try:
22-
headers["Content-Type"] = "application/json"
23-
stream = data.get("stream", False)
24-
response = requests.post(url, headers=headers, json=data, stream=stream)
25-
response.raise_for_status()
26-
return response
27-
except Exception as e:
28-
logger.error(f"Error making direct request to {url}: {str(e)}")
29-
return None
30-
31-
3219
class CodegateTestRunner:
3320
def __init__(self):
3421
self.requester_factory = RequesterFactory()
3522
self.failed_tests = [] # Track failed tests
3623

37-
def call_codegate(
24+
def call_provider(
3825
self, url: str, headers: dict, data: dict, provider: str, method: str = "POST"
3926
) -> Optional[requests.Response]:
4027
logger.debug(f"Creating requester for provider: {provider}")
@@ -146,21 +133,23 @@ def replacement(match):
146133
async def run_test(self, test: dict, test_headers: dict) -> bool:
147134
test_name = test["name"]
148135
data = json.loads(test["data"])
136+
codegate_url = test["url"]
137+
direct_provider_url = test.get(CodeGateEnrichment.KEY)["provider_url"]
149138
streaming = data.get("stream", False)
150139
provider = test["provider"]
151140
logger.info(f"Starting test: {test_name}")
152141

153142
# Call Codegate
154-
response = self.call_codegate(test["url"], test_headers, data, provider)
143+
response = self.call_provider(codegate_url, test_headers, data, provider)
155144
if not response:
156145
logger.error(f"Test {test_name} failed: No response received")
157146
return False
158147

159148
# Call model directly if specified
160149
direct_response = None
161150
if test.get(CodeGateEnrichment.KEY) is not None:
162-
direct_response = call_directly(
163-
test.get(CodeGateEnrichment.KEY)["provider_url"], test_headers, data
151+
direct_response = self.call_provider(
152+
direct_provider_url, test_headers, data, "not-codegate"
164153
)
165154
if not direct_response:
166155
logger.error(f"Test {test_name} failed: No direct response received")
@@ -412,6 +401,7 @@ async def main():
412401
# Exit with status code 1 if any tests failed
413402
if not all_tests_passed:
414403
sys.exit(1)
404+
logger.info("All tests passed")
415405

416406

417407
if __name__ == "__main__":

0 commit comments

Comments
 (0)