2023-10-05 20:48:11 +00:00
|
|
|
import json
|
|
|
|
import os
|
|
|
|
from unittest import mock
|
|
|
|
|
2023-11-21 16:35:29 +00:00
|
|
|
from langchain_core.documents import Document
|
2023-10-05 20:48:11 +00:00
|
|
|
from requests import Response
|
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.retrievers.you import YouRetriever
|
2023-10-05 20:48:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestYouRetriever:
|
|
|
|
def test_get_relevant_documents(self) -> None:
|
|
|
|
os.environ["YDC_API_KEY"] = "MOCK KEY!"
|
|
|
|
retriever = YouRetriever()
|
|
|
|
|
|
|
|
with mock.patch("requests.get") as mock_get:
|
|
|
|
fixture = {"hits": [{"snippets": ["yo"]}, {"snippets": ["bird up"]}]}
|
|
|
|
response = Response()
|
|
|
|
response._content = bytes(json.dumps(fixture).encode("utf-8"))
|
|
|
|
mock_get.return_value = response
|
|
|
|
|
|
|
|
actual = retriever.get_relevant_documents("test")
|
|
|
|
assert actual == [
|
|
|
|
Document(page_content="yo"),
|
|
|
|
Document(page_content="bird up"),
|
|
|
|
]
|