summaryrefslogtreecommitdiffstats
path: root/etc/unittest/backend.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-21 09:37:35 +0100
committerGitHub <noreply@github.com>2024-01-21 09:37:35 +0100
commitfea4f546a7fb7c7af5a3da2247b5ea966e179f08 (patch)
tree59266fc31ec6df5fa53ef97b22f024f2f3f339f8 /etc/unittest/backend.py
parentMerge pull request #1484 from hlohaus/copilot (diff)
parentUpdate workflow (diff)
downloadgpt4free-fea4f546a7fb7c7af5a3da2247b5ea966e179f08.tar
gpt4free-fea4f546a7fb7c7af5a3da2247b5ea966e179f08.tar.gz
gpt4free-fea4f546a7fb7c7af5a3da2247b5ea966e179f08.tar.bz2
gpt4free-fea4f546a7fb7c7af5a3da2247b5ea966e179f08.tar.lz
gpt4free-fea4f546a7fb7c7af5a3da2247b5ea966e179f08.tar.xz
gpt4free-fea4f546a7fb7c7af5a3da2247b5ea966e179f08.tar.zst
gpt4free-fea4f546a7fb7c7af5a3da2247b5ea966e179f08.zip
Diffstat (limited to 'etc/unittest/backend.py')
-rw-r--r--etc/unittest/backend.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/etc/unittest/backend.py b/etc/unittest/backend.py
new file mode 100644
index 00000000..f5961e2d
--- /dev/null
+++ b/etc/unittest/backend.py
@@ -0,0 +1,38 @@
+from . import include
+import unittest
+from unittest.mock import MagicMock
+from .mocks import ProviderMock
+import g4f
+from g4f.gui.server.backend import Backend_Api, get_error_message
+
+class TestBackendApi(unittest.TestCase):
+
+ def setUp(self):
+ 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, list)
+ self.assertTrue(len(response) > 0)
+
+class TestUtilityFunctions(unittest.TestCase):
+
+ def test_get_error_message(self):
+ g4f.debug.last_provider = ProviderMock
+ exception = Exception("Message")
+ result = get_error_message(exception)
+ self.assertEqual("ProviderMock: Exception: Message", result)
+
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file