Skip to content

Commit be0049e

Browse files
committed
address comment]
1 parent db93cf9 commit be0049e

File tree

2 files changed

+69
-12
lines changed

2 files changed

+69
-12
lines changed

features/web_api/agenda_location_search.feature

+61
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,46 @@ Feature: Agenda Search - Filter Locations Based on State
8080
}
8181
"""
8282

83+
And we post json to "/push"
84+
"""
85+
{
86+
"guid": "event5", "type": "event", "state": "scheduled", "pubstatus": "usable",
87+
"slugline": "Empty Name Event",
88+
"name": "",
89+
"dates": {
90+
"start": "2018-05-28T04:00:00+0000",
91+
"end": "2018-05-28T05:00:00+0000",
92+
"tz": "Australia/Sydney"
93+
},
94+
"calendars": [{"qcode": "cal3", "name": "Calendar3"}],
95+
"subject": [
96+
{"code": "d3", "scheme": "sttdepartment", "name": "Dep3"},
97+
{"code": "s3", "scheme": "sttsubj", "name": "Sub3"},
98+
{"code": "e3", "scheme": "event_type", "name": "Art"}
99+
],
100+
"place": [
101+
{"code": "ON", "name": "Ontario"}
102+
],
103+
"anpa_category": [
104+
{"qcode": "e", "name": "Entertainment"},
105+
{"qcode": "f", "name": "Finance"}
106+
],
107+
"location": [{
108+
"name": "",
109+
"address": {
110+
"city": "",
111+
"state": "Ontario",
112+
"country": "Canada",
113+
"line": ["Empty Street"],
114+
"postal_code": "M5V 3L9",
115+
"type": "museum",
116+
"title": "Empty Location Name",
117+
"area": "Downtown Toronto"
118+
}
119+
}]
120+
}
121+
"""
122+
83123
@auth @admin
84124
Scenario: Verify locations are filtered based on event state
85125
When we get "/agenda/search_locations"
@@ -94,3 +134,24 @@ Feature: Agenda Search - Filter Locations Based on State
94134
]
95135
}
96136
"""
137+
138+
@auth @admin
139+
Scenario: Verify locations with empty names are not included in the response
140+
When we get "/agenda/search_locations"
141+
Then we get existing resource
142+
"""
143+
{
144+
"regions": [
145+
{
146+
"name": "New South Wales",
147+
"country": "Australia",
148+
"type": "state"
149+
},
150+
{
151+
"name": "Australia",
152+
"type": "country"
153+
}
154+
],
155+
"places": []
156+
}
157+
"""

newsroom/agenda/views.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,7 @@ def gen_agg_filter(field: str):
338338
}
339339

340340
def gen_agg_terms(field: str):
341-
return {
342-
"field": f"location.{field}.keyword",
343-
"size": 1000,
344-
}
341+
return {"field": f"location.{field}.keyword", "size": 1000, "exclude": [""]}
345342

346343
# Start with an empty aggregation structure
347344
es_query = {"size": 0, "aggs": {}}
@@ -461,14 +458,13 @@ def gen_agg_terms(field: str):
461458
]:
462459
country_name = country_bucket["key"]
463460
for state_bucket in country_bucket["states"]["buckets"]:
464-
if state_bucket["key"]:
465-
regions.append(
466-
{
467-
"name": state_bucket["key"],
468-
"country": country_name,
469-
"type": "state",
470-
}
471-
)
461+
regions.append(
462+
{
463+
"name": state_bucket["key"],
464+
"country": country_name,
465+
"type": "state",
466+
}
467+
)
472468

473469
if location_filter_options.get("country", True):
474470
for country_bucket in (aggs.get("countries") or aggs["country_search"]["countries"])["buckets"]:

0 commit comments

Comments
 (0)