From ac6e1825bac74ecd173431105e29ccacfb7b3ffb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Kom=C3=A1nek?= Date: Wed, 9 Nov 2016 10:36:53 +0100 Subject: [PATCH] Refactoring the available_flavors spec for the automate Cloud Orchestration. --- .../__methods__/available_flavors.rb | 18 +-- .../available_flavors_spec.rb | 83 ------------ .../__methods__/available_flavors_spec.rb | 119 ++++++++++++++++++ 3 files changed, 125 insertions(+), 95 deletions(-) delete mode 100644 spec/automation/unit/method_validation/available_flavors_spec.rb create mode 100644 spec/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_flavors_spec.rb diff --git a/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_flavors.rb b/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_flavors.rb index 2adc968c345..250097a77d4 100644 --- a/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_flavors.rb +++ b/db/fixtures/ae_datastore/ManageIQ/Cloud/Orchestration/Operations/Methods.class/__methods__/available_flavors.rb @@ -12,27 +12,21 @@ def initialize(handle = $evm) end def main - fill_dialog_field(fetch_selected_os) + fill_dialog_field(fetch_list_data) end - def fetch_selected_os - flavor_list = {} - service = $evm.root.attributes["service_template"] || $evm.root.attributes["service"] - if service.respond_to?(:orchestration_manager) && service.orchestration_manager - service.orchestration_manager.flavors.each { |f| flavor_list[f.name] = f.name } - end - flavor_list[nil] = flavor_list.empty? ? "" : "" - + private + def fetch_list_data service = @handle.root.attributes["service_template"] || @handle.root.attributes["service"] flavors = service.try(:orchestration_manager).try(:flavors) flavor_list = {} - flavor_list.each { |f| flavor_list[f.name] = f.name } if flavors + flavors.each { |f| flavor_list[f.name] = f.name } if flavors - return nil => "" if flavor_list.blank? + return nil => "" if flavor_list.blank? - flavor_list[nil] = "" if flavor_list.length > 1 + flavor_list[nil] = "" } + let(:flavor1) { FactoryGirl.create(:flavor, :name => 'flavor1') } + let(:flavor2) { FactoryGirl.create(:flavor, :name => 'flavor2') } + let(:ems) { FactoryGirl.create(:ems_openstack, :flavors => [flavor1, flavor2]) } + + let(:svc_model_flavor1) do + MiqAeMethodService::MiqAeServiceFlavor.find(flavor1.id) + end + + let(:svc_model_flavor2) do + MiqAeMethodService::MiqAeServiceFlavor.find(flavor2.id) + end + + let(:svc_model_orchestration_manager) do + MiqAeMethodService::MiqAeServiceExtManagementSystem.find(ems.id) + end + + let(:svc_model_service) do + root_hash["service_template"] || root_hash["service"] + end + + it "finds all the flavors and populates the list" do + allow(ae_service.root).to receive(:attributes) + .and_return(service_type => svc_model_service) + allow(svc_model_service).to receive(:orchestration_manager) + .and_return(svc_model_orchestration_manager) + allow(svc_model_orchestration_manager).to receive(:flavors) + .and_return([svc_model_flavor1, svc_model_flavor2]) + described_class.new(ae_service).main + + expect(ae_service["values"]).to include( + nil => default_desc, + flavor1.name => flavor1.name, + flavor2.name => flavor2.name + ) + expect(ae_service["default_value"]).to be_nil + end + end + + context "workspace has no service template" do + let(:root_hash) { {} } + + it_behaves_like "#having only default value" + end + + context "workspace has service template other than orchestration" do + let(:service_template) { FactoryGirl.create(:service_template) } + + it_behaves_like "#having only default value" + end + + context "workspace has orchestration service template" do + context 'with orchestration_manager' do + let(:service_template) do + FactoryGirl.create(:service_template_orchestration, :orchestration_manager => ems) + end + + it_behaves_like "#having all flavors", "service_template" + end + + context 'without orchestration_manager' do + let(:service_template) do + FactoryGirl.create(:service_template_orchestration) + end + + it_behaves_like "#having only default value" + end + end + + context "workspace has orchestration service" do + let(:root_hash) do + { 'service' => MiqAeMethodService::MiqAeServiceService.find(service.id) } + end + + context 'with orchestration_manager' do + let(:service) do + FactoryGirl.create(:service_orchestration, :orchestration_manager => ems) + end + + it_behaves_like "#having all flavors", "service" + end + + context 'without orchestration_manager' do + let(:service) do + FactoryGirl.create(:service_orchestration) + end + + it_behaves_like "#having only default value" + end + end +end