Skip to content

Commit 055d47b

Browse files
authored
Merge pull request #478 from ror-community/single-search-marple-implementation
Adding single search
2 parents c3e643f + 5e48232 commit 055d47b

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

rorapi/tests/tests_unit/tests_views_v2.py

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,55 @@ def setUp(self):
2323
self.test_data = json.load(f)
2424

2525
@mock.patch('elasticsearch_dsl.Search.execute')
26-
def test_search_organizations_with_affiliations_match(self, search_mock):
26+
def test_search_organizations_with_affiliations_match(self, search_mock):
27+
# Create mock data with affiliation_match field required for single search
28+
mock_hit = {
29+
"_index": "organizations-v2",
30+
"_type": "_doc",
31+
"_id": "https://ror.org/02en5vm52",
32+
"_score": 1.0,
33+
"_source": {
34+
"id": "https://ror.org/02en5vm52",
35+
"status": "active",
36+
"locations": [
37+
{
38+
"geonames_id": 2988507,
39+
"geonames_details": {
40+
"continent_code": "EU",
41+
"continent_name": "Europe",
42+
"country_code": "FR",
43+
"country_name": "France",
44+
"lat": 48.8566,
45+
"lng": 2.3522,
46+
"name": "Paris"
47+
}
48+
}
49+
],
50+
"names": [
51+
{
52+
"value": "Sorbonne University",
53+
"types": ["ror_display", "label"],
54+
"lang": null
55+
}
56+
],
57+
"affiliation_match": {
58+
"names": [
59+
{"name": "Sorbonne University"},
60+
{"name": "Sorbonne Université"},
61+
{"name": "Université de la Sorbonne"}
62+
]
63+
},
64+
"types": ["Education"],
65+
"established": 2018
66+
}
67+
}
68+
69+
mock_response = IterableAttrDict(
70+
{"hits": {"hits": [mock_hit], "total": {"value": 1}}},
71+
[mock_hit]
72+
)
73+
search_mock.return_value = mock_response
74+
2775
view = views.OrganizationViewSet.as_view({'get': 'list'})
2876
data = {'affiliation':'Sorbonne University, France',
2977
'single_search': ''}
@@ -34,7 +82,9 @@ def test_search_organizations_with_affiliations_match(self, search_mock):
3482
organizations = json.loads(response.content.decode('utf-8'))
3583

3684
print("testing affiliations match: ", organizations)
37-
self.assertNotEqual(organizations['number_of_results'], 0)
85+
self.assertEqual(response.status_code, 200)
86+
self.assertIn('items', organizations)
87+
self.assertGreater(len(organizations['items']), 0)
3888

3989

4090
@mock.patch('elasticsearch_dsl.Search.execute')

0 commit comments

Comments
 (0)