-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Muevo tests, y utils relacionados al admin a la lib
- Loading branch information
1 parent
9dd6c8b
commit ad8086e
Showing
6 changed files
with
257 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
series_tiempo_ar_api/libs/custom_admins/samples/single_distribution.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
{ | ||
"publisher": { | ||
"mbox": "[email protected]", | ||
"name": "Subsecretaría de Programación Macroeconómica." | ||
}, | ||
"license": "Open Database License (ODbL) v1.0", | ||
"description": "Catálogo de datos abiertos de la Subsecretaría de Programación Macroeconómica.", | ||
"language": [ | ||
"SPA" | ||
], | ||
"superThemeTaxonomy": "http://datos.gob.ar/superThemeTaxonomy.json", | ||
"issued": "2017-09-28", | ||
"rights": "2017-09-28", | ||
"modified": "2017-09-28", | ||
"dataset": [ | ||
{ | ||
"publisher": { | ||
"mbox": "[email protected]", | ||
"name": "Subsecretaría de Programación Macroeconómica." | ||
}, | ||
"landingPage": "http://www.minhacienda.gob.ar/secretarias/politica-economica/programacion-macroeconomica/", | ||
"keyword": [ | ||
"Información Económica Histórica", | ||
"Actividad" | ||
], | ||
"superTheme": [ | ||
"ECON" | ||
], | ||
"title": "Datos históricos de la industria siderúrgica", | ||
"language": [ | ||
"SPA" | ||
], | ||
"issued": "2017-12-12", | ||
"temporal": "1960-01-01/2016-12-01", | ||
"source": "Cámara Argentina del Acero y Boletín Informativo de Techint", | ||
"theme": [ | ||
"actividad" | ||
], | ||
"accrualPeriodicity": "R/P1M", | ||
"spatial": "ARG", | ||
"identifier": "359", | ||
"license": "Creative Commons Attribution 4.0", | ||
"contactPoint": { | ||
"fn": "Subsecretaría de Programación Macroeconómica." | ||
}, | ||
"accessLevel": "ABIERTO", | ||
"distribution": [ | ||
{ | ||
"accessURL": "https://www.minhacienda.gob.ar/secretarias/politica-economica/programacion-macroeconomica/", | ||
"scrapingFileSheet": "1.23 Historicos Siderurgia", | ||
"description": "Datos históricos del volumen de producción de la industria siderúrgica. Datos Anuales", | ||
"format": "CSV", | ||
"dataset_identifier": "359", | ||
"issued": "2017-12-12", | ||
"title": "Datos históricos de la industria siderúrgica. Datos Anuales", | ||
"fileName": "datos-historicos-de-la-industria-siderurgica-datos-anuales.csv", | ||
"downloadURL": "http://infra.datos.gob.ar/catalog/sspm/dataset/359/distribution/359.1/download/datos-historicos-de-la-industria-siderurgica-datos-anuales.csv", | ||
"field": [ | ||
{ | ||
"distribution_identifier": "359.1", | ||
"title": "indice_tiempo", | ||
"dataset_identifier": "359", | ||
"scrapingIdentifierCell": "A9", | ||
"specialTypeDetail": "R/P1Y", | ||
"specialType": "time_index", | ||
"type": "date", | ||
"id": "359.1_INDICE_TIEMPO__13", | ||
"scrapingDataStartCell": "A10" | ||
}, | ||
{ | ||
"distribution_identifier": "359.1", | ||
"description": "Volúmen de produción de hierro primario arrabio", | ||
"title": "hierro_primario_arrabio", | ||
"dataset_identifier": "359", | ||
"scrapingIdentifierCell": "B9", | ||
"units": "Unidades", | ||
"type": "number", | ||
"id": "359.1_HIERRO_PRIBIO__23", | ||
"scrapingDataStartCell": "B10" | ||
}, | ||
{ | ||
"distribution_identifier": "359.1", | ||
"description": "Volúmen de produción de hierro primario hierro esponja", | ||
"title": "hierro_primario_hierro_esponja", | ||
"dataset_identifier": "359", | ||
"scrapingIdentifierCell": "C9", | ||
"units": "Unidades", | ||
"type": "number", | ||
"id": "359.1_HIERRO_PRINJA__30", | ||
"scrapingDataStartCell": "C10" | ||
}, | ||
{ | ||
"distribution_identifier": "359.1", | ||
"description": "Volúmen de produción de hierro primario total", | ||
"title": "hierro_primario_total", | ||
"dataset_identifier": "359", | ||
"scrapingIdentifierCell": "D9", | ||
"units": "Unidades", | ||
"type": "number", | ||
"id": "359.1_HIERRO_PRITAL__21", | ||
"scrapingDataStartCell": "D10" | ||
}, | ||
{ | ||
"distribution_identifier": "359.1", | ||
"description": "Volúmen de produción de acero crudo", | ||
"title": "acero_crudo", | ||
"dataset_identifier": "359", | ||
"scrapingIdentifierCell": "F9", | ||
"units": "Unidades", | ||
"type": "number", | ||
"id": "359.1_ACERO_CRUDUDO__11", | ||
"scrapingDataStartCell": "F10" | ||
}, | ||
{ | ||
"distribution_identifier": "359.1", | ||
"description": "Volúmen de produción de laminados no planos en caliente", | ||
"title": "laminados_no_planos_en_caliente", | ||
"dataset_identifier": "359", | ||
"scrapingIdentifierCell": "H9", | ||
"units": "Unidades", | ||
"type": "number", | ||
"id": "359.1_LAMINADOS_NTE__31", | ||
"scrapingDataStartCell": "H10" | ||
}, | ||
{ | ||
"distribution_identifier": "359.1", | ||
"description": "Volúmen de produción de laminados planos en caliente", | ||
"title": "laminados_planos_en_caliente", | ||
"dataset_identifier": "359", | ||
"scrapingIdentifierCell": "I9", | ||
"units": "Unidades", | ||
"type": "number", | ||
"id": "359.1_LAMINADOS_NTE__28", | ||
"scrapingDataStartCell": "I10" | ||
}, | ||
{ | ||
"distribution_identifier": "359.1", | ||
"description": "Volúmen de produción de laminados planos en frio", | ||
"title": "laminados_planos_en_frio", | ||
"dataset_identifier": "359", | ||
"scrapingIdentifierCell": "J9", | ||
"units": "Unidades", | ||
"type": "number", | ||
"id": "359.1_LAMINADOS_RIO__24", | ||
"scrapingDataStartCell": "J10" | ||
} | ||
], | ||
"identifier": "359.1", | ||
"scrapingFileURL": "https://www.economia.gob.ar/download/infoeco/actividad_ied.xlsx" | ||
} | ||
] | ||
} | ||
], | ||
"identifier": "sspm", | ||
"spatial": "ARG", | ||
"title": "Datos Programación Macroeconómica", | ||
"themeTaxonomy": [ | ||
{ | ||
"label": "Actividad", | ||
"id": "actividad", | ||
"description": "Series de actividad: cuentas nacionales, consumo, producción, etc." | ||
}, | ||
{ | ||
"label": "Empleo e Ingresos", | ||
"id": "empleo", | ||
"description": "Series de empleo e ingresos: mercado laboral, salarios, etc." | ||
}, | ||
{ | ||
"label": "Sector Externo", | ||
"id": "externo", | ||
"description": "Series externas: Balance de Pagos, Intercambio Comercial, etc." | ||
}, | ||
{ | ||
"label": "Dinero y Bancos", | ||
"id": "moneda", | ||
"description": "Series monetarias y bancarias" | ||
}, | ||
{ | ||
"label": "Precios", | ||
"id": "precios", | ||
"description": "Series de precios" | ||
}, | ||
{ | ||
"label": "Economía Internacional", | ||
"id": "internacional", | ||
"description": "Series económicas mundiales" | ||
}, | ||
{ | ||
"label": "Finanzas Públicas", | ||
"id": "fiscal", | ||
"description": "Series de recaudación, ingresos, gastos, etc." | ||
}, | ||
{ | ||
"label": "Mercados Financieros", | ||
"id": "finanzas", | ||
"description": "Series financieras y de mercado de capitales" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
|
||
import mock | ||
from django.contrib.admin import ACTION_CHECKBOX_NAME | ||
from django.contrib.auth.models import User | ||
from django.core import urlresolvers | ||
from django.test import TestCase | ||
from django_datajsonar.models import Node, ReadDataJsonTask, Field, Distribution | ||
|
||
from django_datajsonar.indexing.catalog_reader import index_catalog | ||
|
||
SAMPLES_DIR = os.path.join(os.path.dirname(__file__), 'samples') | ||
|
||
|
||
class DeleteMetadataTests(TestCase): | ||
distribution_change = urlresolvers.reverse('admin:django_datajsonar_distribution_changelist') | ||
field_change = urlresolvers.reverse('admin:django_datajsonar_field_changelist') | ||
|
||
def setUp(self): | ||
self.catalog_id = "one" | ||
node = Node.objects.create(catalog_url=os.path.join(SAMPLES_DIR, 'single_distribution.json'), | ||
catalog_id=self.catalog_id, | ||
indexable=True) | ||
index_catalog(node, ReadDataJsonTask.objects.create(), whitelist=True) | ||
user = User.objects.create(username='a', password='b', is_staff=True, is_superuser=True) | ||
self.client.force_login(user) | ||
|
||
def test_delete_fields(self): | ||
with mock.patch('series_tiempo_ar_api.libs.custom_admins.admin.delete_metadata') as fake_delete: | ||
fields = Field.objects.all() | ||
self.client.post(self.field_change, {'action': 'delete_model', | ||
ACTION_CHECKBOX_NAME: [str(f.pk) for f in fields]}, | ||
follow=True) | ||
|
||
self.assertEqual(set(fake_delete.call_args[0][0]), set(fields)) | ||
|
||
def test_delete_distribution(self): | ||
with mock.patch('series_tiempo_ar_api.libs.custom_admins.admin.delete_metadata') as fake_delete: | ||
distribution: Distribution = Distribution.objects.filter(dataset__catalog__identifier=self.catalog_id).first() | ||
fields = set(distribution.field_set.all()) | ||
self.client.post(self.distribution_change, | ||
{'action': 'delete_model', | ||
ACTION_CHECKBOX_NAME: [str(distribution.pk)]}, | ||
follow=True) | ||
self.assertEqual(set(fake_delete.call_args[0][0]), set(fields)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from elasticsearch_dsl import Search, Q | ||
from series_tiempo_ar_api.apps.metadata import constants | ||
from series_tiempo_ar_api.libs.indexing.elastic import ElasticInstance | ||
|
||
|
||
def delete_metadata(fields: list): | ||
es_instance = ElasticInstance.get() | ||
|
||
search = Search(using=es_instance, index=constants.METADATA_ALIAS) | ||
return search.filter('terms', id=[field.identifier for field in fields]).delete() |