[PATCH conductor 2/3] Rspec tests for Provider Accounts API - update

pblaho at redhat.com pblaho at redhat.com
Wed Aug 15 23:30:39 UTC 2012


From: Petr Blaho <pblaho at redhat.com>

https://www.aeolusproject.org/redmine/issues/3691

Adds rspec tests for Provider Accounts API - update
---
 src/spec/requests/api/provider_accounts_spec.rb |  180 ++++++++++++++++++++---
 1 files changed, 162 insertions(+), 18 deletions(-)

diff --git a/src/spec/requests/api/provider_accounts_spec.rb b/src/spec/requests/api/provider_accounts_spec.rb
index f973f48..a7ed5c7 100644
--- a/src/spec/requests/api/provider_accounts_spec.rb
+++ b/src/spec/requests/api/provider_accounts_spec.rb
@@ -52,17 +52,17 @@ describe "ProviderAccounts" do
         let(:xml) do
           DeltaCloud.stub(:valid_credentials?).and_return(true)
           "<provider_account>
-             <label>ec2account</label>
-             <credentials>
-               <username>ec2user</username>
-               <password>ec2password</password>
-               <account_id>ec2account_id</account_id>
-               <x509private><![CDATA[ec2x509private]]></x509private>
-               <x509public><![CDATA[ec2x509public]]></x509public>
-             </credentials>
-           </provider_account>"
+            <label>ec2account</label>
+            <credentials>
+              <username>ec2user</username>
+              <password>ec2password</password>
+              <account_id>ec2account_id</account_id>
+              <x509private><![CDATA[ec2x509private]]></x509private>
+              <x509public><![CDATA[ec2x509public]]></x509public>
+            </credentials>
+          </provider_account>"
         end
-        let(:provider) { FactoryGirl.create(:ec2_provider) }
+        let(:provider) { DeltaCloud.stub(:valid_credentials?).and_return(true); FactoryGirl.create(:ec2_provider) }
 
         it_behaves_like "http OK"
         it_behaves_like "responding with XML"
@@ -109,14 +109,14 @@ describe "ProviderAccounts" do
         let(:xml) do
           DeltaCloud.stub(:valid_credentials?).and_return(true)
           "<provider_account>
-           <credentials>
-             <username>ec2user</username>
-             <password>ec2password</password>
-             <account_id>ec2account_id</account_id>
-             <x509private><![CDATA[ec2x509private]]></x509private>
-             <x509public><![CDATA[ec2x509public]]></x509public>
-           </credentials>
-         </provider_account>"
+          <credentials>
+            <username>ec2user</username>
+            <password>ec2password</password>
+            <account_id>ec2account_id</account_id>
+            <x509private><![CDATA[ec2x509private]]></x509private>
+            <x509public><![CDATA[ec2x509public]]></x509public>
+          </credentials>
+        </provider_account>"
         end
         let(:provider) { FactoryGirl.create(:ec2_provider) }
 
@@ -132,4 +132,148 @@ describe "ProviderAccounts" do
       end
     end
   end
