mirror of
https://github.com/neuml/txtai.git
synced 2026-10-12 02:19:52 +00:00
Test updates
This commit is contained in:
@@ -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(),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user