2023-08-29 21:22:33 +00:00
|
|
|
import unittest
|
|
|
|
from typing import Any
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.graphs import FalkorDBGraph
|
2023-08-29 21:22:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestFalkorDB(unittest.TestCase):
|
|
|
|
def setUp(self) -> None:
|
|
|
|
self.host = "localhost"
|
|
|
|
self.graph = "test_falkordb"
|
|
|
|
self.port = 6379
|
|
|
|
|
|
|
|
@patch("redis.Redis")
|
|
|
|
def test_init(self, mock_client: Any) -> None:
|
|
|
|
mock_client.return_value = MagicMock()
|
|
|
|
FalkorDBGraph(database=self.graph, host=self.host, port=self.port)
|
|
|
|
|
|
|
|
@patch("redis.Redis")
|
|
|
|
def test_execute(self, mock_client: Any) -> None:
|
|
|
|
mock_client.return_value = MagicMock()
|
|
|
|
graph = FalkorDBGraph(database=self.graph, host=self.host, port=self.port)
|
|
|
|
|
|
|
|
query = "RETURN 1"
|
|
|
|
result = graph.query(query)
|
|
|
|
self.assertIsInstance(result, MagicMock)
|
|
|
|
|
|
|
|
@patch("redis.Redis")
|
|
|
|
def test_refresh_schema(self, mock_client: Any) -> None:
|
|
|
|
mock_client.return_value = MagicMock()
|
|
|
|
graph = FalkorDBGraph(database=self.graph, host=self.host, port=self.port)
|
|
|
|
|
|
|
|
graph.refresh_schema()
|
|
|
|
self.assertNotEqual(graph.get_schema, "")
|