|
| 1 | +RSpec.describe 'Flavors API' do |
| 2 | + let(:ems) { FactoryGirl.create(:ems_cloud) } |
| 3 | + let(:flavor) { FactoryGirl.create(:flavor_openstack, :ext_management_system => ems) } |
| 4 | + let(:flavor_2) { FactoryGirl.create(:flavor_openstack, :ext_management_system => ems) } |
| 5 | + |
| 6 | + describe 'GET/api/flavors' do |
| 7 | + it 'lists all the flavor bases with an appropriate role' do |
| 8 | + flavor = FactoryGirl.create(:flavor_openstack) |
| 9 | + |
| 10 | + api_basic_authorize collection_action_identifier(:flavors, :read, :get) |
| 11 | + |
| 12 | + run_get(api_flavors_url) |
| 13 | + |
| 14 | + expected = { |
| 15 | + 'count' => 1, |
| 16 | + 'subcount' => 1, |
| 17 | + 'name' => 'flavors', |
| 18 | + 'resources' => [hash_including('href' => a_string_matching(api_flavors_url(nil, flavor.compressed_id)))] |
| 19 | + } |
| 20 | + expect(response.parsed_body).to include(expected) |
| 21 | + expect(response).to have_http_status(:ok) |
| 22 | + end |
| 23 | + |
| 24 | + it 'forbids access to flavor bases without an appropriate role' do |
| 25 | + api_basic_authorize |
| 26 | + |
| 27 | + run_get(api_flavors_url) |
| 28 | + |
| 29 | + expect(response).to have_http_status(:forbidden) |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + describe 'GET /api/flavors/:id' do |
| 34 | + it 'will show a flavor base' do |
| 35 | + api_basic_authorize action_identifier(:flavors, :read, :resource_actions, :get) |
| 36 | + |
| 37 | + run_get(api_flavor_url(nil, flavor)) |
| 38 | + |
| 39 | + expected = { |
| 40 | + 'href' => a_string_matching(api_flavors_url(nil, flavor.compressed_id)) |
| 41 | + } |
| 42 | + expect(response.parsed_body).to include(expected) |
| 43 | + expect(response).to have_http_status(:ok) |
| 44 | + end |
| 45 | + |
| 46 | + it 'forbids access to a flavor base' do |
| 47 | + api_basic_authorize |
| 48 | + |
| 49 | + run_get(api_flavors_url) |
| 50 | + |
| 51 | + expect(response).to have_http_status(:forbidden) |
| 52 | + end |
| 53 | + end |
| 54 | + |
| 55 | + describe 'DELETE /api/flavors/:id' do |
| 56 | + it 'will delete a flavor' do |
| 57 | + api_basic_authorize action_identifier(:flavors, :delete, :resource_actions, :delete) |
| 58 | + |
| 59 | + run_delete api_flavor_url(nil, flavor) |
| 60 | + |
| 61 | + expect(response).to have_http_status(:no_content) |
| 62 | + end |
| 63 | + |
| 64 | + it 'will not delete a flavor without an appropriate role' do |
| 65 | + api_basic_authorize |
| 66 | + |
| 67 | + run_delete api_flavor_url(nil, flavor) |
| 68 | + |
| 69 | + expect(response).to have_http_status(:forbidden) |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + describe 'POST /api/flavors' do |
| 74 | + let(:create_params) do |
| 75 | + { |
| 76 | + :action => 'create', |
| 77 | + :description => "Description", |
| 78 | + :name => "A Flavor", |
| 79 | + :related => {}, |
| 80 | + :ems => { :id => ems.id }, |
| 81 | + :type => 'ManageIQ::Providers::Openstack::CloudManager::Flavor', |
| 82 | + } |
| 83 | + end |
| 84 | + |
| 85 | + it 'will delete multiple flavors' do |
| 86 | + api_basic_authorize collection_action_identifier(:flavors, :delete, :post) |
| 87 | + |
| 88 | + expected = { |
| 89 | + 'results' => [ |
| 90 | + a_hash_including( |
| 91 | + 'success' => true, |
| 92 | + 'message' => a_string_including('Deleting Flavor'), |
| 93 | + 'task_id' => a_kind_of(String) |
| 94 | + ), |
| 95 | + a_hash_including( |
| 96 | + 'success' => true, |
| 97 | + 'message' => a_string_including('Deleting Flavor'), |
| 98 | + 'task_id' => a_kind_of(String) |
| 99 | + ) |
| 100 | + ] |
| 101 | + } |
| 102 | + |
| 103 | + run_post(api_flavors_url, :action => 'delete', :resources => [{ 'id' => flavor.id}, { 'id' => flavor_2.id }]) |
| 104 | + |
| 105 | + expect(response.parsed_body).to include(expected) |
| 106 | + expect(response).to have_http_status(:ok) |
| 107 | + end |
| 108 | + |
| 109 | + it 'will forbid deletion to an flavor without appropriate role' do |
| 110 | + api_basic_authorize |
| 111 | + |
| 112 | + run_post(api_flavors_url, :action => 'delete', :resources => [{ 'id' => flavor.id }]) |
| 113 | + expect(response).to have_http_status(:forbidden) |
| 114 | + end |
| 115 | + |
| 116 | + it 'can create an flavor' do |
| 117 | + api_basic_authorize collection_action_identifier(:flavors, :create, :post) |
| 118 | + |
| 119 | + expected = { |
| 120 | + 'results' => [a_hash_including( |
| 121 | + 'success' => true, |
| 122 | + 'message' => 'Creating Flavor', |
| 123 | + 'task_id' => a_kind_of(String) |
| 124 | + )] |
| 125 | + } |
| 126 | + run_post(api_flavors_url, create_params) |
| 127 | + |
| 128 | + expect(response).to have_http_status(:ok) |
| 129 | + expect(response.parsed_body).to include(expected) |
| 130 | + end |
| 131 | + |
| 132 | + it 'can create flavors in bulk' do |
| 133 | + api_basic_authorize collection_action_identifier(:flavors, :create, :post) |
| 134 | + |
| 135 | + expected = { |
| 136 | + 'results' => [ |
| 137 | + a_hash_including( |
| 138 | + 'success' => true, |
| 139 | + 'message' => 'Creating Flavor', |
| 140 | + 'task_id' => a_kind_of(String) |
| 141 | + ), |
| 142 | + a_hash_including( |
| 143 | + 'success' => true, |
| 144 | + 'message' => 'Creating Flavor', |
| 145 | + 'task_id' => a_kind_of(String) |
| 146 | + ) |
| 147 | + ] |
| 148 | + } |
| 149 | + run_post(api_flavors_url, :resources => [create_params, create_params]) |
| 150 | + |
| 151 | + expect(response).to have_http_status(:ok) |
| 152 | + expect(response.parsed_body).to include(expected) |
| 153 | + end |
| 154 | + |
| 155 | + it 'will forbid creation of an flavor without appropriate role' do |
| 156 | + api_basic_authorize |
| 157 | + |
| 158 | + run_post(api_flavors_url, :action => 'create') |
| 159 | + |
| 160 | + expect(response).to have_http_status(:forbidden) |
| 161 | + end |
| 162 | + end |
| 163 | +end |
0 commit comments