Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/datosgobar/pydatajson
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/datosgobar/pydatajson:
  Arreglo indicadores de red nulos cuando un catálogo es inválido
  • Loading branch information
abenassi committed Aug 2, 2017
2 parents d960a3b + 4097b4c commit 1eff053
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pydatajson/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,16 @@ def add_dicts(one_dict, other_dict):
"""
result = other_dict.copy()
for k, v in one_dict.items():
if v is None:
v = 0

if isinstance(v, dict):
result[k] = add_dicts(v, other_dict.get(k, {}))
else:
result[k] = result.get(k, 0) + v
other_value = result.get(k, 0)
if other_value is None:
other_value = 0
result[k] = other_value + v

return result

Expand Down
11 changes: 11 additions & 0 deletions tests/samples/invalid_catalog_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"publisher": {
"mbox": "",
"name": ""
},
"description": "Describí el portal. Explicá de qué se trata tu catálogo de datos. Por favor, hacelo en no más de tres líneas.",
"superThemeTaxonomy": "http://datos.gob.ar/superThemeTaxonomy.json",
"title": "Ministerio de Desarrollos Social",
"dataset": [],
"themeTaxonomy": []
}
9 changes: 9 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,15 @@ def test_dataset_is_updated(self):
def test_parse_date_string(self):
self.assertEqual(self.dj._parse_date_string(""), None)

def test_date_network_indicators_empty_catalog(self):
catalog = os.path.join(self.SAMPLES_DIR, "invalid_catalog_empty.json")
indics, network_indics = self.dj.generate_catalogs_indicators(
[catalog,
catalog]
)

for k, v in network_indics.items():
self.assertTrue(v is not None)

if __name__ == '__main__':
nose.run(defaultTest=__name__)

0 comments on commit 1eff053

Please sign in to comment.