File size: 1,366 Bytes
af03eab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
os.environ["SUPABASE_URL"] = "http://localhost"
os.environ["SUPABASE_ANON_KEY"] = "fake"
os.environ["SUPABASE_DB_URL"] = "postgres://fake"

import pytest
from unittest.mock import patch
from fastapi.testclient import TestClient
from api import app

client = TestClient(app)

@patch("api.create_scan_job", return_value="123e4567-e89b-12d3-a456-426614174000")
@patch("api.run_background_scan")
def test_scan_async_endpoint(mock_run_bg, mock_create_scan_job):
    # Attempt to hit the new async endpoint
    response = client.post("/api/scan/async", json={
        "connector_type": "postgres",
        "host": "localhost",
        "port": "5432",
        "database": "mydb",
        "user": "user",
        "password": "pass",
        "table": "users"
    })
    
    # Should return 202 Accepted and a job_id
    assert response.status_code == 202
    data = response.json()
    assert "job_id" in data
    assert data["status"] == "queued"

def test_scan_status_endpoint():
    response = client.get("/api/scan/status/123e4567-e89b-12d3-a456-426614174000")
    assert response.status_code == 200
    data = response.json()
    assert "job_id" in data
    assert "status" in data

def test_catalog_endpoint():
    response = client.get("/api/catalog/mydb")
    assert response.status_code == 200
    data = response.json()
    assert isinstance(data, list)