gpt4free/etc/unittest/backend.py
H Lohaus 6ce493d4df
Fix api streaming, fix AsyncClient (#2357)
* Fix api streaming, fix AsyncClient, Improve Client class, Some providers fixes, Update models list, Fix some tests, Update model list in Airforce provid
er, Add OpenAi image generation url to api, Fix reload and debug in api arguments, Fix websearch in gui

* Fix Cloadflare and Pi and AmigoChat provider

* Fix conversation support in DDG provider, Add cloudflare bypass with nodriver

* Fix unittests without curl_cffi
2024-11-16 13:19:51 +01:00

49 lines
No EOL
1.4 KiB
Python

from __future__ import annotations
import unittest
import asyncio
from unittest.mock import MagicMock
from g4f.errors import MissingRequirementsError
try:
from g4f.gui.server.backend import Backend_Api
has_requirements = True
except:
has_requirements = False
try:
from duckduckgo_search.exceptions import DuckDuckGoSearchException
except ImportError:
class DuckDuckGoSearchException:
pass
class TestBackendApi(unittest.TestCase):
def setUp(self):
if not has_requirements:
self.skipTest("gui is not installed")
self.app = MagicMock()
self.api = Backend_Api(self.app)
def test_version(self):
response = self.api.get_version()
self.assertIn("version", response)
self.assertIn("latest_version", response)
def test_get_models(self):
response = self.api.get_models()
self.assertIsInstance(response, list)
self.assertTrue(len(response) > 0)
def test_get_providers(self):
response = self.api.get_providers()
self.assertIsInstance(response, dict)
self.assertTrue(len(response) > 0)
def test_search(self):
from g4f.gui.server.internet import search
try:
result = asyncio.run(search("Hello"))
except DuckDuckGoSearchException as e:
self.skipTest(e)
except MissingRequirementsError:
self.skipTest("search is not installed")
self.assertEqual(5, len(result))