ref: refs/heads/master
commit da7728d2cc698cddf87f7cca5f81b30adce4055e
Author: Klaus Kämpf
Date: Tue Jul 7 14:17:49 2009 +0200
Clean up permissions_controller_test output
---
webservice/lib/error_result.rb | 2 +-
.../test/functional/permissions_controller_test.rb | 96 ++++++++++++++++++++
webservice/test/functional/permissions_test.rb | 96 --------------------
3 files changed, 97 insertions(+), 97 deletions(-)
diff --git a/webservice/lib/error_result.rb b/webservice/lib/error_result.rb
index 72dfc2c..75a4cd1 100644
--- a/webservice/lib/error_result.rb
+++ b/webservice/lib/error_result.rb
@@ -6,7 +6,7 @@ class ErrorResult
# return parameters for 'render'
def self.error ( status = 400, code = 1, message = "Unspecific")
- $stderr.puts "Error #{code}:#{message}"
+ Rails.logger.error "Error #{code}:#{message}"
{ :partial => "layouts/error", :status => status, :locals => { :code => code, :message => message } }
end
diff --git a/webservice/test/functional/permissions_controller_test.rb b/webservice/test/functional/permissions_controller_test.rb
new file mode 100644
index 0000000..4e754e8
--- /dev/null
+++ b/webservice/test/functional/permissions_controller_test.rb
@@ -0,0 +1,96 @@
+#
+# Testing PermissionsController
+#
+
+require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+
+require 'test/unit'
+require 'rubygems'
+require "scr"
+require 'mocha'
+
+
+class PermissionsControllerTest < ActionController::TestCase
+ fixtures :accounts
+ def setup
+ @controller = PermissionsController.new
+ @request = ActionController::TestRequest.new
+ # http://railsforum.com/viewtopic.php?id=1719
+ @request.session[:account_id] = 1 # defined in fixtures
+ 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", "schubi", "--explicit"]).returns(:stderr=>"", :exit=>0, :stdout=>"org.opensuse.yast.system.users.read\norg.opensuse.yast.system.users.write\norg.opensuse.yast.system.users.new\n")
+ Scr.any_instance.stubs(:execute).with(['polkit-auth', '--user', 'schubi', '--grant', 'org.opensuse.yast.patch.install']).returns({:stderr=>"", :exit=>0, :stdout=>""})
+ end
+
+ test "access index" do
+ get :index, :user_id => "schubi"
+ assert_response :success
+ end
+
+ test "access index xml" do
+ mime = Mime::XML
+ @request.accept = mime.to_s
+ get :index, :user_id => "schubi", :format => :xml
+ assert_equal mime.to_s, @response.content_type
+ end
+
+ test "access index json" do
+ mime = Mime::JSON
+ @request.accept = mime.to_s
+ get :index, :user_id => "schubi", :format => :json
+ assert_equal mime.to_s, @response.content_type
+ end
+
+ test "access index without user" do
+ get :index
+ assert_response 404
+ end
+
+ test "access index with wrong user" do
+ Scr.any_instance.stubs(:execute).with(["polkit-auth", "--user", "not avail", "--explicit"]).returns({:stderr=>"polkit-auth: cannot look up uid for user 'not avail'\n", :exit=>1, :stdout=>""})
+ get :index, :user_id => "not avail"
+ assert_response 404
+ end
+
+ test "access show" do
+ get :show, :id => "org.opensuse.yast.system.users.read", :user_id => "schubi"
+ assert_response :success
+ end
+
+ test "access show without right" do
+ get :show, :user_id => "schubi"
+ assert_response 404
+ end
+
+ test "access show without user" do
+ get :show, :id => "org.opensuse.yast.system.users.read"
+ assert_response 404
+ end
+
+ test "access show without user AND right" do
+ get :show
+ assert_response 404
+ end
+
+ test "setting permissions" do
+ put :update, :permissions => {"name"=>"org.opensuse.yast.patch.install", "id"=>"schubi", "grant"=>true}, :id=>"schubi.xml"
+ assert_response :success
+ end
+
+ test "setting permissions without permissions" do
+ put :update, :id=>"schubi.xml"
+ assert_response 404
+ end
+
+ test "setting permissions without user" do
+ put :update, :permissions => {"name"=>"org.opensuse.yast.patch.install", "id"=>"schubi", "grant"=>true}
+ assert_response 404
+ end
+
+ test "setting permissions returns false from polkit-auth" do
+ Scr.any_instance.stubs(:execute).with(['polkit-auth', '--user', 'schubi', '--grant', 'org.opensuse.yast.patch.install']).returns({:stderr=>"error", :exit=>1, :stdout=>""})
+ put :update, :permissions => {"name"=>"org.opensuse.yast.patch.install", "id"=>"schubi", "grant"=>true}, :id=>"schubi.xml"
+ assert_response 404
+ end
+
+end
diff --git a/webservice/test/functional/permissions_test.rb b/webservice/test/functional/permissions_test.rb
deleted file mode 100644
index 4e754e8..0000000
--- a/webservice/test/functional/permissions_test.rb
+++ /dev/null
@@ -1,96 +0,0 @@
-#
-# Testing PermissionsController
-#
-
-require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
-
-require 'test/unit'
-require 'rubygems'
-require "scr"
-require 'mocha'
-
-
-class PermissionsControllerTest < ActionController::TestCase
- fixtures :accounts
- def setup
- @controller = PermissionsController.new
- @request = ActionController::TestRequest.new
- # http://railsforum.com/viewtopic.php?id=1719
- @request.session[:account_id] = 1 # defined in fixtures
- 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", "schubi", "--explicit"]).returns(:stderr=>"", :exit=>0, :stdout=>"org.opensuse.yast.system.users.read\norg.opensuse.yast.system.users.write\norg.opensuse.yast.system.users.new\n")
- Scr.any_instance.stubs(:execute).with(['polkit-auth', '--user', 'schubi', '--grant', 'org.opensuse.yast.patch.install']).returns({:stderr=>"", :exit=>0, :stdout=>""})
- end
-
- test "access index" do
- get :index, :user_id => "schubi"
- assert_response :success
- end
-
- test "access index xml" do
- mime = Mime::XML
- @request.accept = mime.to_s
- get :index, :user_id => "schubi", :format => :xml
- assert_equal mime.to_s, @response.content_type
- end
-
- test "access index json" do
- mime = Mime::JSON
- @request.accept = mime.to_s
- get :index, :user_id => "schubi", :format => :json
- assert_equal mime.to_s, @response.content_type
- end
-
- test "access index without user" do
- get :index
- assert_response 404
- end
-
- test "access index with wrong user" do
- Scr.any_instance.stubs(:execute).with(["polkit-auth", "--user", "not avail", "--explicit"]).returns({:stderr=>"polkit-auth: cannot look up uid for user 'not avail'\n", :exit=>1, :stdout=>""})
- get :index, :user_id => "not avail"
- assert_response 404
- end
-
- test "access show" do
- get :show, :id => "org.opensuse.yast.system.users.read", :user_id => "schubi"
- assert_response :success
- end
-
- test "access show without right" do
- get :show, :user_id => "schubi"
- assert_response 404
- end
-
- test "access show without user" do
- get :show, :id => "org.opensuse.yast.system.users.read"
- assert_response 404
- end
-
- test "access show without user AND right" do
- get :show
- assert_response 404
- end
-
- test "setting permissions" do
- put :update, :permissions => {"name"=>"org.opensuse.yast.patch.install", "id"=>"schubi", "grant"=>true}, :id=>"schubi.xml"
- assert_response :success
- end
-
- test "setting permissions without permissions" do
- put :update, :id=>"schubi.xml"
- assert_response 404
- end
-
- test "setting permissions without user" do
- put :update, :permissions => {"name"=>"org.opensuse.yast.patch.install", "id"=>"schubi", "grant"=>true}
- assert_response 404
- end
-
- test "setting permissions returns false from polkit-auth" do
- Scr.any_instance.stubs(:execute).with(['polkit-auth', '--user', 'schubi', '--grant', 'org.opensuse.yast.patch.install']).returns({:stderr=>"error", :exit=>1, :stdout=>""})
- put :update, :permissions => {"name"=>"org.opensuse.yast.patch.install", "id"=>"schubi", "grant"=>true}, :id=>"schubi.xml"
- assert_response 404
- end
-
-end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org