
import requests
import os

def test_export_endpoint():
    # The app runs on port 8000 inside the container.
    # The root_path is /ce, so the full URL is http://localhost:8000/ce/api/companies/export
    url = "http://localhost:8000/ce/api/companies/export"
    
    print(f"--- Testing Export Endpoint: GET {url} ---")
    
    try:
        response = requests.get(url)
        response.raise_for_status() # Will raise an exception for 4xx/5xx errors
        
        # Print the first few hundred characters to verify content
        print("\n--- Response Headers ---")
        print(response.headers)
        
        print("\n--- CSV Output (first 500 chars) ---")
        print(response.text[:500])

        # A simple check
        if "Metric Value" in response.text and "Source URL" in response.text:
            print("\n[SUCCESS] New columns found in export.")
        else:
            print("\n[FAILURE] New columns seem to be missing from the export.")

    except requests.exceptions.RequestException as e:
        print(f"\n[FAILURE] Could not connect to the endpoint: {e}")

if __name__ == "__main__":
    test_export_endpoint()

