ref: refs/heads/patch_refactor commit 1a38dd1dfe42d7a208069f4e07e48a34dec75dd2 Author: Klaus Kämpf <kkaempf@suse.de> Date: Fri Sep 25 23:06:53 2009 +0200 Add full D-Bus mocking --- .../test/functional/permissions_controller_test.rb | 17 ++++++++++++++++- webservice/test/functional/scr_test.rb | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/webservice/test/functional/permissions_controller_test.rb b/webservice/test/functional/permissions_controller_test.rb index 3cd3bfc..f8195b7 100644 --- a/webservice/test/functional/permissions_controller_test.rb +++ b/webservice/test/functional/permissions_controller_test.rb @@ -12,7 +12,11 @@ require 'mocha' class PermissionsControllerTest < ActionController::TestCase fixtures :accounts - + + SERVICE = "org.opensuse.yast.SCR" + PATH = "/SCR" + INTERFACE = "#{SERVICE}.Methods" + def setup @controller = PermissionsController.new @request = ActionController::TestRequest.new @@ -21,6 +25,17 @@ class PermissionsControllerTest < ActionController::TestCase # http://railsforum.com/viewtopic.php?id=1719 @request.session[:account_id] = 1 # defined in fixtures + # stub D-Bus/SCR, see lib/scr.rb + @scr_proxy = DBus::ProxyObject.new(DBus::SystemBus.instance, SERVICE, PATH) + @scr_iface = DBus::ProxyObjectInterface.new(@scr_proxy, SERVICE) + # must stub class method here, 'Singleton' seems to prevent instance stubbing ?! + @scr_iface.class.any_instance.stubs(:Write).returns(true) + @scr_iface.class.any_instance.stubs(:Read).returns([["","",""]]) + @scr_iface.class.any_instance.stubs(:Execute).returns([[nil,nil,{"exit"=>[0,0,0],"stdout"=>["","",""], "stderr"=>["","",""]}]]) + + @scr_proxy[INTERFACE] = @scr_iface + DBus::SystemBus.any_instance.stubs(:introspect).with(SERVICE,PATH).returns(@scr_proxy) + Scr.any_instance.stubs(:execute).with(["polkit-action"]).returns({:stderr=>"", :exit=>0, :stdout=>"org.opensuse.yast.system.users.read\norg.opensuse.yast.system.users.write\norg.opensuse.yast.system.users.new\norg.opensuse.yast.system.users.delete\n"}) Scr.any_instance.stubs(:execute).with(["polkit-auth", "--user", "test_user", "--explicit"]).returns(:stderr=>"", :exit=>0, :stdout=>"org.opensuse.yast.system.users.read\norg.opensuse.yast.system.users.write\norg.opensuse.yast.system.users.new\norg.opensuse.yast.permissions.write\n") Scr.any_instance.stubs(:execute).with(['polkit-auth', '--user', 'test_user', '--grant', 'org.opensuse.yast.patch.install']).returns({:stderr=>"", :exit=>0, :stdout=>""}) diff --git a/webservice/test/functional/scr_test.rb b/webservice/test/functional/scr_test.rb index f716b62..27b7fd1 100644 --- a/webservice/test/functional/scr_test.rb +++ b/webservice/test/functional/scr_test.rb @@ -8,7 +8,24 @@ require File.expand_path(File.dirname(__FILE__) + "/../test_helper") class ScrTest < ActiveSupport::TestCase require "scr" - + + SERVICE = "org.opensuse.yast.SCR" + PATH = "/SCR" + INTERFACE = "#{SERVICE}.Methods" + + def setup + # stub D-Bus/SCR, see lib/scr.rb + @scr_proxy = DBus::ProxyObject.new(DBus::SystemBus.instance, SERVICE, PATH) + @scr_iface = DBus::ProxyObjectInterface.new(@scr_proxy, SERVICE) + # must stub class method here, 'Singleton' seems to prevent instance stubbing ?! + @scr_iface.class.any_instance.stubs(:Write).returns(true) + @scr_iface.class.any_instance.stubs(:Read).returns([["","",""]]) + @scr_iface.class.any_instance.stubs(:Execute).returns([[nil,nil,{"exit"=>[0,0,0],"stdout"=>["","",""], "stderr"=>["","",""]}]]) + + @scr_proxy[INTERFACE] = @scr_iface + DBus::SystemBus.any_instance.stubs(:introspect).with(SERVICE,PATH).returns(@scr_proxy) + end + test "instanciating the scr singleton" do assert Scr.instance end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org