ref: refs/heads/master
commit ca683904cad4c450416d1caa9cf9b554c2fb53de
Author: Klaus Kämpf
Date: Tue Sep 22 17:00:41 2009 +0200
Factor out and rewrite PackageKit mocking
---
plugins/patches/test/packagekit_stub.rb | 89 ++++++++++++++++++++++++++
plugins/patches/test/unit/resolvable_test.rb | 27 ++++++++
2 files changed, 116 insertions(+), 0 deletions(-)
diff --git a/plugins/patches/test/packagekit_stub.rb b/plugins/patches/test/packagekit_stub.rb
new file mode 100644
index 0000000..521394c
--- /dev/null
+++ b/plugins/patches/test/packagekit_stub.rb
@@ -0,0 +1,89 @@
+#
+# packagekit_stub.rb
+#
+# Stubs for PackageKit/D-Bus
+#
+#
+
+require File.join(File.dirname(__FILE__), "test_helper")
+
+class PackageKitStub
+
+ SERVICE = "org.freedesktop.PackageKit"
+ PATH = "/org/freedesktop/PackageKit"
+ TRANSACTION = "#{SERVICE}.Transaction"
+ TID = 42 # (dummy) transaction id
+
+ def self.stub!
+
+ #
+ # PackageKit stubbing
+ #
+ # We mock all calls needed to access the PackageKit
+ # dbus service
+ #
+ # Reference: http://www.packagekit.org/gtk-doc/index.html
+ #
+
+ #
+ # PackageKit service
+ #
+
+ # create (dormant) pk_service
+ pk_service = DBus::Service.new(SERVICE, DBus::SystemBus.instance)
+
+ # stub: pk_service = system_bus.service("org.freedesktop.PackageKit")
+ DBus::SystemBus.instance.stubs(:service).with(SERVICE).returns(pk_service)
+
+ #
+ # PackageKit proxy object
+ #
+ packagekit_proxy = DBus::ProxyObject.new(DBus::SystemBus.instance, SERVICE, PATH)
+
+ # stub: packagekit_proxy = pk_service.object("/org/freedesktop/PackageKit")
+ pk_service.stubs(:object).with(PATH).returns(packagekit_proxy)
+
+ # stub: packagekit_proxy.introspect
+ packagekit_proxy.stubs(:introspect).returns(true)
+ packagekit_proxy.stubs(:has_iface?).returns(true)
+
+ #
+ # PackageKit interface
+ #
+ packagekit_iface = DBus::ProxyObjectInterface.new(packagekit_proxy, SERVICE)
+
+ # stub: packagekit_iface = packagekit_proxy["org.freedesktop.PackageKit"]
+ packagekit_proxy[SERVICE] = packagekit_iface
+
+ # stub: tid = packagekit_iface.GetTid
+ packagekit_iface.stubs(:GetTid).returns([TID])
+
+ #
+ # PackageKit transaction proxy
+ #
+ transaction_proxy = DBus::ProxyObject.new(DBus::SystemBus.instance, SERVICE, PATH)
+
+ # stub: transaction_proxy = pk_service.object(tid[0])
+ pk_service.stubs(:object).with(TID).returns(transaction_proxy)
+
+ # stub: transaction_proxy.introspect
+ transaction_proxy.stubs(:introspect).returns(true)
+ transaction_proxy.stubs(:has_iface?).returns(true)
+
+ #
+ # PackageKit transaction interface
+ #
+ transaction_iface = DBus::ProxyObjectInterface.new(pk_service, TRANSACTION)
+
+ # stub: transaction_iface = transaction_proxy["org.freedesktop.PackageKit.Transaction"]
+ transaction_proxy[TRANSACTION] = transaction_iface
+
+ # stub: packagekit_iface.SuggestDaemonQuit
+ packagekit_iface.stubs(:SuggestDaemonQuit).returns(true)
+
+ # stub: transaction_iface.GetUpdates("NONE")
+ transaction_iface.stubs(:GetUpdates).with("NONE").returns(true)
+
+ end # stub !
+
+end # PackageKitStub
diff --git a/plugins/patches/test/unit/resolvable_test.rb b/plugins/patches/test/unit/resolvable_test.rb
new file mode 100644
index 0000000..f2d7688
--- /dev/null
+++ b/plugins/patches/test/unit/resolvable_test.rb
@@ -0,0 +1,27 @@
+#
+# resolvable_test.rb
+#
+# Test 'Resolvable' model
+#
+#
+
+require File.join(File.dirname(__FILE__), "..", "test_helper")
+require File.join(File.dirname(__FILE__), "..", "packagekit_stub")
+
+class ResolvableTest < ActiveSupport::TestCase
+ require 'resolvable'
+
+ def setup
+ PackageKitStub.stub!
+ end
+
+ def test_resolvable_search
+ Resolvable.execute( "SearchName", ["installed;~devel", "yast2"], "Package") do |info,id,summary|
+ assert info
+ assert id
+ assert summary
+ end
+
+ end
+
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org