File size: 1,079 Bytes
cc564ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from pathlib import Path

import pytest
import respx
from httpx import Response
from fastapi.testclient import TestClient

from app.main import app

@pytest.fixture(autouse=True)
def mock_http(respx_mock: respx.MockRouter):
    # 1) Mock SerpAPI (Google) search
    gh_search = json.loads(Path("test/data/github_search.json").read_text())
    respx_mock.get("https://serpapi.com/search.json").mock(
        return_value=Response(200, json=gh_search)
    )

    # 2) Mock GitHub profile HTML fetch
    gh_html = Path("test/data/github_profile.html").read_text()
    respx_mock.get(respx.MockRouter._compile(r"https://github\.com/.*")).mock(
        return_value=Response(200, text=gh_html)
    )

    # 3) Mock RapidAPI LinkedIn profile fetch
    ln_json = json.loads(Path("test/data/mock_linkedin.json").read_text())
    respx_mock.get(respx.MockRouter._compile(r"https://fresh-linkedin-profile-data\.p\.rapidapi\.com/.*")).mock(
        return_value=Response(200, json=ln_json)
    )

    yield

@pytest.fixture
def client() -> TestClient:
    return TestClient(app)