Look the list of artifacts in 'artifacts' section

Now when user requests a list of artifacts glare returns
a json dict that has a section called after the type name,
which contains the list of the artifacts.
Example:
GET /artifacts/my_artifacts

{"my_artifacts": [...]}

It's not really a resful approach, so it's suggested to create a
unified section 'artifacts' for all cases, i.e. return
{"artifacts": [...]}

Change-Id: I2afb80fc7285bb8111a45a88d03f8ea21052f871
This commit is contained in:
Mike Fedosin 2017-12-12 13:48:20 +01:00
parent c11f038e6e
commit 8348e98224
2 changed files with 24 additions and 2 deletions

View File

@ -70,7 +70,7 @@ class TestController(testtools.TestCase):
'/artifacts/checked_name/test-id')
self.c._check_type_name.assert_called_once_with('test_name')
def test_list(self):
def test_list_legacy(self):
self.mock_http_client.get.side_effect = [
(None, {'checked_name': [10, 11, 12], "next": "next1"}),
(None, {'checked_name': [13, 14, 15], "next": "next2"}),
@ -88,6 +88,24 @@ class TestController(testtools.TestCase):
]
self.assertEqual(expected_calls, self.mock_http_client.mock_calls)
def test_list(self):
self.mock_http_client.get.side_effect = [
(None, {'artifacts': [10, 11, 12], "next": "next1"}),
(None, {'artifacts': [13, 14, 15], "next": "next2"}),
(None, {'artifacts': [16, 17, 18], "next": "next3"}),
(None, {'artifacts': [19, 20, 21]}),
]
data = list(self.c.list(type_name='test-type', limit=10, page_size=3))
expected = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
self.assertEqual(expected, data)
expected_calls = [
mock.call.get('/artifacts/checked_name?&limit=3'),
mock.call.get('next1'),
mock.call.get('next2'),
mock.call.get('next3'),
]
self.assertEqual(expected_calls, self.mock_http_client.mock_calls)
def test_activate(self):
self.c.update = mock.Mock()
self.assertEqual(self.c.update.return_value,

View File

@ -161,7 +161,11 @@ class Controller(object):
"limit=%s" % limit)
resp, body = self.http_client.get(next_url)
for artifact in body[type_name]:
# For backward compatibility we also look for the list of
# artifacts under the type_name section.
# In current versions it should be located in 'artifacts'.
for artifact in body.get('artifacts', body.get(type_name)):
yield artifact
if limit: