#949 Added the ability to search mbs builds by the whole NSVC string.
Merged 10 months ago by ralph. Opened 10 months ago by mcurlej.
mcurlej/fm-orchestrator enable_nsvc_search  into  master

@@ -196,6 +196,13 @@ 

              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:

@@ -373,6 +373,25 @@ 

          }

          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)

Hi All,

added the ability to search mbs with an NSVC string. Right now you have to split the string before searching. + test

@ralph @mprahl @jkaluza Can you take a look?

Signed-off-by: Martin Curlej mcurlej@redhat.com

You could use:

for key, part in zip(query_keys, nsvc_parts):
    search_query[key] = part

This will also fix the traceback when you use n:s:v:c:foo as input :).

Fun fact (irrelevant here)... you can unzip with zip(*something).

>>> a = (1, 2, 3)
>>> b = ('a', 'b', 'c')
>>> [a, b] == zip(*zip(a, b))
True

rebased onto e2e804b

10 months ago

@ralph @jkaluza @mprahl
Thank you guys zip is magical... :) never used it before.

Pull-Request has been merged by ralph

10 months ago