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 restful approach, so it's suggested to create a
unified section 'artifacts' for all cases, i.e. return
{"artifacts": [...]}

Change-Id: Ic0762f7a379754d19147a4f41a6d5a98abdc86b0
This commit is contained in:
Mike Fedosin 2017-12-12 14:38:23 +01:00 committed by Idan Narotzki
parent 8dce349bdf
commit 2924e662cb
7 changed files with 111 additions and 105 deletions

View File

@ -594,10 +594,11 @@ enabled artifact types.
.. code-block:: javascript .. code-block:: javascript
{ {
"<type_name>": [<JSON_list_with_artifacts_data>], "artifacts": [<JSON_list_with_artifacts_data>],
"first": "/artifacts/<type_name>", "first": "/artifacts/<type_name>",
"schema": "/schemas/<type_name>", "schema": "/schemas/<type_name>",
"next": "<url_to_the_next_page>" "next": "<url_to_the_next_page>",
"type_name": "<type_name>"
} }
* **Create a new artifact** * **Create a new artifact**
@ -968,7 +969,7 @@ For this example, we have an artifact type 'example_type' with fields:
.. code-block:: javascript .. code-block:: javascript
{ {
"example_type": [{ "artifacts": [{
"status": "drafted", "status": "drafted",
"name": "new_art", "name": "new_art",
"id": "art_id1", "id": "art_id1",
@ -994,7 +995,8 @@ For this example, we have an artifact type 'example_type' with fields:
"visibility": "private" "visibility": "private"
}], }],
"first": "/artifacts/example_type", "first": "/artifacts/example_type",
"schema": "/schemas/example_type" "schema": "/schemas/example_type",
"type_name": "example_type"
} }
Request: Request:
@ -1010,7 +1012,7 @@ For this example, we have an artifact type 'example_type' with fields:
.. code-block:: javascript .. code-block:: javascript
{ {
"example_type": [{ "artifacts": [{
"status": "drafted", "status": "drafted",
"name": "old_art", "name": "old_art",
"id": "art_id2", "id": "art_id2",
@ -1028,7 +1030,8 @@ For this example, we have an artifact type 'example_type' with fields:
"visibility": "private" "visibility": "private"
}], }],
"first": "/artifacts/example_type?name=eq%3Aold_art", "first": "/artifacts/example_type?name=eq%3Aold_art",
"schema": "/schemas/example_type" "schema": "/schemas/example_type",
"type_name": "example_type"
} }
4. Update artifact 4. Update artifact

View File

