deploy Nous v15 update
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import urllib.error
|
||||
import unittest
|
||||
from http.client import HTTPConnection
|
||||
from unittest.mock import patch
|
||||
@@ -116,6 +117,26 @@ class BrowserOnlyAppTests(unittest.TestCase):
|
||||
self.assertTrue(body["ok"])
|
||||
self.assertEqual(http_json.call_args.args[0:2], ("POST", "https://inference-api.nousresearch.com/v1/chat/completions"))
|
||||
|
||||
def test_provider_errors_are_not_mislabelled_as_maps_errors(self):
|
||||
class CloudflareResponse:
|
||||
def read(self):
|
||||
return b'{"error_code":1010,"detail":"blocked"}'
|
||||
|
||||
def close(self):
|
||||
return None
|
||||
|
||||
code = 403
|
||||
|
||||
with patch("api.server.urllib.request.urlopen", side_effect=urllib.error.HTTPError("https://inference-api.nousresearch.com/v1/chat/completions", 403, "Forbidden", {}, CloudflareResponse())):
|
||||
with self.assertRaisesRegex(RuntimeError, r"^ai_cloudflare_1010:"):
|
||||
server.http_json("POST", "https://inference-api.nousresearch.com/v1/chat/completions", {}, error_prefix="ai")
|
||||
|
||||
def test_provider_requests_send_explicit_user_agent(self):
|
||||
response = type("Response", (), {"__enter__": lambda self: self, "__exit__": lambda self, *args: None, "read": lambda self: b"{}"})()
|
||||
with patch("api.server.urllib.request.urlopen", return_value=response) as open_url:
|
||||
server.http_json("GET", "https://example.test/v1/models", error_prefix="ai")
|
||||
self.assertEqual(open_url.call_args.args[0].headers.get("User-agent"), server.OUTBOUND_USER_AGENT)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user