From 9cbe9c1ccb2381e37402a36297f11a0f96b1b557 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Sun, 21 Jan 2024 02:20:23 +0100 Subject: Improve tests --- etc/unittest/backend.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 etc/unittest/backend.py (limited to 'etc/unittest/backend.py') 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 -- cgit v1.2.3