Skip to content

Commit

Permalink
Merge pull request #195 from datosgobar/175-publisher-name-endpoint
Browse files Browse the repository at this point in the history
publisher name endpoint
  • Loading branch information
lucaslavandeira authored Feb 20, 2018
2 parents 0fdd304 + 446a96b commit 5e847be
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions series_tiempo_ar_api/apps/metadata/indexer/doc_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Field(DocType):
dataset_description = Text()
theme_description = Text()
units = Keyword()
dataset_publisher_name = Keyword()

# Guardamos una copia como keyword para poder usar en aggregations
dataset_source = Text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def scrap_datajson(self):
dataset_source=dataset['source'],
dataset_source_keyword=dataset['source'],
dataset_description=dataset['description'],
dataset_publisher_name=dataset['publisher']['name'],
theme_description=themes[dataset['theme'][0]]
)
actions.append(doc.to_dict(include_meta=True))
Expand Down
14 changes: 14 additions & 0 deletions series_tiempo_ar_api/apps/metadata/tests/view_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ def test_run(self):
response_sources = json.loads(response.content)['data']
# Expected: search results in 'data' list
self.assertIn(test_unit, response_sources)


class PublisherNameTests(TestCase):

def test_run(self):
test_unit = 'Test publisher name'
search_mock = mock.MagicMock()
search_mock.aggregations.results.buckets = [{'key': test_unit}]

with mock.patch.object(Search, 'execute', return_value=search_mock):
response = self.client.get(reverse('api:metadata:dataset_publisher_name'))
response_sources = json.loads(response.content)['data']
# Expected: search results in 'data' list
self.assertIn(test_unit, response_sources)
3 changes: 2 additions & 1 deletion series_tiempo_ar_api/apps/metadata/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!coding=utf8
from django.conf.urls import url

from .views import search, dataset_source, field_units
from .views import search, dataset_source, field_units, dataset_publisher_name

urlpatterns = [
url('^$', search, name='search'),
url('^dataset_source$', dataset_source, name='dataset_source'),
url('^field_units$', field_units, name='field_units'),
url('^dataset_publisher_name', dataset_publisher_name, name='dataset_publisher_name'),
]
6 changes: 6 additions & 0 deletions series_tiempo_ar_api/apps/metadata/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ def field_units(request):
response = query_field_terms(field='units')

return JsonResponse(response)


def dataset_publisher_name(request):
response = query_field_terms(field='dataset_publisher')

return JsonResponse(response)

0 comments on commit 5e847be

Please sign in to comment.