feat: expose native configured model discovery API (#18)
This commit is contained in:
@@ -27,9 +27,9 @@ def main():
|
||||
config.write_text(json.dumps({'bind': f'127.0.0.1:{port}', 'api_key_file': str(key), 'model': 'auth-cpu-smoke'}))
|
||||
env = {'PATH': os.defpath}
|
||||
|
||||
def request(path, headers=(), body=None):
|
||||
def request(path, headers=(), body=None, method=None):
|
||||
conn = http.client.HTTPConnection('127.0.0.1', port, timeout=2)
|
||||
conn.putrequest('POST' if body is not None else 'GET', path)
|
||||
conn.putrequest(method or ('POST' if body is not None else 'GET'), path)
|
||||
for name, value in headers:
|
||||
conn.putheader(name, value)
|
||||
if body is not None:
|
||||
@@ -59,6 +59,18 @@ def main():
|
||||
assert code == 401
|
||||
assert response_headers.get('www-authenticate') == 'Bearer'
|
||||
auth = (('Authorization', 'Bearer ' + token),)
|
||||
model_record = {'id': 'auth-cpu-smoke', 'object': 'model', 'created': 0, 'owned_by': 'local'}
|
||||
for path in ['/v1/models', '/v1/models/auth-cpu-smoke', '/v1/models/missing?x=1']:
|
||||
assert request(path)[0] == 401
|
||||
assert request(path, (('Authorization', 'Bearer wrong'),))[0] == 401
|
||||
assert json.loads(request('/v1/models', auth)[2]) == {'object': 'list', 'data': [model_record]}
|
||||
assert json.loads(request('/v1/models/auth-cpu-smoke', auth)[2]) == model_record
|
||||
missing = request('/v1/models/missing', auth)
|
||||
assert missing[0] == 404 and json.loads(missing[2])['error']['code'] == 'model_not_found'
|
||||
for path in ['/v1/models?limit=1', '/v1/models/auth-cpu-smoke?x=1']:
|
||||
assert request(path, auth)[0] == 400
|
||||
for method, path in [('POST', '/v1/models'), ('DELETE', '/v1/models/auth-cpu-smoke')]:
|
||||
assert request(path, auth, method=method)[0] == 405
|
||||
assert request('/status')[0] == 401
|
||||
assert request('/ready')[0] == 401
|
||||
assert request('/metrics')[0] == 401
|
||||
@@ -79,6 +91,8 @@ def main():
|
||||
assert request('/v1/responses', auth, b'not-json')[0] == 400
|
||||
assert json.loads(request('/admin/lifecycle', auth)[2])['draining'] is False
|
||||
assert json.loads(request('/admin/drain', auth, b'{}')[2])['drained'] is True
|
||||
assert json.loads(request('/v1/models', auth)[2]) == {'object': 'list', 'data': [model_record]}
|
||||
assert json.loads(request('/metrics', auth)[2])['generation']['started'] == 0
|
||||
assert request('/v1/responses', auth, b'not-json')[0] == 503
|
||||
assert json.loads(request('/admin/resume', auth, b'{}')[2])['draining'] is False
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user