From 7880fa5a58e2442bf6bcd66c0d604350ecf80213 Mon Sep 17 00:00:00 2001 From: amartynov Date: Mon, 7 Jul 2014 12:51:18 +0400 Subject: [PATCH] images list test, image create, image delete --- .../api_v2/10_create/00_filter.feature | 20 + .../api_v2/10_create/10_image.feature | 477 ++++++++++++++++++ .../api_v2/20_delete/90_image.feature | 23 + devops-service/features/api_v2/image.feature | 48 -- devops-service/routes/v2.0/image.rb | 2 +- 5 files changed, 521 insertions(+), 49 deletions(-) create mode 100644 devops-service/features/api_v2/10_create/10_image.feature create mode 100644 devops-service/features/api_v2/20_delete/90_image.feature delete mode 100644 devops-service/features/api_v2/image.feature diff --git a/devops-service/features/api_v2/10_create/00_filter.feature b/devops-service/features/api_v2/10_create/00_filter.feature index fa109f8..f65bbc2 100644 --- a/devops-service/features/api_v2/10_create/00_filter.feature +++ b/devops-service/features/api_v2/10_create/00_filter.feature @@ -86,6 +86,16 @@ Feature: Filters And the JSON response should be an object And the object should contains key 'images' with array and array should contains strings '08093b30-8393-42c3-8fb3-c4df56deb967' + @openstack + Scenario: Add openstack image filter with invalid JSON + When I send PUT '/v2.0/filter/openstack/image' query with JSON body + """ + [ + "08093b30-8393-42c3-8fb3-c4df56deb967", + ] + """ + Then response should be '400' + @ec2 Scenario: Add ec2 image filter with user without privileges When I send PUT '/v2.0/filter/ec2/image' query with user without privileges @@ -171,3 +181,13 @@ Feature: Filters And the JSON response should be an object And the object should contains key 'images' with array and array should contains strings 'ami-63071b0a' + @ec2 + Scenario: Add ec2 image filter with invalid JSON + When I send PUT '/v2.0/filter/ec2/image' query with JSON body + """ + [ + "ami-63071b0a", + ] + """ + Then response should be '400' + diff --git a/devops-service/features/api_v2/10_create/10_image.feature b/devops-service/features/api_v2/10_create/10_image.feature new file mode 100644 index 0000000..a50893f --- /dev/null +++ b/devops-service/features/api_v2/10_create/10_image.feature @@ -0,0 +1,477 @@ +@image +Feature: Manage images + + Scenario: Get list of all images + When I send GET '/v2.0/images' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an array + And response array should contains elements like: + """ + [ + { + "provider": "foo_provider", + "name": "foo_name", + "remote_user": "foo_user", + "bootstrap_template": "foo_template", + "id": "foo_id" + } + ] + """ + + Scenario: Get list of all images without header 'Accept' + When I send GET '/v2.0/images' query without headers 'Accept' + Then response should be '406' + + @openstack + Scenario: Get list of openstack images + When I send GET '/v2.0/images?provider=openstack' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an array + And response array should contains elements like: + """ + [ + { + "provider": "foo_provider", + "name": "foo_name", + "remote_user": "foo_user", + "bootstrap_template": "foo_template", + "id": "foo_id" + } + ] + """ + + @openstack + Scenario: Get list of openstack images (provider) + When I send GET '/v2.0/images/provider/openstack' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an array + + @openstack + Scenario: Get list of openstack images (provider) without header 'Accept' + When I send GET '/v2.0/images/provider/openstack' query without headers 'Accept' + Then response should be '406' + + @openstack + Scenario: Get images list of openstack without privileges + When I send GET '/v2.0/images/provider/openstack' query with user without privileges + Then response should be '401' + + @openstack + Scenario: Get openstack image without privileges + When I send GET '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with user without privileges + Then response should be '401' + + @ec2 + Scenario: Get list of ec2 images + When I send GET '/v2.0/images?provider=ec2' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an array + And response array should contains elements like: + """ + [ + { + "provider": "foo_provider", + "name": "foo_name", + "remote_user": "foo_user", + "bootstrap_template": "foo_template", + "id": "foo_id" + } + ] + """ + + @ec2 + Scenario: Get list of ec2 images (provider) + When I send GET '/v2.0/images/provider/ec2' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an array + + @ec2 + Scenario: Get list of ec2 images (provider) without header 'Accept' + When I send GET '/v2.0/images/provider/ec2' query without headers 'Accept' + Then response should be '406' + + @ec2 + Scenario: Get images list of ec2 without privileges + When I send GET '/v2.0/images/provider/ec2' query with user without privileges + Then response should be '401' + + @ec2 + Scenario: Get ec2 image without privileges + When I send GET '/v2.0/image/ami-63071b0a' query with user without privileges + Then response should be '401' + + Scenario: Get list of images of unknown provider + When I send GET '/v2.0/images/provider/foo' query + Then response should be '404' + + Scenario: Get images list without privileges + When I send GET '/v2.0/images' query with user without privileges + Then response should be '401' + + Scenario: Get unknown image + When I send GET '/v2.0/image/foo' query + Then response should be '404' + + Scenario: Get unknown image without privileges + When I send GET '/v2.0/image/foo' query with user without privileges + Then response should be '401' + + @openstack + Scenario: Create openstack image with invalid provider + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "foo", + "name": "freebsd-10.0", + "remote_user": "root", + "bootstrap_template": "chef_freebsd", + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid provider - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": ["foo"], + "name": "freebsd-10.0", + "remote_user": "root", + "bootstrap_template": "chef_freebsd", + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid provider - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": {}, + "name": "freebsd-10.0", + "remote_user": "root", + "bootstrap_template": "chef_freebsd", + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid name - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": {}, + "remote_user": "root", + "bootstrap_template": "chef_freebsd", + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid name - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": [], + "remote_user": "root", + "bootstrap_template": "chef_freebsd", + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid remote_user - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": "freebsd-10.0", + "remote_user": {}, + "bootstrap_template": "chef_freebsd", + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid remote_user - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": "freebsd-10.0", + "remote_user": [], + "bootstrap_template": "chef_freebsd", + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid bootstrap_template - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": "freebsd-10.0", + "remote_user": "root", + "bootstrap_template": [], + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid bootstrap_template - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": "freebsd-10.0", + "remote_user": "root", + "bootstrap_template": {}, + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid id - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": "freebsd-10.0", + "remote_user": "root", + "bootstrap_template": "chef_freebsd", + "id": [] + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image with invalid id - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": "freebsd-10.0", + "remote_user": "root", + "bootstrap_template": "chef_freebsd", + "id": {} + } + """ + Then response should be '400' + + @openstack + Scenario: Create openstack image + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "openstack", + "name": "freebsd-10.0", + "remote_user": "root", + "bootstrap_template": "chef_freebsd", + "id": "08093b30-8393-42c3-8fb3-c4df56deb967" + } + """ + Then response should be '201' + And the Content-Type header should include 'application/json' + + @ec2 + Scenario: Create ec2 image with invalid provider + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "foo", + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid provider - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": ["foo"], + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid provider - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": {}, + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid name - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": {}, + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid name - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": [], + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid remote_user - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": "test-ec2", + "remote_user": {}, + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid remote_user - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": "test-ec2", + "remote_user": [], + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid bootstrap_template - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": [], + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid bootstrap_template - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": {}, + "id": "ami-63071b0a" + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid id - array + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": [] + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image with invalid id - hash + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": {} + } + """ + Then response should be '400' + + @ec2 + Scenario: Create ec2 image + When I send POST '/v2.0/image' query with JSON body + """ + { + "provider": "ec2", + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ + Then response should be '201' + And the Content-Type header should include 'application/json' + + @ec2 + Scenario: Get info for single image + When I send GET '/v2.0/image/ami-63071b0a' query + Then response should be '200' + And the Content-Type header should include 'application/json' + And the JSON response should be an object + And response should be JSON object like: + """ + { + "provider": "ec2", + "name": "test-ec2", + "remote_user": "ec2-user", + "bootstrap_template": null, + "id": "ami-63071b0a" + } + """ diff --git a/devops-service/features/api_v2/20_delete/90_image.feature b/devops-service/features/api_v2/20_delete/90_image.feature new file mode 100644 index 0000000..59b3571 --- /dev/null +++ b/devops-service/features/api_v2/20_delete/90_image.feature @@ -0,0 +1,23 @@ +@image +Feature: delete image + + @openstack + Scenario: Delete openstack image with user without privileges + When I send DELETE '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query with user without privileges + Then response should be '401' + + @openstack + Scenario: Delete openstack image + When I send DELETE '/v2.0/image/08093b30-8393-42c3-8fb3-c4df56deb967' query + Then response should be '200' + + @ec2 + Scenario: Delete ec2 image with user without privileges + When I send DELETE '/v2.0/image/ami-63071b0a' query with user without privileges + Then response should be '401' + + @ec2 + Scenario: Delete ec2 image + When I send DELETE '/v2.0/image/ami-63071b0a' query + Then response should be '200' + diff --git a/devops-service/features/api_v2/image.feature b/devops-service/features/api_v2/image.feature deleted file mode 100644 index cbc9252..0000000 --- a/devops-service/features/api_v2/image.feature +++ /dev/null @@ -1,48 +0,0 @@ -@image -Feature: Manage images - - Scenario: Get list of all images - When I send GET '/v2.0/images' query - Then response should be '200' - And the Content-Type header should include 'application/json' - And the JSON response should be an array - And response array should contains elements like: - """ - [ - { - "provider": "foo_provider", - "name": "foo_name", - "remote_user": "foo_user", - "bootstrap_template": "foo_template", - "id": "foo_id" - } - ] - """ - - Scenario: Get info for single image - When I send GET '/v2.0/image/ami-83e4bcea' query - Then response should be '200' - And the Content-Type header should include 'application/json' - And the JSON response should be a hash - And response should be JSON object like: - """ - { - "provider": "foo_provider", - "name": "foo_name", - "remote_user": "foo_user", - "bootstrap_template": "foo_template", - "id": "b79994de" - } - """ - - Scenario: Get images list without privileges - When I send GET '/v2.0/images' query with user without privileges - Then response should be '401' - - Scenario: Get image without privileges - When I send GET '/v2.0/image/ami-83e4bcea' query with user without privileges - Then response should be '401' - - Scenario: Get unknown image - When I send GET '/v2.0/image/foo' query - Then response should be '404' diff --git a/devops-service/routes/v2.0/image.rb b/devops-service/routes/v2.0/image.rb index 11fc852..656afc2 100644 --- a/devops-service/routes/v2.0/image.rb +++ b/devops-service/routes/v2.0/image.rb @@ -174,7 +174,7 @@ module Version2_0 end r = BaseRoutes.mongo.image_delete params[:image_id] - create_response("Image '#{params[:image_id]}' removed") + create_response("Image '#{params[:image_id]}' has been removed") end end