ref: refs/heads/jr-yastmodel
commit 1b3cb8b179cdf2ba8f0b544be8c3a6ca0f237533
Author: Josef Reidinger
Date: Tue Dec 22 10:57:38 2009 +0100
add wrapper around http mock to easy test plugins
---
webclient/lib/yast_mock.rb | 43 ++++++++++++++++++++++++++++++
webclient/test/unit/yast_model_test.rb | 45 ++++++-------------------------
2 files changed, 52 insertions(+), 36 deletions(-)
diff --git a/webclient/lib/yast_mock.rb b/webclient/lib/yast_mock.rb
new file mode 100644
index 0000000..dac860b
--- /dev/null
+++ b/webclient/lib/yast_mock.rb
@@ -0,0 +1,43 @@
+require 'active_resource/http_mock'
+module ActiveResource
+ class HttpMock
+ class << self
+ def set_authentification
+ YaST::ServiceResource::Session.site = "http://localhost"
+ YaST::ServiceResource::Session.login = "test"
+ YaST::ServiceResource::Session.auth_token = "1234"
+ end
+
+ def authentification_header
+ {"Authorization"=>"Basic OjEyMzQ="}
+ end
+ end
+
+ class Responder
+ def resources(routes,opts={})
+ response = ""
+ routes.each do |interface,path|
+ response << "<resource><interface>#{interface}</interface><href>#{path}</href>"
+ response << (opts[:policy] ? "<policy>#{opts[:policy]}</policy>" : "<policy/>")
+ response << ("" + (opts[:policy].nil? ? "true" : opts[:policy].to_s) + "</singular>")
+ response << "</resource>\n"
+ end
+ response << "</resources>"
+ get "/resources.xml", {}, response, 200
+ end
+
+ def permissions(prefix,perm,opts={})
+ response = ""
+ perm.each do |perm,granted|
+ response << "<permission>"
+ response << "#{granted.to_s}</granted>"
+ response << "<id>#{prefix}.#{perm.to_s}</id>"
+ response << "</permission>"
+ end
+ response << "</permissions>"
+ get "/permissions.xml?filter=#{prefix}&user_id=test", HttpMock.authentification_header, response, 200
+ end
+ end
+
+ end
+end
diff --git a/webclient/test/unit/yast_model_test.rb b/webclient/test/unit/yast_model_test.rb
index c3205ae..321e31d 100644
--- a/webclient/test/unit/yast_model_test.rb
+++ b/webclient/test/unit/yast_model_test.rb
@@ -1,34 +1,8 @@
require File.dirname(__FILE__) + '/../test_helper'
-require 'active_resource/http_mock'
+require 'yast_mock'
class YastModelTest < ActiveSupport::TestCase
-PERMISSION_RESPONSE= <"Basic OjEyMzQ="}, PERMISSION_RESPONSE,200
- mock.get "/test.xml", {"Authorization"=>"Basic OjEyMzQ="}, TEST_RESPONSE, 200
- mock.post "/test.xml", {"Authorization"=>"Basic OjEyMzQ="}, TEST_RESPONSE, 200
- mock.get "/test2.xml", {"Authorization"=>"Basic OjEyMzQ="}, TEST2_RESPONSE, 200
- mock.post "/test2.xml", {"Authorization"=>"Basic OjEyMzQ="}, TEST2_RESPONSE, 200
+ header = ActiveResource::HttpMock.authentification_header
+ mock.resources :'org.opensuse.yast.modules.test' => "/test", :'org.opensuse.yast.modules.test2' => "/test2"
+ mock.permissions "org.opensuse.yast.modules.test", { :synchronize => true }
+ mock.get "/test.xml", header, TEST_RESPONSE, 200
+ mock.post "/test.xml", header, TEST_RESPONSE, 200
+ mock.get "/test2.xml", header, TEST2_RESPONSE, 200
+ mock.post "/test2.xml", header, TEST2_RESPONSE, 200
end
- YaST::ServiceResource::Session.site = "http://localhost"
- YaST::ServiceResource::Session.login = "test"
- YaST::ServiceResource::Session.auth_token = "1234"
end
class TestModel < ActiveResource::Base
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org