| | import unittest |
| | import os |
| | from unittest.mock import patch |
| | from backend.config.database import db_settings |
| |
|
| | class TestMongoAtlasSettings(unittest.TestCase): |
| |
|
| | @patch.dict(os.environ, { |
| | 'VECTOR_STORE_PROVIDER': 'mongodb' |
| | }) |
| | def test_mongo_settings(self): |
| | """ |
| | Test mongodb config contains expected fields when VECTOR_STORE_PROVIDER is set |
| | """ |
| | |
| | db_settings.__init__() |
| |
|
| | db_config = db_settings.get_vector_store_config() |
| | self.assertTrue('collection_name' in db_config) |
| | self.assertTrue('index_name' in db_config) |
| | self.assertTrue('text_field' in db_config) |
| |
|
| | class TestChromaDBSettings(unittest.TestCase): |
| |
|
| | @patch.dict(os.environ, { |
| | 'VECTOR_STORE_PROVIDER': 'chromadb' |
| | }) |
| | def test_mongo_settings(self): |
| | """ |
| | Test chromadb config contains expected fields when VECTOR_STORE_PROVIDER is set |
| | """ |
| | |
| | db_settings.__init__() |
| |
|
| | db_config = db_settings.get_vector_store_config() |
| | self.assertTrue('collection_name' in db_config) |
| | self.assertTrue('persist_directory' in db_config) |
| | self.assertTrue('refresh_on_start' in db_config) |
| |
|
| | class TestInvalidDBSettings(unittest.TestCase): |
| |
|
| | @patch.dict(os.environ, { |
| | 'VECTOR_STORE_PROVIDER': 'postgres' |
| | }) |
| | def test_mongo_settings(self): |
| | """ |
| | Test invalid db config raises correct error |
| | """ |
| | |
| | db_settings.__init__() |
| |
|
| | with self.assertRaisesRegex(ValueError, "Unsupported"): |
| | db_settings.get_vector_store_config() |
| |
|