From e2e804b1d6bcc9b0f661fa4b5ab712769b22e0f6 Mon Sep 17 00:00:00 2001 From: Martin Curlej Date: Jun 13 2018 07:30:52 +0000 Subject: Added the ability to search mbs builds by the whole NSVC string. Signed-off-by: Martin Curlej Found about the magical properties of zip. Signed-off-by: Martin Curlej --- diff --git a/module_build_service/utils/views.py b/module_build_service/utils/views.py index 00b46ae..abd3630 100644 --- a/module_build_service/utils/views.py +++ b/module_build_service/utils/views.py @@ -196,6 +196,13 @@ def filter_module_builds(flask_request): else: raise ValidationError('An invalid state was supplied') + nsvc = flask_request.args.get('nsvc', None) + if nsvc: + nsvc_parts = nsvc.split(":") + query_keys = ["name", "stream", "version", "context"] + for key, part in zip(query_keys, nsvc_parts): + search_query[key] = part + query = models.ModuleBuild.query if search_query: diff --git a/tests/test_views/test_views.py b/tests/test_views/test_views.py index 2c9adc7..62d03f7 100644 --- a/tests/test_views/test_views.py +++ b/tests/test_views/test_views.py @@ -373,6 +373,25 @@ class TestViews: } assert actual == expected + def test_query_builds_with_nsvc(self): + nsvcs = ["testmodule:4.3.43:7:00000000", + "testmodule:4.3.43:7", + "testmodule:4.3.43", + "testmodule"] + + results = [] + for nsvc in nsvcs: + rv = self.client.get('/module-build-service/1/module-builds/?nsvc=%s&per_page=2' % nsvc) + results.append(json.loads(rv.data)['items']) + + nsvc_keys = ["name", "stream", "version", "context"] + + for items, nsvc in zip(results, nsvcs): + nsvc_parts = nsvc.split(":") + for item in items: + for key, part in zip(nsvc_keys, nsvc_parts): + assert item[key] == part + def test_query_component_build(self): rv = self.client.get('/module-build-service/1/component-builds/1') data = json.loads(rv.data)