Test updates

This commit is contained in:
davidmezzetti
2026-07-23 10:10:28 -04:00
parent 50ca7b2fde
commit 86af7ec344
3 changed files with 89 additions and 16 deletions
-1
View File
@@ -24,7 +24,6 @@ class TestAuthorization(unittest.TestCase):
os.environ,
{
"CONFIG": os.path.join(tempfile.gettempdir(), "testapi.yml"),
"DEPENDENCIES": "txtai.api.Authorization",
"TOKEN": hashlib.sha256("token".encode("utf-8")).hexdigest(),
},
)
+66
View File
@@ -0,0 +1,66 @@
"""
Dependency module tests
"""
import os
import tempfile
import unittest
from unittest.mock import patch
from fastapi.testclient import TestClient
from txtai.api import application
class SampleDependency:
"""
Sample dependency
"""
def __call__(self):
raise NotImplementedError("Dependency test")
class TestDependency(unittest.TestCase):
"""
API tests for dependency injection
"""
@staticmethod
@patch.dict(
os.environ,
{"CONFIG": os.path.join(tempfile.gettempdir(), "testapi.yml"), "DEPENDENCIES": "testapi.testdependency.SampleDependency"},
)
def start():
"""
Starts a mock FastAPI client.
"""
config = os.path.join(tempfile.gettempdir(), "testapi.yml")
with open(config, "w", encoding="utf-8") as output:
output.write("embeddings:\n")
# Create new application and set on client
application.app = application.create()
client = TestClient(application.app)
application.start()
return client
@classmethod
def setUpClass(cls):
"""
Create API client on creation of class.
"""
cls.client = TestDependency.start()
def testDependency(self):
"""
Test dependency included
"""
with self.assertRaises(NotImplementedError):
self.client.get("search?query=test")