Skip to content

Commit

Permalink
makes the tests more independent from the sugarCRM
Browse files Browse the repository at this point in the history
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
Jens Fahnenbruck committed May 18, 2011
1 parent 714e852 commit 0005ad3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
9 changes: 5 additions & 4 deletions lib/sugarcrm/session.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions test/connection/test_get_entry_list.rb
Expand Up @@ -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(
Expand All @@ -19,4 +20,4 @@ class TestGetEntryList < ActiveSupport::TestCase
assert_instance_of SugarCRM::User, @response[0]
end
end
end
end
1 change: 1 addition & 0 deletions test/helper.rb
@@ -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__))
Expand Down
10 changes: 5 additions & 5 deletions test/test_finders.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -198,4 +198,4 @@ class TestFinders < ActiveSupport::TestCase
assert a.delete
end
end
end
end
6 changes: 4 additions & 2 deletions test/test_session.rb
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 0005ad3

Please sign in to comment.