forked from JLucasFFerraz/DBpedia_doc_onto_extraction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI_unit_tests.py
118 lines (93 loc) · 3.82 KB
/
API_unit_tests.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import unittest
from unittest.mock import patch
import json
import requests
# Define the API endpoint
api_endpoint = "http://127.0.0.1:8014/search"
def perform_search_case(case_data):
headers = {
"Content-Type": "application/json"
}
response = requests.post(api_endpoint, headers=headers, data=json.dumps(case_data))
return response
class TestSearchAPI(unittest.TestCase):
@patch('requests.post') # Mock the requests.post method
def test_simple_fuzzy_filtering(self, mock_post):
case_data = {
"fuzzy_filters": {"label": "date"},
"fuzzy_filters_config": {"model_name": "LaBSE"},
}
# Set up the mock response
mock_response = {
"result": "some_result",
"status": "success"
}
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = mock_response
# Perform the search
response = perform_search_case(case_data)
# Print the response
print("Test: test_simple_fuzzy_filtering")
print("Status Code:", response.status_code)
print("Response JSON:", response.json())
# Check the mock response
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), mock_response)
@patch('requests.post')
def test_simple_exact_filtering(self, mock_post):
case_data = {
"exact_filters": {"termtype": "ObjectProperty"}
}
mock_response = {
"result": "exact_result",
"status": "success"
}
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = mock_response
response = perform_search_case(case_data)
# Print the response
print("Test: test_simple_exact_filtering")
print("Status Code:", response.status_code)
print("Response JSON:", response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), mock_response)
@patch('requests.post')
def test_complex_exact_filtering(self, mock_post):
case_data = {
"exact_filters": {"termtype": "ObjectProperty", "domain": 'http://www.demcare.eu/ontologies/demlab.owl#Protocol'}
}
mock_response = {
"result": "complex_exact_result",
"status": "success"
}
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = mock_response
response = perform_search_case(case_data)
# Print the response
print("Test: test_complex_exact_filtering")
print("Status Code:", response.status_code)
print("Response JSON:", response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), mock_response)
@patch('requests.post')
def test_complex_fuzzy_filtering(self, mock_post):
case_data = {
"fuzzy_filters": {"label": "date", "domain": "creative work"},
"fuzzy_filters_config": {"model_name": "LaBSE"},
"exact_filters": {"termtype": "ObjectProperty"}
}
mock_response = {
"result": "complex_fuzzy_result",
"status": "success"
}
mock_post.return_value.status_code = 200
mock_post.return_value.json.return_value = mock_response
response = perform_search_case(case_data)
# Print the response
print("Test: test_complex_fuzzy_filtering")
print("Status Code:", response.status_code)
print("Response JSON:", response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), mock_response)
if __name__ == '__main__':
unittest.main()