From 9710e487075339478fe7cee4cda2989e9dae4bf7 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jun 08 2018 18:02:40 +0000 Subject: De-list the type when iterating over announcement subjects. When trying to run this, I found that the announcement subjects always yielded nothing because `type` is always a list of one element like `['koji_build']`. --- diff --git a/functional-tests/consumers/test_resultsdb.py b/functional-tests/consumers/test_resultsdb.py index 12207c2..1396942 100644 --- a/functional-tests/consumers/test_resultsdb.py +++ b/functional-tests/consumers/test_resultsdb.py @@ -29,8 +29,8 @@ def test_consume_new_result( 'name': 'dist.rpmdeplint', }, 'data': { - 'item': nvr, - 'type': 'koji_build', + 'item': [nvr], + 'type': ['koji_build'], } } } @@ -262,8 +262,8 @@ def test_no_message_for_unchanged_decision( 'name': 'dist.rpmdeplint', }, 'data': { - 'item': nvr, - 'type': 'koji_build', + 'item': [nvr], + 'type': ['koji_build'], } } } @@ -301,8 +301,8 @@ def test_invalidate_new_result_with_mocked_cache( 'name': 'dist.rpmdeplint', }, 'data': { - 'item': nvr, - 'type': 'koji_build', + 'item': [nvr], + 'type': ['koji_build'], } } } @@ -372,8 +372,8 @@ def test_invalidate_new_result_with_real_cache( 'name': 'dist.rpmdeplint' }, 'data': { - 'item': nvr, - 'type': 'koji_build', + 'item': [nvr], + 'type': ['koji_build'], } } } @@ -423,8 +423,8 @@ def test_invalidate_new_result_with_no_preexisting_cache( 'name': 'dist.rpmdeplint' }, 'data': { - 'item': nvr, - 'type': 'koji_build', + 'item': [nvr], + 'type': ['koji_build'], } } } @@ -467,7 +467,7 @@ def test_consume_compose_id_result( 'name': 'compose.install_no_user', }, 'data': { - 'productmd.compose.id': compose_id, + 'productmd.compose.id': [compose_id], }, } } diff --git a/greenwave/consumers/resultsdb.py b/greenwave/consumers/resultsdb.py index fb1a3b2..149e2de 100644 --- a/greenwave/consumers/resultsdb.py +++ b/greenwave/consumers/resultsdb.py @@ -76,18 +76,19 @@ class ResultsDBHandler(fedmsg.consumers.FedmsgConsumer): def _decode(value): """ Decode either a string or a list of strings. """ - if len(value) == 1: + if value and len(value) == 1: value = value[0] return value - if data.get('type') == 'bodhi_update' and 'item' in data: + _type = _decode(data.get('type')) + if _type == 'bodhi_update' and 'item' in data: yield ('bodhi_update', _decode(data['item'])) if 'productmd.compose.id' in data: yield ('compose', _decode(data['productmd.compose.id'])) - if (data.get('type') == 'koji_build' and 'item' in data or - data.get('type') == 'brew-build' and 'item' in data or + if (_type == 'koji_build' and 'item' in data or + _type == 'brew-build' and 'item' in data or 'original_spec_nvr' in data): - if data.get('type') in ['koji_build', 'brew-build']: + if _type in ['koji_build', 'brew-build']: nvr = _decode(data['item']) else: nvr = _decode(data['original_spec_nvr'])