|
| 1 | +RSpec.describe "Flavors API" do |
| 2 | + describe "as a subcollection of providers" do |
| 3 | + describe "GET /api/providers/:c_id/flavors" do |
| 4 | + it "can list the flavors of a provider" do |
| 5 | + api_basic_authorize(action_identifier(:flavors, :read, :subcollection_actions, :get)) |
| 6 | + ems = FactoryGirl.create(:ems_cloud) |
| 7 | + flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) |
| 8 | + |
| 9 | + get(api_provider_flavors_url(nil, ems)) |
| 10 | + |
| 11 | + expected = { |
| 12 | + "count" => 1, |
| 13 | + "name" => "flavors", |
| 14 | + "resources" => [ |
| 15 | + {"href" => api_provider_flavor_url(nil, ems, flavor)} |
| 16 | + ] |
| 17 | + } |
| 18 | + expect(response.parsed_body).to include(expected) |
| 19 | + expect(response).to have_http_status(:ok) |
| 20 | + end |
| 21 | + |
| 22 | + it "will not list flavors unless authorized" do |
| 23 | + api_basic_authorize |
| 24 | + ems = FactoryGirl.create(:ems_cloud) |
| 25 | + FactoryGirl.create(:flavor, :ext_management_system => ems) |
| 26 | + |
| 27 | + get(api_provider_flavors_url(nil, ems)) |
| 28 | + |
| 29 | + expect(response).to have_http_status(:forbidden) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe "GET /api/providers/:c_id/flavors/:id" do |
| 34 | + it "can show a provider's flavor" do |
| 35 | + api_basic_authorize(action_identifier(:flavors, :read, :subresource_actions, :get)) |
| 36 | + ems = FactoryGirl.create(:ems_cloud) |
| 37 | + flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) |
| 38 | + |
| 39 | + get(api_provider_flavor_url(nil, ems, flavor)) |
| 40 | + |
| 41 | + expected = { |
| 42 | + "href" => api_provider_flavor_url(nil, ems, flavor), |
| 43 | + "id" => flavor.id.to_s |
| 44 | + } |
| 45 | + expect(response.parsed_body).to include(expected) |
| 46 | + expect(response).to have_http_status(:ok) |
| 47 | + end |
| 48 | + |
| 49 | + it "will not show a flavor unless authorized" do |
| 50 | + api_basic_authorize |
| 51 | + ems = FactoryGirl.create(:ems_cloud) |
| 52 | + flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) |
| 53 | + |
| 54 | + get(api_provider_flavor_url(nil, ems, flavor)) |
| 55 | + |
| 56 | + expect(response).to have_http_status(:forbidden) |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + describe "POST /api/providers/:c_id/flavors" do |
| 61 | + it "can queue the creation of a flavors" do |
| 62 | + api_basic_authorize(action_identifier(:flavors, :create, :subcollection_actions)) |
| 63 | + ems = FactoryGirl.create(:ems_cloud) |
| 64 | + |
| 65 | + post(api_provider_flavors_url(nil, ems), :params => { :name => "test-flavor" }) |
| 66 | + |
| 67 | + expected = { |
| 68 | + "results" => [ |
| 69 | + a_hash_including( |
| 70 | + "success" => true, |
| 71 | + "message" => "Creating Flavor", |
| 72 | + "task_id" => anything, |
| 73 | + "task_href" => a_string_matching(api_tasks_url) |
| 74 | + ) |
| 75 | + ] |
| 76 | + } |
| 77 | + expect(response.parsed_body).to include(expected) |
| 78 | + expect(response).to have_http_status(:ok) |
| 79 | + end |
| 80 | + |
| 81 | + it "will not create a flavor unless authorized" do |
| 82 | + api_basic_authorize |
| 83 | + ems = FactoryGirl.create(:ems_cloud) |
| 84 | + |
| 85 | + post(api_provider_flavors_url(nil, ems), :params => { :name => "test-flavor" }) |
| 86 | + |
| 87 | + expect(response).to have_http_status(:forbidden) |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + describe "POST /api/providers/:c_id/flavors/:s_id with delete action" do |
| 92 | + it "can queue a flavor for deletion" do |
| 93 | + api_basic_authorize(action_identifier(:flavors, :delete, :subresource_actions)) |
| 94 | + |
| 95 | + ems = FactoryGirl.create(:ems_cloud) |
| 96 | + flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) |
| 97 | + |
| 98 | + post(api_provider_flavor_url(nil, ems, flavor), :params => { :action => "delete" }) |
| 99 | + |
| 100 | + expected = { |
| 101 | + "message" => "Deleting Flavor id:#{flavor.id} name: '#{flavor.name}'", |
| 102 | + "success" => true, |
| 103 | + "task_href" => a_string_matching(api_tasks_url), |
| 104 | + "task_id" => anything |
| 105 | + } |
| 106 | + expect(response.parsed_body).to include(expected) |
| 107 | + expect(response).to have_http_status(:ok) |
| 108 | + end |
| 109 | + |
| 110 | + it "will not delete a flavor unless authorized" do |
| 111 | + api_basic_authorize |
| 112 | + ems = FactoryGirl.create(:ems_cloud) |
| 113 | + flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) |
| 114 | + |
| 115 | + post(api_provider_flavor_url(nil, ems, flavor), :params => { :action => "delete" }) |
| 116 | + |
| 117 | + expect(response).to have_http_status(:forbidden) |
| 118 | + end |
| 119 | + end |
| 120 | + |
| 121 | + describe "DELETE /api/providers/:c_id/flavors/:s_id" do |
| 122 | + it "can delete a flavor" do |
| 123 | + api_basic_authorize(action_identifier(:flavors, :delete, :subresource_actions, :delete)) |
| 124 | + ems = FactoryGirl.create(:ems_cloud) |
| 125 | + flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) |
| 126 | + |
| 127 | + delete(api_provider_flavor_url(nil, ems, flavor)) |
| 128 | + |
| 129 | + expect(response).to have_http_status(:no_content) |
| 130 | + end |
| 131 | + |
| 132 | + it "will not delete a flavor unless authorized" do |
| 133 | + api_basic_authorize |
| 134 | + ems = FactoryGirl.create(:ems_cloud) |
| 135 | + flavor = FactoryGirl.create(:flavor, :ext_management_system => ems) |
| 136 | + |
| 137 | + delete(api_provider_flavor_url(nil, ems, flavor)) |
| 138 | + |
| 139 | + expect(response).to have_http_status(:forbidden) |
| 140 | + end |
| 141 | + end |
| 142 | + end |
| 143 | +end |
0 commit comments