@ -539,7 +539,8 @@ class ResponseSerializer(api_versioning.VersionedResource,
type_name = af_list['type_name'] type_name = af_list['type_name']
body = { body = {
type_name: af_list['artifacts'], 'type_name': type_name,
'artifacts': af_list['artifacts'],
'first': '/artifacts/%s' % type_name, 'first': '/artifacts/%s' % type_name,
'schema': '/schemas/%s' % type_name, 'schema': '/schemas/%s' % type_name,
} }

View File

@ -31,26 +31,26 @@ class TestAll(base.TestArtifact):
# get all possible artifacts # get all possible artifacts
url = '/all?sort=name:asc&limit=100' url = '/all?sort=name:asc&limit=100'
res = self.get(url=url, status=200)['all'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(54, len(res)) self.assertEqual(54, len(res))
# get artifacts with latest versions # get artifacts with latest versions
url = '/all?version=latest&sort=name:asc' url = '/all?version=latest&sort=name:asc'
res = self.get(url=url, status=200)['all'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(18, len(res)) self.assertEqual(18, len(res))
for art in res: for art in res:
self.assertEqual('2.0.0', art['version']) self.assertEqual('2.0.0', art['version'])
# get images only # get images only
url = '/all?type_name=images&sort=name:asc' url = '/all?type_name=images&sort=name:asc'
res = self.get(url=url, status=200)['all'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(9, len(res)) self.assertEqual(9, len(res))
for art in res: for art in res:
self.assertEqual('images', art['type_name']) self.assertEqual('images', art['type_name'])
# get images and heat_templates # get images and heat_templates
url = '/all?type_name=in:images,heat_templates&sort=name:asc' url = '/all?type_name=in:images,heat_templates&sort=name:asc'
res = self.get(url=url, status=200)['all'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(18, len(res)) self.assertEqual(18, len(res))
for art in res: for art in res:
self.assertIn(art['type_name'], ('images', 'heat_templates')) self.assertIn(art['type_name'], ('images', 'heat_templates'))
@ -103,7 +103,7 @@ class TestAll(base.TestArtifact):
# fetch all artifacts # fetch all artifacts
url = '/all?sort=created_at:asc' url = '/all?sort=created_at:asc'
res = self.get(url=url, status=200)['all'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(2, len(res)) self.assertEqual(2, len(res))
self.assertEqual('sample_artifact', res[0]['type_name']) self.assertEqual('sample_artifact', res[0]['type_name'])

View File

@ -42,8 +42,9 @@ default_store = database
url = '/sample_artifact' url = '/sample_artifact'
response = self.get(url=url, status=200) response = self.get(url=url, status=200)
expected = {'first': '/artifacts/sample_artifact', expected = {'first': '/artifacts/sample_artifact',
'sample_artifact': [], 'artifacts': [],
'schema': '/schemas/sample_artifact'} 'schema': '/schemas/sample_artifact',
'type_name': 'sample_artifact'}
self.assertEqual(expected, response) self.assertEqual(expected, response)
# Create a test artifact # Create a test artifact

View File

@ -341,7 +341,7 @@ max_artifact_number = 10
def test_count_artifact_number(self): def test_count_artifact_number(self):
# initially there are no artifacts # initially there are no artifacts
result = self.get('/all') result = self.get('/all')
self.assertEqual([], result['all']) self.assertEqual([], result['artifacts'])
# create 3 images for user1 # create 3 images for user1
for i in range(3): for i in range(3):
@ -381,7 +381,7 @@ max_artifact_number = 10
# initially there are no artifacts # initially there are no artifacts
result = self.get('/all') result = self.get('/all')
self.assertEqual([], result['all']) self.assertEqual([], result['artifacts'])
# create 2 sample artifacts for user1 # create 2 sample artifacts for user1
art1 = self.create_artifact(data={'name': 'art1'}) art1 = self.create_artifact(data={'name': 'art1'})
@ -510,7 +510,7 @@ class TestDynamicQuotas(base.TestArtifact):
self.set_user('user1') self.set_user('user1')
# initially there are no artifacts # initially there are no artifacts
result = self.get('/all') result = self.get('/all')
self.assertEqual([], result['all']) self.assertEqual([], result['artifacts'])
# create 3 images for user1 # create 3 images for user1
for i in range(3): for i in range(3):
@ -659,7 +659,7 @@ class TestDynamicQuotas(base.TestArtifact):
self.set_user('user1') self.set_user('user1')
# initially there are no artifacts # initially there are no artifacts
result = self.get('/all') result = self.get('/all')
self.assertEqual([], result['all']) self.assertEqual([], result['artifacts'])
# create 2 sample artifacts for user1 # create 2 sample artifacts for user1
art1 = self.create_artifact(data={'name': 'art1'}) art1 = self.create_artifact(data={'name': 'art1'})

View File

@ -41,33 +41,33 @@ class TestList(base.TestArtifact):
# sort by 'next' url # sort by 'next' url
url = '/sample_artifact?limit=1&sort=int1:asc,name:desc' url = '/sample_artifact?limit=1&sort=int1:asc,name:desc'
result = self.get(url=url) result = self.get(url=url)
self.assertEqual([art_list[0]], result['sample_artifact']) self.assertEqual([art_list[0]], result['artifacts'])
marker = result['next'] marker = result['next']
result = self.get(url=marker[10:]) result = self.get(url=marker[10:])
self.assertEqual([art_list[1]], result['sample_artifact']) self.assertEqual([art_list[1]], result['artifacts'])
# sort by custom marker # sort by custom marker
url = '/sample_artifact?sort=int1:asc&marker=%s' % art_list[1]['id'] url = '/sample_artifact?sort=int1:asc&marker=%s' % art_list[1]['id']
result = self.get(url=url) result = self.get(url=url)
self.assertEqual(art_list[2:], result['sample_artifact']) self.assertEqual(art_list[2:], result['artifacts'])
url = '/sample_artifact?sort=int1:desc&marker=%s' % art_list[1]['id'] url = '/sample_artifact?sort=int1:desc&marker=%s' % art_list[1]['id']
result = self.get(url=url) result = self.get(url=url)
self.assertEqual(art_list[:1], result['sample_artifact']) self.assertEqual(art_list[:1], result['artifacts'])
url = '/sample_artifact' \ url = '/sample_artifact' \
'?sort=float1:asc,name:desc&marker=%s' % art_list[1]['id'] '?sort=float1:asc,name:desc&marker=%s' % art_list[1]['id']
result = self.get(url=url) result = self.get(url=url)
self.assertEqual([art_list[0]], result['sample_artifact']) self.assertEqual([art_list[0]], result['artifacts'])
# paginate by name in desc order with limit 2 # paginate by name in desc order with limit 2
url = '/sample_artifact?limit=2&sort=name:desc' url = '/sample_artifact?limit=2&sort=name:desc'
result = self.get(url=url) result = self.get(url=url)
self.assertEqual(art_list[4:2:-1], result['sample_artifact']) self.assertEqual(art_list[4:2:-1], result['artifacts'])
marker = result['next'] marker = result['next']
result = self.get(url=marker[10:]) result = self.get(url=marker[10:])
self.assertEqual(art_list[2:0:-1], result['sample_artifact']) self.assertEqual(art_list[2:0:-1], result['artifacts'])
marker = result['next'] marker = result['next']
result = self.get(url=marker[10:]) result = self.get(url=marker[10:])
self.assertEqual([art_list[0]], result['sample_artifact']) self.assertEqual([art_list[0]], result['artifacts'])
def test_list_base_filters(self): def test_list_base_filters(self):
# Create artifact # Create artifact
@ -108,43 +108,43 @@ class TestList(base.TestArtifact):
self.get(url=url, status=400) self.get(url=url, status=400)
url = '/sample_artifact?name=name0' url = '/sample_artifact?name=name0'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([art_list[0]], result) self.assertEqual([art_list[0]], result)
url = '/sample_artifact?tags=tag4' url = '/sample_artifact?tags=tag4'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[4:], result) self.assertEqual(art_list[4:], result)
url = '/sample_artifact?name=eq:name0' url = '/sample_artifact?name=eq:name0'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:1], result) self.assertEqual(art_list[:1], result)
url = '/sample_artifact?str1=eq:bugaga' url = '/sample_artifact?str1=eq:bugaga'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?int1=eq:2048' url = '/sample_artifact?int1=eq:2048'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[5:], result) self.assertEqual(art_list[5:], result)
url = '/sample_artifact?float1=eq:123.456' url = '/sample_artifact?float1=eq:123.456'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?name=neq:name0' url = '/sample_artifact?name=neq:name0'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[1:], result) self.assertEqual(art_list[1:], result)
url = '/sample_artifact?name=in:name,name0' url = '/sample_artifact?name=in:name,name0'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:1], result) self.assertEqual(art_list[:1], result)
url = '/sample_artifact?name=in:not_exist,name0' url = '/sample_artifact?name=in:not_exist,name0'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:1], result) self.assertEqual(art_list[:1], result)
url = '/sample_artifact?name=not_exist' url = '/sample_artifact?name=not_exist'
result = self.get(url=url)['sample_artifact'] result = self.get(url=url)['artifacts']
self.assertEqual([], result) self.assertEqual([], result)
url = '/sample_artifact?name=bla:name1' url = '/sample_artifact?name=bla:name1'
@ -157,31 +157,31 @@ class TestList(base.TestArtifact):
self.get(url=url, status=400) self.get(url=url, status=400)
url = '/sample_artifact?tags=tag4,tag5' url = '/sample_artifact?tags=tag4,tag5'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[5:], result) self.assertEqual(art_list[5:], result)
url = '/sample_artifact?tags-any=tag4' url = '/sample_artifact?tags-any=tag4'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[4:], result) self.assertEqual(art_list[4:], result)
url = '/sample_artifact?tags=tag4,tag_not_exist,tag5' url = '/sample_artifact?tags=tag4,tag_not_exist,tag5'
result = self.get(url=url)['sample_artifact'] result = self.get(url=url)['artifacts']
self.assertEqual([], result) self.assertEqual([], result)
url = '/sample_artifact?tags-any=tag4,tag_not_exist,tag5' url = '/sample_artifact?tags-any=tag4,tag_not_exist,tag5'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[4:], result) self.assertEqual(art_list[4:], result)
url = '/sample_artifact?tags=tag_not_exist,tag_not_exist_1' url = '/sample_artifact?tags=tag_not_exist,tag_not_exist_1'
result = self.get(url=url)['sample_artifact'] result = self.get(url=url)['artifacts']
self.assertEqual([], result) self.assertEqual([], result)
url = '/sample_artifact?tags' url = '/sample_artifact?tags'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list, result) self.assertEqual(art_list, result)
url = '/sample_artifact?tags=' url = '/sample_artifact?tags='
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list, result) self.assertEqual(art_list, result)
url = '/sample_artifact?tags=eq:tag0' url = '/sample_artifact?tags=eq:tag0'
@ -194,27 +194,27 @@ class TestList(base.TestArtifact):
self.get(url=url, status=400) self.get(url=url, status=400)
url = '/sample_artifact?visibility=private' url = '/sample_artifact?visibility=private'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?visibility=public' url = '/sample_artifact?visibility=public'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[5:], result) self.assertEqual(art_list[5:], result)
url = '/sample_artifact?visibility=eq:private' url = '/sample_artifact?visibility=eq:private'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?visibility=eq:public' url = '/sample_artifact?visibility=eq:public'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[5:], result) self.assertEqual(art_list[5:], result)
url = '/sample_artifact?visibility=neq:private' url = '/sample_artifact?visibility=neq:private'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[5:], result) self.assertEqual(art_list[5:], result)
url = '/sample_artifact?visibility=neq:public' url = '/sample_artifact?visibility=neq:public'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?visibility=blabla' url = '/sample_artifact?visibility=blabla'
@ -224,51 +224,51 @@ class TestList(base.TestArtifact):
self.get(url=url, status=400) self.get(url=url, status=400)
url = '/sample_artifact?name=eq:name0&name=name1&tags=tag1' url = '/sample_artifact?name=eq:name0&name=name1&tags=tag1'
result = self.get(url=url)['sample_artifact'] result = self.get(url=url)['artifacts']
self.assertEqual([], result) self.assertEqual([], result)
url = '/sample_artifact?int1=gt:2000' url = '/sample_artifact?int1=gt:2000'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[5:], result) self.assertEqual(art_list[5:], result)
url = '/sample_artifact?int1=lte:1024' url = '/sample_artifact?int1=lte:1024'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?int1=gt:1000&int1=lt:2000' url = '/sample_artifact?int1=gt:1000&int1=lt:2000'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?int1=lt:2000' url = '/sample_artifact?int1=lt:2000'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?float1=gt:200.000' url = '/sample_artifact?float1=gt:200.000'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[5:], result) self.assertEqual(art_list[5:], result)
url = '/sample_artifact?float1=gt:100.00&float1=lt:200.00' url = '/sample_artifact?float1=gt:100.00&float1=lt:200.00'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?float1=lt:200.00' url = '/sample_artifact?float1=lt:200.00'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?float1=lt:200' url = '/sample_artifact?float1=lt:200'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?float1=lte:123.456' url = '/sample_artifact?float1=lte:123.456'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?bool1=True' url = '/sample_artifact?bool1=True'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:5], result) self.assertEqual(art_list[:5], result)
url = '/sample_artifact?bool1=False' url = '/sample_artifact?bool1=False'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[5:], result) self.assertEqual(art_list[5:], result)
def test_artifact_list_dict_filters(self): def test_artifact_list_dict_filters(self):
@ -299,28 +299,28 @@ class TestList(base.TestArtifact):
# test list filters # test list filters
url = '/sample_artifact?list_of_str=aaa&sort=name' url = '/sample_artifact?list_of_str=aaa&sort=name'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:3], result) self.assertEqual(art_list[:3], result)
url = '/sample_artifact?list_of_str=ccc&sort=name' url = '/sample_artifact?list_of_str=ccc&sort=name'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([art_list[0], art_list[4]], result) self.assertEqual([art_list[0], art_list[4]], result)
url = '/sample_artifact?list_of_str=eee&sort=name' url = '/sample_artifact?list_of_str=eee&sort=name'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([], result) self.assertEqual([], result)
# test dict filters # test dict filters
url = '/sample_artifact?dict_of_str=aaa&sort=name' url = '/sample_artifact?dict_of_str=aaa&sort=name'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:3], result) self.assertEqual(art_list[:3], result)
url = '/sample_artifact?dict_of_str=ccc&sort=name' url = '/sample_artifact?dict_of_str=ccc&sort=name'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([art_list[0], art_list[4]], result) self.assertEqual([art_list[0], art_list[4]], result)
url = '/sample_artifact?dict_of_str=eee&sort=name' url = '/sample_artifact?dict_of_str=eee&sort=name'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([], result) self.assertEqual([], result)
def test_list_dict_prop_filters(self): def test_list_dict_prop_filters(self):
@ -348,23 +348,23 @@ class TestList(base.TestArtifact):
art_list.sort(key=lambda x: x['name']) art_list.sort(key=lambda x: x['name'])
url = '/sample_artifact?dict_of_str.pr1=val1' url = '/sample_artifact?dict_of_str.pr1=val1'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:2], result) self.assertEqual(art_list[:2], result)
url = '/sample_artifact?dict_of_int.1=10' url = '/sample_artifact?dict_of_int.1=10'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[3:4], result) self.assertEqual(art_list[3:4], result)
url = '/sample_artifact?dict_of_str.pr1=val999' url = '/sample_artifact?dict_of_str.pr1=val999'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([], result) self.assertEqual([], result)
url = '/sample_artifact?dict_of_str.pr1=eq:val1' url = '/sample_artifact?dict_of_str.pr1=eq:val1'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual(art_list[:2], result) self.assertEqual(art_list[:2], result)
url = '/sample_artifact?dict_of_str.' url = '/sample_artifact?dict_of_str.'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([], result) self.assertEqual([], result)
for op in ['gt', 'gte', 'lt', 'lte']: for op in ['gt', 'gte', 'lt', 'lte']:
@ -375,11 +375,11 @@ class TestList(base.TestArtifact):
self.get(url=url, status=400) self.get(url=url, status=400)
url = '/sample_artifact?dict_of_str.pr1=' url = '/sample_artifact?dict_of_str.pr1='
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([], result) self.assertEqual([], result)
url = '/sample_artifact?dict_of_str.pr1=' url = '/sample_artifact?dict_of_str.pr1='
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([], result) self.assertEqual([], result)
url = '/sample_artifact?dict_of_str' url = '/sample_artifact?dict_of_str'
@ -392,7 +392,7 @@ class TestList(base.TestArtifact):
self.get(url=url, status=400) self.get(url=url, status=400)
url = '/sample_artifact?dict_of_str.bla=val1' url = '/sample_artifact?dict_of_str.bla=val1'
result = sort_results(self.get(url=url)['sample_artifact']) result = sort_results(self.get(url=url)['artifacts'])
self.assertEqual([], result) self.assertEqual([], result)
url = '/sample_artifact?dict_of_int.1=lala' url = '/sample_artifact?dict_of_int.1=lala'
@ -415,40 +415,40 @@ class TestList(base.TestArtifact):
url = '/sample_artifact?sort=name:asc' url = '/sample_artifact?sort=name:asc'
result = self.get(url=url) result = self.get(url=url)
expected = sort_results(art_list) expected = sort_results(art_list)
self.assertEqual(expected, result['sample_artifact']) self.assertEqual(expected, result['artifacts'])
# sorted by string 'desc' # sorted by string 'desc'
url = '/sample_artifact?sort=name:desc' url = '/sample_artifact?sort=name:desc'
result = self.get(url=url) result = self.get(url=url)
expected = sort_results(art_list) expected = sort_results(art_list)
expected.reverse() expected.reverse()
self.assertEqual(expected, result['sample_artifact']) self.assertEqual(expected, result['artifacts'])
# sorted by int 'asc' # sorted by int 'asc'
url = '/sample_artifact?sort=int1:asc' url = '/sample_artifact?sort=int1:asc'
result = self.get(url=url) result = self.get(url=url)
expected = sort_results(art_list, target='int1') expected = sort_results(art_list, target='int1')
self.assertEqual(expected, result['sample_artifact']) self.assertEqual(expected, result['artifacts'])
# sorted by int 'desc' # sorted by int 'desc'
url = '/sample_artifact?sort=int1:desc' url = '/sample_artifact?sort=int1:desc'
result = self.get(url=url) result = self.get(url=url)
expected = sort_results(art_list, target='int1') expected = sort_results(art_list, target='int1')
expected.reverse() expected.reverse()
self.assertEqual(expected, result['sample_artifact']) self.assertEqual(expected, result['artifacts'])
# sorted by float 'asc' # sorted by float 'asc'
url = '/sample_artifact?sort=float1:asc' url = '/sample_artifact?sort=float1:asc'
result = self.get(url=url) result = self.get(url=url)
expected = sort_results(art_list, target='float1') expected = sort_results(art_list, target='float1')
self.assertEqual(expected, result['sample_artifact']) self.assertEqual(expected, result['artifacts'])
# sorted by float 'desc' # sorted by float 'desc'
url = '/sample_artifact?sort=float1:desc' url = '/sample_artifact?sort=float1:desc'
result = self.get(url=url) result = self.get(url=url)
expected = sort_results(art_list, target='float1') expected = sort_results(art_list, target='float1')
expected.reverse() expected.reverse()
self.assertEqual(expected, result['sample_artifact']) self.assertEqual(expected, result['artifacts'])
# sorted by unsorted 'asc' # sorted by unsorted 'asc'
url = '/sample_artifact?sort=bool1:asc' url = '/sample_artifact?sort=bool1:asc'
@ -475,7 +475,7 @@ class TestList(base.TestArtifact):
result = self.get(url=url) result = self.get(url=url)
expected = sort_results(art_list) expected = sort_results(art_list)
expected.reverse() expected.reverse()
self.assertEqual(expected, result['sample_artifact']) self.assertEqual(expected, result['artifacts'])
# sorted by list # sorted by list
url = '/sample_artifact?sort=list_of_int:asc' url = '/sample_artifact?sort=list_of_int:asc'
@ -493,7 +493,7 @@ class TestList(base.TestArtifact):
url = '/sample_artifact?sort=name:asc,int1:desc' url = '/sample_artifact?sort=name:asc,int1:desc'
result = self.get(url=url) result = self.get(url=url)
expected = sort_results(sort_results(art_list), target='int1') expected = sort_results(sort_results(art_list), target='int1')
self.assertEqual(expected, result['sample_artifact']) self.assertEqual(expected, result['artifacts'])
def test_list_versions(self): def test_list_versions(self):
# Create artifacts with versions # Create artifacts with versions
@ -530,7 +530,7 @@ class TestList(base.TestArtifact):
expected_result = sort_results(art_list, target='version') expected_result = sort_results(art_list, target='version')
url = '/sample_artifact' url = '/sample_artifact'
result = sort_results(self.get(url=url)['sample_artifact'], result = sort_results(self.get(url=url)['artifacts'],
target='version') target='version')
self.assertEqual(expected_result, result) self.assertEqual(expected_result, result)
@ -546,13 +546,13 @@ class TestList(base.TestArtifact):
status=409) status=409)
url = '/sample_artifact?name=name&version=gte:2.0.0' url = '/sample_artifact?name=name&version=gte:2.0.0'
result = sort_results(self.get(url=url)['sample_artifact'], result = sort_results(self.get(url=url)['artifacts'],
target='version') target='version')
self.assertEqual(expected_result[3:], result) self.assertEqual(expected_result[3:], result)
url = ('/sample_artifact?' url = ('/sample_artifact?'
'name=name&version=gte:1.1&version=lt:2.0.1-beta') 'name=name&version=gte:1.1&version=lt:2.0.1-beta')
result = sort_results(self.get(url=url)['sample_artifact'], result = sort_results(self.get(url=url)['artifacts'],
target='version') target='version')
self.assertEqual(expected_result[2:4], result) self.assertEqual(expected_result[2:4], result)
@ -570,12 +570,12 @@ class TestList(base.TestArtifact):
# Sorting by version 'asc' # Sorting by version 'asc'
url = '/sample_artifact?name=name&sort=version:asc' url = '/sample_artifact?name=name&sort=version:asc'
result = self.get(url=url)['sample_artifact'] result = self.get(url=url)['artifacts']
self.assertEqual(art_list, result) self.assertEqual(art_list, result)
# Sorting by version 'desc' # Sorting by version 'desc'
url = '/sample_artifact?name=name&sort=version:desc' url = '/sample_artifact?name=name&sort=version:desc'
result = self.get(url=url)['sample_artifact'] result = self.get(url=url)['artifacts']
self.assertEqual(list(reversed(art_list)), result) self.assertEqual(list(reversed(art_list)), result)
def test_list_latest_filter(self): def test_list_latest_filter(self):
@ -605,7 +605,7 @@ class TestList(base.TestArtifact):
'bool1': True}) 'bool1': True})
url = '/sample_artifact?version=latest&sort=name:asc' url = '/sample_artifact?version=latest&sort=name:asc'
res = self.get(url=url, status=200)['sample_artifact'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(2, len(res)) self.assertEqual(2, len(res))
self.assertEqual('20.0.0', res[0]['version']) self.assertEqual('20.0.0', res[0]['version'])
self.assertEqual('1000.0.1', res[1]['version']) self.assertEqual('1000.0.1', res[1]['version'])
@ -613,24 +613,24 @@ class TestList(base.TestArtifact):
self.patch('/sample_artifact/' + res[0]['id'], self.make_active) self.patch('/sample_artifact/' + res[0]['id'], self.make_active)
url = '/sample_artifact?version=latest&sort=name:asc&status=drafted' url = '/sample_artifact?version=latest&sort=name:asc&status=drafted'
res = self.get(url=url, status=200)['sample_artifact'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(2, len(res)) self.assertEqual(2, len(res))
self.assertEqual('2.0.1', res[0]['version']) self.assertEqual('2.0.1', res[0]['version'])
self.assertEqual('1000.0.1', res[1]['version']) self.assertEqual('1000.0.1', res[1]['version'])
url = '/sample_artifact?version=latest&sort=name:asc&int1=2050' url = '/sample_artifact?version=latest&sort=name:asc&int1=2050'
res = self.get(url=url, status=200)['sample_artifact'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(2, len(res)) self.assertEqual(2, len(res))
self.assertEqual('2.0.0', res[0]['version']) self.assertEqual('2.0.0', res[0]['version'])
self.assertEqual('99.0.0', res[1]['version']) self.assertEqual('99.0.0', res[1]['version'])
url = '/sample_artifact?version=latest&name=group1' url = '/sample_artifact?version=latest&name=group1'
res = self.get(url=url, status=200)['sample_artifact'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(1, len(res)) self.assertEqual(1, len(res))
self.assertEqual('20.0.0', res[0]['version']) self.assertEqual('20.0.0', res[0]['version'])
url = '/sample_artifact?version=latest&name=group2' url = '/sample_artifact?version=latest&name=group2'
res = self.get(url=url, status=200)['sample_artifact'] res = self.get(url=url, status=200)['artifacts']
self.assertEqual(1, len(res)) self.assertEqual(1, len(res))
self.assertEqual('1000.0.1', res[0]['version']) self.assertEqual('1000.0.1', res[0]['version'])
@ -648,7 +648,7 @@ class TestList(base.TestArtifact):
response_url = u'/artifacts/sample_artifact?name=' \ response_url = u'/artifacts/sample_artifact?name=' \
u'%D0%9F%D0%A0%D0%98%D0%92%D0%95%D0%A2' u'%D0%9F%D0%A0%D0%98%D0%92%D0%95%D0%A2'
result = self.get(url=url, headers=headers) result = self.get(url=url, headers=headers)
self.assertEqual(art1, result['sample_artifact'][0]) self.assertEqual(art1, result['artifacts'][0])
self.assertEqual(response_url, result['first']) self.assertEqual(response_url, result['first'])
@ -658,8 +658,9 @@ class TestBlobs(base.TestArtifact):
url = '/sample_artifact' url = '/sample_artifact'
response = self.get(url=url, status=200) response = self.get(url=url, status=200)
expected = {'first': '/artifacts/sample_artifact', expected = {'first': '/artifacts/sample_artifact',
'sample_artifact': [], 'artifacts': [],
'schema': '/schemas/sample_artifact'} 'schema': '/schemas/sample_artifact',
'type_name': 'sample_artifact'}
self.assertEqual(expected, response) self.assertEqual(expected, response)
# Create a test artifact # Create a test artifact
@ -1362,7 +1363,7 @@ class TestArtifactOps(base.TestArtifact):
self.delete(url=url, status=204) self.delete(url=url, status=204)
self.get(url=url, status=404) self.get(url=url, status=404)
self.assertEqual(0, len(self.get( self.assertEqual(0, len(self.get(
url='/sample_artifact')['sample_artifact'])) url='/sample_artifact')['artifacts']))
def test_deactivate(self): def test_deactivate(self):
# test artifact deactivate for non-active artifact # test artifact deactivate for non-active artifact

View File

@ -97,7 +97,7 @@ class TestVisibility(base.TestArtifact):
# Now admin sees 2 artifacts with the same name/version # Now admin sees 2 artifacts with the same name/version
self.set_user("admin") self.set_user("admin")
url = '/sample_artifact?name=my_art&version=1' url = '/sample_artifact?name=my_art&version=1'
self.assertEqual(2, len(self.get(url=url)['sample_artifact'])) self.assertEqual(2, len(self.get(url=url)['artifacts']))
# Admin can activate and publish artifact art3 # Admin can activate and publish artifact art3
url = '/sample_artifact/%s' % art3['id'] url = '/sample_artifact/%s' % art3['id']
@ -109,12 +109,12 @@ class TestVisibility(base.TestArtifact):
# After that user1 sees 2 artifacts with the same name/version as well # After that user1 sees 2 artifacts with the same name/version as well
self.set_user("user1") self.set_user("user1")
url = '/sample_artifact?name=my_art&version=1' url = '/sample_artifact?name=my_art&version=1'
self.assertEqual(2, len(self.get(url=url)['sample_artifact'])) self.assertEqual(2, len(self.get(url=url)['artifacts']))
# User2 still sees only his public artifact # User2 still sees only his public artifact
self.set_user("user2") self.set_user("user2")
url = '/sample_artifact?name=my_art&version=1' url = '/sample_artifact?name=my_art&version=1'
self.assertEqual(1, len(self.get(url=url)['sample_artifact'])) self.assertEqual(1, len(self.get(url=url)['artifacts']))
# Admin is able to create a private artifact with the same name/version # Admin is able to create a private artifact with the same name/version
self.set_user("admin") self.set_user("admin")
@ -122,7 +122,7 @@ class TestVisibility(base.TestArtifact):
# And he sees 3 artifacts # And he sees 3 artifacts
url = '/sample_artifact?name=my_art&version=1' url = '/sample_artifact?name=my_art&version=1'
self.assertEqual(3, len(self.get(url=url)['sample_artifact'])) self.assertEqual(3, len(self.get(url=url)['artifacts']))
# But he can't publish his artifact, because this name/version already # But he can't publish his artifact, because this name/version already
# exists in public scope # exists in public scope
@ -160,7 +160,7 @@ class TestVisibility(base.TestArtifact):
type_name='heat_templates') type_name='heat_templates')
# User 1 sees his 2 artifacts # User 1 sees his 2 artifacts
url = '/all?name=my_art&version=1' url = '/all?name=my_art&version=1'
self.assertEqual(2, len(self.get(url=url)['all'])) self.assertEqual(2, len(self.get(url=url)['artifacts']))
self.set_user('user2') self.set_user('user2')
self.create_artifact(data={'name': 'my_art', 'version': 1.0}, self.create_artifact(data={'name': 'my_art', 'version': 1.0},
@ -169,11 +169,11 @@ class TestVisibility(base.TestArtifact):
type_name='heat_templates') type_name='heat_templates')
# User 2 sees his 2 artifacts # User 2 sees his 2 artifacts
url = '/all?name=my_art&version=1' url = '/all?name=my_art&version=1'
self.assertEqual(2, len(self.get(url=url)['all'])) self.assertEqual(2, len(self.get(url=url)['artifacts']))
# Admin sees 4 artifacts from both users # Admin sees 4 artifacts from both users
self.set_user("admin") self.set_user("admin")
self.assertEqual(4, len(self.get(url=url)['all'])) self.assertEqual(4, len(self.get(url=url)['artifacts']))
# After publishing art1 and art2 user 2 can see 4 artifacts as well # After publishing art1 and art2 user 2 can see 4 artifacts as well
url = '/sample_artifact/%s' % art1['id'] url = '/sample_artifact/%s' % art1['id']
@ -190,4 +190,4 @@ class TestVisibility(base.TestArtifact):
self.set_user("user2") self.set_user("user2")
url = '/all?name=my_art&version=1' url = '/all?name=my_art&version=1'
self.assertEqual(4, len(self.get(url=url)['all'])) self.assertEqual(4, len(self.get(url=url)['artifacts']))