+
+  describe "PUT /api/provider_accounts/:provider_account_id" do
+    before(:each) do
+      put "/api/provider_accounts/#{provider_account.id}", xml, headers
+    end
+
+    context "for existing Provider Account" do
+      context "with valid" do
+        context "mock provider account XML" do
+          let(:xml) do
+            "<provider_account><label>mockaccount</label><credentials><username>mockuser</username><password>mockpassword</password></credentials></provider_account>"
+          end
+          let(:provider) { FactoryGirl.create(:mock_provider) }
+          let(:provider_account) { FactoryGirl.create(:mock_provider_account, :provider => provider) }
+
+          it_behaves_like "http OK"
+          it_behaves_like "responding with XML"
+          context "XML body" do
+            subject { Nokogiri::XML(response.body) }
+            it "should have correct nodes" do
+              subject.xpath('//provider_account').size.should be_eql(1)
+              subject.xpath('//provider_account/label').size.should be_eql(1)
+              subject.xpath('//provider_account/label').text.should be_eql("mockaccount")
+              subject.xpath('//provider_account/credentials').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/username').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/username').text.should be_eql("mockuser")
+              subject.xpath('//provider_account/credentials/password').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/password').text.should be_eql("mockpassword")
+            end
+          end
+        end
+
+        context "ec2 provider account XML" do
+          let(:xml) do
+            DeltaCloud.stub(:valid_credentials?).and_return(true)
+            "<provider_account>
+                         <label>ec2account</label>
+                         <credentials>
+                           <username>ec2user</username>
+                           <password>ec2password</password>
+                           <account_id>ec2account_id</account_id>
+                           <x509private><![CDATA[ec2x509private]]></x509private>
+                           <x509public><![CDATA[ec2x509public]]></x509public>
+                         </credentials>
+                       </provider_account>"
+          end
+          let(:provider) { FactoryGirl.create(:ec2_provider) }
+          let(:provider_account) { DeltaCloud.stub(:valid_credentials?).and_return(true); FactoryGirl.create(:ec2_provider_account, :provider => provider) }
+
+          it_behaves_like "http OK"
+          it_behaves_like "responding with XML"
+          context "XML body" do
+            subject { Nokogiri::XML(response.body) }
+            it "should have correct nodes" do
+              subject.xpath('//provider_account').size.should be_eql(1)
+              subject.xpath('//provider_account/label').size.should be_eql(1)
+              subject.xpath('//provider_account/label').text.should be_eql("ec2account")
+              subject.xpath('//provider_account/credentials').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/username').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/username').text.should be_eql("ec2user")
+              subject.xpath('//provider_account/credentials/account_id').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/account_id').text.should be_eql("ec2account_id")
+              subject.xpath('//provider_account/credentials/password').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/password').text.should be_eql("ec2password")
+              subject.xpath('//provider_account/credentials/x509private').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/x509private').text.should be_eql("ec2x509private")
+              subject.xpath('//provider_account/credentials/x509public').size.should be_eql(1)
+              subject.xpath('//provider_account/credentials/x509public').text.should be_eql("ec2x509public")
+            end
+          end
+        end
+      end
+
+      context "with invalid" do
+        context "mock provider account XML" do
+          # omit label
+          let(:xml) do
+            "<provider_account><label></label><credentials><username>mockuser</username><password>mockpassword</password></credentials></provider_account>"
+          end
+          let(:provider) { FactoryGirl.create(:mock_provider) }
+          let(:provider_account) { FactoryGirl.create(:mock_provider_account, :provider => provider) }
+
+          it_behaves_like "http Bad Request"
+          it_behaves_like "responding with XML"
+          context "XML body" do
+            subject { Nokogiri::XML(response.body) }
+            it "should have some errors" do
+              subject.xpath('//errors').size.should be_eql(1)
+              subject.xpath('//errors/error').size.should <= 1
+            end
+          end
+
+        end
+
+        context "ec2 provider account XML" do
+          # omit label
+          let(:xml) do
+            DeltaCloud.stub(:valid_credentials?).and_return(true)
+            "<provider_account>
+                         <label></label>
+                         <credentials>
+                           <username>ec2user</username>
+                           <password>ec2password</password>
+                           <account_id>ec2account_id</account_id>
+                           <x509private><![CDATA[ec2x509private]]></x509private>
+                           <x509public><![CDATA[ec2x509public]]></x509public>
+                         </credentials>
+                       </provider_account>"
+          end
+          let(:provider) { FactoryGirl.create(:ec2_provider) }
+          let(:provider_account) { DeltaCloud.stub(:valid_credentials?).and_return(true); FactoryGirl.create(:ec2_provider_account, :provider => provider) }
+
+          it_behaves_like "http Bad Request"
+          it_behaves_like "responding with XML"
+          context "XML body" do
+            subject { Nokogiri::XML(response.body) }
+            it "should have some errors" do
+              subject.xpath('//errors').size.should be_eql(1)
+              subject.xpath('//errors/error').size.should <= 1
+            end
+          end
+        end
+      end
+    end
+
+    context "for non existing Provider Account" do
+
+      let(:provider_account) { provider_account = FactoryGirl.create(:mock_provider_account); ProviderAccount.delete(provider_account.id); provider_account }
+      let(:xml) { "" }
+
+      it_behaves_like "http Not Found"
+      it_behaves_like "responding with XML"
+
+      context "XML body" do
+        subject { Nokogiri::XML(response.body) }
+
+        it "have RecordNotFound error message" do
+          subject.xpath('//error').size.should be_eql(1)
+          subject.xpath('//error/code').text.should be_eql('RecordNotFound')
+        end
+      end
+
+    end
+  end
 end
-- 
1.7.7.6




More information about the aeolus-devel mailing list