ref: refs/heads/master
commit 841e188697c95abeaa58a958f593e5b66847e285
Author: Klaus Kämpf
Date: Sat Sep 26 20:49:52 2009 +0200
Use new PackageKit mocking
---
plugins/patches/test/unit/patch_test.rb | 83 +++++-------------------------
1 files changed, 14 insertions(+), 69 deletions(-)
diff --git a/plugins/patches/test/unit/patch_test.rb b/plugins/patches/test/unit/patch_test.rb
index fd5dea7..67156ac 100644
--- a/plugins/patches/test/unit/patch_test.rb
+++ b/plugins/patches/test/unit/patch_test.rb
@@ -1,5 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+require File.join(File.dirname(__FILE__), "..", "packagekit_stub")
require 'patch'
class PatchTest < ActiveSupport::TestCase
@@ -17,6 +18,12 @@ class PatchTest < ActiveSupport::TestCase
# avoid accessing the rpm db
Patch.stubs(:mtime).returns(Time.now)
+ @pk_stub = PackageKitStub.new
+
+ end
+
+ def test_available_patches
+ results = Array.new
# Available updates in PackageKit format
#
# Format:
@@ -25,78 +32,16 @@ class PatchTest < ActiveSupport::TestCase
# line2: <name>;<id>;<arch>;<repo>
# line3: <summary>
#
- update_result1 = ['important', 'update-test-affects-package-manager;847;noarch;updates-test', 'update-test: Test updates for 11.2']
- update_result2 = ['security', 'update-test;844;noarch;updates-test', 'update-test: Test update for 11.2']
-
-
- #
- # PackageKit stubbing
- #
- # We mock all calls needed to access the PackageKit
- # dbus service
- #
-
- # Service object with arbitrary transaction id
- obj_tid = DBus::ProxyObject.new(DBus::SystemBus.instance, SERVICE, "/104_acdadcdd_data")
- # no introspection needed
- obj_tid.stubs(:introspect).returns(true)
- # provides interface
- obj_tid.stubs(:has_iface?).returns(true)
-
- # Transaction interface
- obj_tid_with_iface = DBus::ProxyObjectInterface.new(obj_tid, TRANSACTION)
- # provides 'GetUpdates' method
- obj_tid_with_iface.stubs(:GetUpdates).with("NONE").returns(true)
-
- # allow Array-like access to interface
- obj_tid[TRANSACTION] = obj_tid_with_iface
-
- # Create PackageKit object stub
- object = DBus::ProxyObject.new(DBus::SystemBus.instance, SERVICE, PATH)
- object.stubs(:introspect).returns(true)
-
- # Create interface
- obj_with_iface = DBus::ProxyObjectInterface.new(object, SERVICE)
-
- # Stub a transaction ID
- obj_with_iface.stubs(:GetTid).returns([TID])
- obj_with_iface.stubs(:SuggestDaemonQuit).returns(true)
-
- # object[SERVICE] returns interface
- object.stubs(:'[]').with(SERVICE).returns(obj_with_iface)
-
- # allow access to PackageKit and Transaction via Service
- DBus::Service.any_instance.stubs(:object).with(PATH).returns(object)
- DBus::Service.any_instance.stubs(:object).with(TID).returns(obj_tid)
-
- # Duplicate ??
- service = DBus::Service.new(SERVICE, DBus::SystemBus.instance)
- service.stubs(:object).with(PATH).returns(object)
- service.stubs(:object).with(TID).returns(obj_tid)
-
- DBus::SystemBus.instance.stubs(:service).with(SERVICE).returns(service)
-
- #
- # mix Patch and PackageKit mocking
- #
+ results << PackageKitResult.new( 'important', 'update-test-affects-package-manager;847;noarch;updates-test', 'update-test: Test updates for 11.2')
+ results << PackageKitResult.new( 'security', 'update-test;844;noarch;updates-test', 'update-test: Test update for 11.2')
- # emit updates
-
- DBus::Main.send(:define_method, :run) do
- DBus::SystemBus.instance.emit(service, obj_tid, obj_tid_with_iface, DBus::Signal.new("Packages"), update_result1)
- DBus::SystemBus.instance.emit(service, obj_tid, obj_tid_with_iface, DBus::Signal.new("Packages"), update_result2)
- @buses.each do |socket, bus|
- end
- return true
- end
-
- end
+ signal = "Package"
+ @pk_stub.run signal, results
- def test_available_patches
patches = Patch.find(:available)
- #assert_equal(2, patches.size)
- #patch = patches.first
- #assert_equal("847", patch.resolvable_id)
+ assert_equal 2, patches.size
+ patch = patches.first
+ assert_equal "847", patch.resolvable_id
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org