|
1 |
| -import os |
2 | 1 | import unittest
|
3 |
| -from unittest.mock import patch |
4 | 2 |
|
5 |
| -from chatbot.config import Settings |
| 3 | +from pydantic import ValidationError |
| 4 | + |
| 5 | +from chatbot.config import Settings, remove_postgresql_variants |
| 6 | + |
| 7 | + |
| 8 | +class TestRemovePostgresqlVariants(unittest.TestCase): |
| 9 | + def test_remove_psycopg(self): |
| 10 | + dsn = "postgresql+psycopg://user:pass@localhost/dbname" |
| 11 | + expected = "postgresql://user:pass@localhost/dbname" |
| 12 | + self.assertEqual(remove_postgresql_variants(dsn), expected) |
| 13 | + |
| 14 | + def test_remove_psycopg2(self): |
| 15 | + dsn = "postgresql+psycopg2://user:pass@localhost/dbname" |
| 16 | + expected = "postgresql://user:pass@localhost/dbname" |
| 17 | + self.assertEqual(remove_postgresql_variants(dsn), expected) |
| 18 | + |
| 19 | + def test_remove_psycopg2cffi(self): |
| 20 | + dsn = "postgresql+psycopg2cffi://user:pass@localhost/dbname" |
| 21 | + expected = "postgresql://user:pass@localhost/dbname" |
| 22 | + self.assertEqual(remove_postgresql_variants(dsn), expected) |
| 23 | + |
| 24 | + def test_no_change(self): |
| 25 | + dsn = "postgresql://user:pass@localhost/dbname" |
| 26 | + expected = "postgresql://user:pass@localhost/dbname" |
| 27 | + self.assertEqual(remove_postgresql_variants(dsn), expected) |
6 | 28 |
|
7 | 29 |
|
8 | 30 | class TestSettings(unittest.TestCase):
|
9 |
| - def test_default_inferece_url(self): |
| 31 | + def test_llm_default(self): |
10 | 32 | settings = Settings()
|
11 |
| - self.assertEqual(str(settings.llm.url), "http://localhost:8080") |
| 33 | + self.assertEqual(settings.llm, {"api_key": "NOT_SET"}) |
| 34 | + |
| 35 | + def test_llm_custom(self): |
| 36 | + custom_llm = {"model": "gpt-3", "version": "davinci"} |
| 37 | + settings = Settings(llm=custom_llm) |
| 38 | + self.assertEqual(settings.llm, custom_llm) |
12 | 39 |
|
13 |
| - @patch.dict(os.environ, {"LLM__URL": "http://foo.bar.com"}, clear=True) |
14 |
| - def test_inference_server_url(self): |
| 40 | + def test_psycopg_url_default(self): |
15 | 41 | settings = Settings()
|
16 |
| - self.assertEqual(str(settings.llm.url), "http://foo.bar.com/") |
| 42 | + expected = "postgresql://postgres:postgres@localhost:5432/" |
| 43 | + self.assertEqual(settings.psycopg_url, expected) |
| 44 | + |
| 45 | + def test_psycopg_url_custom(self): |
| 46 | + custom_url = "postgresql+psycopg2://custom_user:custom_pass@localhost/custom_db" |
| 47 | + settings = Settings(db_url=custom_url) |
| 48 | + expected = "postgresql://custom_user:custom_pass@localhost/custom_db" |
| 49 | + self.assertEqual(settings.psycopg_url, expected) |
| 50 | + |
| 51 | + def test_invalid_db_url(self): |
| 52 | + with self.assertRaises(ValidationError): |
| 53 | + Settings(db_url="invalid_url") |
17 | 54 |
|
18 | 55 |
|
19 | 56 | if __name__ == "__main__":
|
|
0 commit comments