From 6817b39911084054d16bd44aafa73e92b7ff5bf1 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Tue, 5 Sep 2017 16:57:13 +0100 Subject: [PATCH] Unskip all revision tag functional tests. Unskip all revision tag functional tests added by commit If0fc9cec1f2382ae5dcf7ff7ebb60d0779df55dd Change-Id: If95aa4e208fb80cb0f2f66ad4930099b51e1d757 --- deckhand/control/views/revision.py | 30 +++++++++++++++---- .../revision-crud-success-single-bucket.yaml | 8 ++--- .../gabbits/revision-tag-success.yaml | 16 +++------- .../tests/unit/views/test_revision_views.py | 13 ++------ 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/deckhand/control/views/revision.py b/deckhand/control/views/revision.py index cf2b3080..8406e7b0 100644 --- a/deckhand/control/views/revision.py +++ b/deckhand/control/views/revision.py @@ -28,11 +28,20 @@ class ViewBuilder(common.ViewBuilder): } for revision in revisions: - result = {} + body = {'tags': set(), 'buckets': set()} + rev_documents = revision.pop('documents') + for attr in ('id', 'created_at'): - result[common.to_camel_case(attr)] = revision[attr] - result['count'] = len(revision.pop('documents')) - resp_body['results'].append(result) + body[common.to_camel_case(attr)] = revision[attr] + + body['tags'].update([t['tag'] for t in revision['tags']]) + body['buckets'].update( + [d['bucket_id'] for d in rev_documents]) + + body['tags'] = sorted(body['tags']) + body['buckets'] = sorted(body['buckets']) + + resp_body['results'].append(body) return resp_body @@ -42,6 +51,10 @@ class ViewBuilder(common.ViewBuilder): Each revision's documents should only be validation policies. """ validation_policies = [] + # TODO(fmontei): For the time being we're only returning the tag name, + # but eventually we'll return data associated with the tag, which is + # why this is a dictionary, not a list. + tags = {} success_status = 'success' for vp in [d for d in revision['documents'] @@ -60,10 +73,17 @@ class ViewBuilder(common.ViewBuilder): if validation_policy['status'] != 'success': success_status = 'failed' + for tag in revision['tags']: + tags.setdefault(tag['tag'], {'name': tag['tag']}) + + buckets = sorted(set([d['bucket_id'] for d in revision['documents']])) + return { 'id': revision.get('id'), 'createdAt': revision.get('created_at'), 'url': self._gen_url(revision), 'validationPolicies': validation_policies, - 'status': success_status + 'status': success_status, + 'tags': tags, + 'buckets': buckets } diff --git a/deckhand/tests/functional/gabbits/revision-crud-success-single-bucket.yaml b/deckhand/tests/functional/gabbits/revision-crud-success-single-bucket.yaml index 82252c6d..6491b13e 100644 --- a/deckhand/tests/functional/gabbits/revision-crud-success-single-bucket.yaml +++ b/deckhand/tests/functional/gabbits/revision-crud-success-single-bucket.yaml @@ -39,23 +39,19 @@ tests: response_multidoc_jsonpaths: $.[0].id: $HISTORY['initialize'].$RESPONSE['$.[0].status.revision'] $.[0].buckets: [mop] - $.[0].tags: [] - skip: Not implemented. + $.[0].tags: {} # Validates whether revision was created. - # Required parameters: - # path: revision_id. # Asserts that status code and response headers are correct. - name: verify_revision_list desc: Verify that revision was created for document above - GET: /api/v1.0/revisions/$RESPONSE['$.[0].status.revision'] + GET: /api/v1.0/revisions status: 200 response_multidoc_jsonpaths: $.[0].count: 1 $.[0].results[0].id: $HISTORY['initialize'].$RESPONSE['$.[0].status.revision'] $.[0].results[0].buckets: [mop] $.[0].results[0].tags: [] - skip: Not implemented. # Validates whether revision deletion works. # Required parameters: diff --git a/deckhand/tests/functional/gabbits/revision-tag-success.yaml b/deckhand/tests/functional/gabbits/revision-tag-success.yaml index 18d3554b..2ca29c69 100644 --- a/deckhand/tests/functional/gabbits/revision-tag-success.yaml +++ b/deckhand/tests/functional/gabbits/revision-tag-success.yaml @@ -66,15 +66,13 @@ tests: status: 200 response_multidoc_jsonpaths: $.[0].tags.foo.name: foo - skip: Not implemented. - name: verify_revision_list_foo desc: Verify showing created tag on revision list GET: /api/v1.0/revisions status: 200 response_multidoc_jsonpaths: - $.[0].tags [foo] - skip: Not implemented. + $.[0].results[0].tags: [foo] - name: create_tag_with_data desc: Create a tag with data for the revision @@ -106,15 +104,13 @@ tests: response_multidoc_jsonpaths: $.[0].tags.bar.name: bar $.[0].tags.foo.name: foo - skip: Not implemented. - name: verify_revision_list_bar desc: Verify showing created tag on revision list GET: /api/v1.0/revisions status: 200 response_multidoc_jsonpaths: - $.[0].tags [bar, foo] - skip: Not implemented. + $.[0].results[0].tags: [bar, foo] - name: delete_tag desc: Verify deleting tag works @@ -137,15 +133,13 @@ tests: status: 200 response_multidoc_jsonpaths: $.[0].tags.bar.name: bar - skip: Not implemented. - name: verify_revision_list_deleted_foo desc: Verify not showing deleted tag on revision list GET: /api/v1.0/revisions status: 200 response_multidoc_jsonpaths: - $.[0].tags [bar] - skip: Not implemented. + $.[0].results[0].tags: [bar] - name: delete_all_tags desc: Verify deleting tag works @@ -158,15 +152,13 @@ tests: status: 200 response_multidoc_jsonpaths: $.[0].tags: {} - skip: Not implemented. - name: verify_revision_list_deleted_all desc: Verify empty tags on revision list GET: /api/v1.0/revisions status: 200 response_multidoc_jsonpaths: - $.[0].tags [] - skip: Not implemented. + $.[0].results[0].tags: [] - name: verify_tag_delete_all desc: Verify all tags have been deleted diff --git a/deckhand/tests/unit/views/test_revision_views.py b/deckhand/tests/unit/views/test_revision_views.py index 492c7db4..3d021831 100644 --- a/deckhand/tests/unit/views/test_revision_views.py +++ b/deckhand/tests/unit/views/test_revision_views.py @@ -34,15 +34,11 @@ class TestRevisionViews(base.TestDbBase): revisions = self.list_revisions() revisions_view = self.view_builder.list(revisions) - expected_attrs = ('results', 'count') - for attr in expected_attrs: - self.assertIn(attr, revisions_view) + self.assertIn('results', revisions_view) # Validate that only 1 revision was returned. self.assertEqual(1, revisions_view['count']) # Validate that the first revision has 4 documents. self.assertIn('id', revisions_view['results'][0]) - self.assertIn('count', revisions_view['results'][0]) - self.assertEqual(4, revisions_view['results'][0]['count']) def test_list_multiple_revisions(self): docs_count = [] @@ -57,18 +53,13 @@ class TestRevisionViews(base.TestDbBase): revisions = self.list_revisions() revisions_view = self.view_builder.list(revisions) - expected_attrs = ('results', 'count') - for attr in expected_attrs: - self.assertIn(attr, revisions_view) + self.assertIn('results', revisions_view) # Validate that only 1 revision was returned. self.assertEqual(3, revisions_view['count']) # Validate that each revision has correct number of documents. for idx, doc_count in enumerate(docs_count): - self.assertIn('count', revisions_view['results'][idx]) self.assertIn('id', revisions_view['results'][idx]) - self.assertEqual(doc_count, revisions_view['results'][idx][ - 'count']) def test_show_revision(self): payload = [base.DocumentFixture.get_minimal_fixture()