forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_openapi.py
54 lines (41 loc) 路 2.04 KB
/
test_openapi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import unittest
from typing import TYPE_CHECKING
from unittest.mock import patch
import pytest
if TYPE_CHECKING:
from openapi_pydantic import Info, Reference, Schema
from langchain_community.utilities.openapi import OpenAPISpec
class OpenAPISpecTestCase(unittest.TestCase):
@pytest.mark.requires("openapi-pydantic")
def setUp(self) -> None:
self.instance = OpenAPISpec(info=Info(title="test", version="1.0.0"))
@patch("langchain_community.utilities.openapi.OpenAPISpec.get_referenced_schema")
@pytest.mark.requires("openapi-pydantic")
def test_get_root_referenced_schema_with_obj_ref(self, mock_get_referenced_schema): # type: ignore[no-untyped-def]
address_schema = Schema()
address_schema.properties = {
"address": Reference(ref="#/components/schemas/Address")
}
address_ref_schema = Schema()
address_ref_schema.properties = {
"street": Schema(),
"city": Schema(),
"state": Schema(),
}
mock_get_referenced_schema.side_effect = [address_schema, address_ref_schema]
ref = Reference(ref="#/components/schemas/Pet")
result = self.instance._get_root_referenced_schema(ref)
self.assertIsInstance(result.properties["address"], Schema)
@patch("langchain_community.utilities.openapi.OpenAPISpec.get_referenced_schema")
@pytest.mark.requires("openapi-pydantic")
def test_get_root_referenced_schema_obj_arr_ref(self, mock_get_referenced_schema): # type: ignore[no-untyped-def]
hobby_schema = Schema()
hobby_schema.properties = {"hobby": Reference(ref="#/components/schemas/Hobby")}
hobby_ref_schema = Schema()
hobby_ref_schema.properties = {"name": Schema()}
mock_get_referenced_schema.side_effect = [hobby_schema, hobby_ref_schema]
ref = Reference(ref="#/components/schemas/Pet")
result = self.instance._get_root_referenced_schema(ref)
self.assertIsInstance(result.properties["hobby"], Schema)
if __name__ == "__main__":
unittest.main()