Permalink
Browse files

makes the tests more independent from the sugarCRM

now the tests work with SugarCRM servers other than 127.0.0.1 and
accepts admin users with other usernames than admin
  • Loading branch information...
1 parent 714e852 commit 0005ad3711597c8aa371a38413150ad223ea1671 Jens Fahnenbruck committed May 18, 2011
Showing with 19 additions and 14 deletions.
  1. +5 −4 lib/sugarcrm/session.rb
  2. +4 −3 test/connection/test_get_entry_list.rb
  3. +1 −0 test/helper.rb
  4. +5 −5 test/test_finders.rb
  5. +4 −2 test/test_session.rb
View
@@ -102,10 +102,11 @@ def extensions_folder=(folder, dirstring=nil)
end
# load credentials from file, and (re)connect to SugarCRM
- def load_config(path)
+ def load_config(path, opts = {})
+ opts.reverse_merge! :reconnect => true
new_config = self.class.parse_config_file(path)
- @config[:config] = new_config[:config] if new_config
- reconnect(@config[:base_url], @config[:username], @config[:password]) if connection_info_loaded?
+ update_config(new_config[:config]) if new_config and new_config[:config]
+ reconnect(@config[:base_url], @config[:username], @config[:password]) if opts[:reconnect] and connection_info_loaded?
@config
end
@@ -207,4 +208,4 @@ def self.parse_connection_pool_options(config_values)
result[:wait_timeout] = wait_timeout if wait_timeout
result
end
-end; end
+end; end
@@ -2,12 +2,13 @@
class TestGetEntryList < ActiveSupport::TestCase
context "A SugarCRM.connection" do
- should "return a list of entries when sent #get_entry_list and no fields." do
+ should "return a list of entries when sent #get_entry_list" do
users = SugarCRM.connection.get_entry_list(
"Users",
"users.deleted = 0"
)
- assert_equal "admin", users.first.user_name
+ assert_kind_of Array, users
+ assert_equal SugarCRM.config[:username], users.first.user_name
end
should "return an object when #get_entry_list" do
@response = SugarCRM.connection.get_entry_list(
@@ -19,4 +20,4 @@ class TestGetEntryList < ActiveSupport::TestCase
assert_instance_of SugarCRM::User, @response[0]
end
end
-end
+end
View
@@ -1,6 +1,7 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
+require 'active_support/test_case'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
View
@@ -5,9 +5,9 @@ class TestFinders < ActiveSupport::TestCase
should "always return an Array when :all" do
users = SugarCRM::User.all(:limit => 10)
assert_instance_of Array, users
- users = SugarCRM::User.find(:all, :conditions => {:user_name => '= admin'})
+ users = SugarCRM::User.find(:all, :conditions => {:user_name => "= #{users.first.user_name}"})
assert_instance_of Array, users
- assert users.length == 1
+ assert_equal 1, users.length
users = SugarCRM::User.find(:all, :conditions => {:user_name => '= invalid_user_123'})
assert_instance_of Array, users
assert users.length == 0
@@ -101,12 +101,12 @@ class TestFinders < ActiveSupport::TestCase
should "receive a response containing all fields when sent #get_entry" do
u = SugarCRM::User.find(1)
- assert_equal u.user_name, "admin"
+ assert_not_nil u.user_name
end
should "return an array of records when sent #find([id1, id2, id3])" do
users = SugarCRM::User.find(["seed_sarah_id", 1])
- assert_equal "admin", users.last.user_name
+ assert_not_nil users.last.user_name
end
# test Base#find_by_sql edge case
@@ -198,4 +198,4 @@ class TestFinders < ActiveSupport::TestCase
assert a.delete
end
end
-end
+end
View
@@ -15,6 +15,7 @@
class TestSession < ActiveSupport::TestCase
context "The SugarCRM::Session class" do
should "raise SugarCRM::MissingCredentials if at least one of url/username/password is missing" do
+
assert_raise(SugarCRM::MissingCredentials){ SugarCRM.connect('http://127.0.0.1/sugarcrm', nil, nil) }
end
@@ -33,7 +34,7 @@ class TestSession < ActiveSupport::TestCase
end
should "parse config parameters from a file" do
- assert_equal CONFIG_CONTENTS, SugarCRM::Session.parse_config_file(CONFIG_PATH)
+ assert_equal CONFIG_CONTENTS, SugarCRM::Session.parse_config_file(CONFIG_TEST_PATH)
end
should "create a session from a config file" do
@@ -59,8 +60,9 @@ class TestSession < ActiveSupport::TestCase
end
should "load config file" do
- SugarCRM.load_config CONFIG_TEST_PATH
+ SugarCRM.load_config CONFIG_TEST_PATH, :reconnect => false
CONFIG_CONTENTS[:config].each{|k,v| assert_equal v, SugarCRM.config[k]}
+ SugarCRM.load_config CONFIG_PATH
end
should "be able to disconnect, and log in to Sugar automatically if credentials are present in config file" do

0 comments on commit 0005ad3

Please sign in to comment.