From e5969e52e033404488da585f9d73de0f10161dcf Mon Sep 17 00:00:00 2001 From: Lucas Lavandeira <19612265+lucaslavandeira@users.noreply.github.com> Date: Tue, 20 Feb 2018 14:16:09 -0300 Subject: [PATCH 1/3] Indexo dataset publisher refs:#175 refs:#175 --- series_tiempo_ar_api/apps/metadata/indexer/doc_types.py | 1 + series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py | 1 + 2 files changed, 2 insertions(+) diff --git a/series_tiempo_ar_api/apps/metadata/indexer/doc_types.py b/series_tiempo_ar_api/apps/metadata/indexer/doc_types.py index 2eb28fa2..6f7611ce 100644 --- a/series_tiempo_ar_api/apps/metadata/indexer/doc_types.py +++ b/series_tiempo_ar_api/apps/metadata/indexer/doc_types.py @@ -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() diff --git a/series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py b/series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py index 98a0cc65..ce636977 100644 --- a/series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py +++ b/series_tiempo_ar_api/apps/metadata/indexer/metadata_indexer.py @@ -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)) From 610e396ba6e9c16a36a8f44f3a7c6d792d4f5879 Mon Sep 17 00:00:00 2001 From: Lucas Lavandeira <19612265+lucaslavandeira@users.noreply.github.com> Date: Tue, 20 Feb 2018 14:18:49 -0300 Subject: [PATCH 2/3] Agrego view para mostrar dataset publisher names refs:#175 --- series_tiempo_ar_api/apps/metadata/urls.py | 3 ++- series_tiempo_ar_api/apps/metadata/views.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/series_tiempo_ar_api/apps/metadata/urls.py b/series_tiempo_ar_api/apps/metadata/urls.py index 6d07e8df..3e1711e3 100644 --- a/series_tiempo_ar_api/apps/metadata/urls.py +++ b/series_tiempo_ar_api/apps/metadata/urls.py @@ -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'), ] diff --git a/series_tiempo_ar_api/apps/metadata/views.py b/series_tiempo_ar_api/apps/metadata/views.py index 1672aece..4178a9d8 100644 --- a/series_tiempo_ar_api/apps/metadata/views.py +++ b/series_tiempo_ar_api/apps/metadata/views.py @@ -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) From 446a96bd94e9e125266c407d2109e940d74244ad Mon Sep 17 00:00:00 2001 From: Lucas Lavandeira <19612265+lucaslavandeira@users.noreply.github.com> Date: Tue, 20 Feb 2018 14:25:41 -0300 Subject: [PATCH 3/3] Agrego caso de prueba para el endpoint refs:#175 --- .../apps/metadata/tests/view_tests.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/series_tiempo_ar_api/apps/metadata/tests/view_tests.py b/series_tiempo_ar_api/apps/metadata/tests/view_tests.py index 8e7ea3a4..ef181d9a 100644 --- a/series_tiempo_ar_api/apps/metadata/tests/view_tests.py +++ b/series_tiempo_ar_api/apps/metadata/tests/view_tests.py @@ -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)