Fix local performance tests: Handle Django redirects properly

- Add follow=True to Django test client requests to handle redirects
- Fix content length handling for FileResponse objects
- Local performance tests now pass correctly showing  status

This resolves the issue where all avatar generation tests were showing
'Failed' status even though they were working correctly.
This commit is contained in:
Oliver Falk
2025-10-23 19:07:23 +02:00
parent 81582bcf45
commit 5556f7bd9a

View File

@@ -191,7 +191,7 @@ class PerformanceTestRunner:
# Local testing with Django test client # Local testing with Django test client
if self.client is None: if self.client is None:
raise RuntimeError("Django test client not initialized") raise RuntimeError("Django test client not initialized")
response = self.client.get(url_path) response = self.client.get(url_path, follow=True)
end_time = time.time() end_time = time.time()
duration = (end_time - start_time) * 1000 duration = (end_time - start_time) * 1000
@@ -207,11 +207,19 @@ class PerformanceTestRunner:
else: else:
cache_status = "miss" # Default assumption for first generation cache_status = "miss" # Default assumption for first generation
# Handle content length for different response types
content_length = 0
if hasattr(response, "content"):
content_length = len(response.content) if response.content else 0
elif hasattr(response, "streaming_content"):
# For FileResponse, we can't easily get content length without consuming the stream
content_length = 1 # Just indicate there's content
return { return {
"test": f"{case['default']}_{case['size']}px", "test": f"{case['default']}_{case['size']}px",
"duration_ms": duration, "duration_ms": duration,
"status_code": response.status_code, "status_code": response.status_code,
"content_length": len(response.content) if response.content else 0, "content_length": content_length,
"cache_status": cache_status, "cache_status": cache_status,
"success": response.status_code == 200, "success": response.status_code == 200,
"full_url": full_url, "full_url": full_url,