File size: 785 Bytes
c4e3b10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""TestClient shim for local fastapi package.

"""
try:
    # If requests and starlette are available, a more realistic client could be used.
    pass
except Exception:
    pass

class TestClient:
    def __init__(self, app):
        self.app = app

    def get(self, path: str):
        for method, route_path, fn in getattr(self.app, '_routes', []):
            if method == 'GET' and route_path == path:
                result = fn()
                class Resp:
                    status_code = 200
                    def json(self):
                        return result
                return Resp()
        class Resp404:
            status_code = 404
            def json(self):
                return {"detail": "Not Found"}
        return Resp404()