Mailinglist Archive: yast-commit (883 mails)

< Previous Next >
[yast-commit] <rest-service> master : separate basic tests to webservice module
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Wed, 8 Jul 2009 15:36:48 +0200
  • Message-id: <E1MOnkB-0002PB-UQ@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 56c23c0e3bd62948bbe10bf6a9c50200d11755a8
Author: Josef Reidinger <jreidinger@xxxxxxx>
Date: Wed Jul 8 15:36:48 2009 +0200

separate basic tests to webservice module
---
plugins/language/app/models/language.rb | 2 +-
.../test/functional/language_controller_test.rb | 55 +-----------
webservice/lib/plugin_basic_tests.rb | 93 ++++++++++++++++++++
3 files changed, 99 insertions(+), 51 deletions(-)

diff --git a/plugins/language/app/models/language.rb
b/plugins/language/app/models/language.rb
index e97460c..f68fbb8 100644
--- a/plugins/language/app/models/language.rb
+++ b/plugins/language/app/models/language.rb
@@ -72,7 +72,7 @@ class Language
@@available.each do |k,v|
xml.language do
xml.tag!(:id, k)
- xml.tag!(:name, v[0])
+ xml.tag!(:name, v[0]) # [native UTF8, native ascii, UTF8
extension, english name]
end
end
end
diff --git a/plugins/language/test/functional/language_controller_test.rb
b/plugins/language/test/functional/language_controller_test.rb
index 5ba28a9..2bd3d81 100644
--- a/plugins/language/test/functional/language_controller_test.rb
+++ b/plugins/language/test/functional/language_controller_test.rb
@@ -2,49 +2,21 @@ require File.expand_path(File.dirname(__FILE__) +
"/../test_helper")
require 'test/unit'
require 'rubygems'
require 'mocha'
-
+require File.expand_path( File.join("lib","plugin_basic_tests"),
RailsParent.parent )

class LanguageControllerTest < ActionController::TestCase
fixtures :accounts
+
def setup
+ @model_class = Language
@controller = LanguageController.new
@request = ActionController::TestRequest.new
# http://railsforum.com/viewtopic.php?id=1719
@request.session[:account_id] = 1 # defined in fixtures
+ @data = Data
end

-
-
- def test_access_index
- #mock model to test only controller
- Language.any_instance.stubs(:read)
- get :show
- assert_response :success
- end
-
- def test_access_denied
- #mock model to test only controller
- Language.any_instance.stubs(:read)
- @controller.stubs(:permission_check).returns(false);
- get :show
- assert_response :forbidden
- end
-
- def test_access_show_xml
- Language.any_instance.stubs(:read)
- mime = Mime::XML
- @request.accept = mime.to_s
- get :show, :format => :xml
- assert_equal mime.to_s, @response.content_type
- end
-
- def test_access_show_json
- Language.any_instance.stubs(:read)
- mime = Mime::JSON
- @request.accept = mime.to_s
- get :show, :format => :json
- assert_equal mime.to_s, @response.content_type
- end
+ include PluginBasicTests

Data = {:language => {
:current => "cs_CZ",
@@ -72,21 +44,4 @@ class LanguageControllerTest < ActionController::TestCase
assert_equal lang.utf8, Data[:language][:utf8]
assert_equal lang.rootlocale, Data[:language][:rootlocale]
end
-
- def test_update_noparams
- Language.any_instance.stubs(:save)
- put :update
- assert_response :missing
- end
-
- def test_update_noperm
- #ensure that nothink is saved
- Language.any_instance.expects(:save).never
-
- @controller.stubs(:permission_check).returns(false);
-
- put :update, Data
-
- assert_response :forbidden
- end
end
diff --git a/webservice/lib/plugin_basic_tests.rb
b/webservice/lib/plugin_basic_tests.rb
new file mode 100644
index 0000000..1c071e6
--- /dev/null
+++ b/webservice/lib/plugin_basic_tests.rb
@@ -0,0 +1,93 @@
+# = PluginBasicTests module
+# The module is designed to perform few basic tests of webservice plugin
+# controller behavior. Its goal is provide same unify behavior to each
+# webservice plugin like unified response if user doesn't have permissions
+# or same content type.
+# == Prerequisites
+# The module expect some hints from controller test file for correct work.
+# It needs model class specified at @*model_class* field, controller instance
at
+# @*controller* and request specification at @*request* field. Field @*data* is
+# used to test update with valid data but without permissions.
+# Controller is expected to be thin layer and all dbus or system call is done
+# at model code. Controller use during reading only *read* motode of model
+# and during writing only *save* method.
+# == Example usage
+# This example show basic testing of controller of plugin
+# require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
+# require 'test/unit'
+# require 'rubygems'
+# require 'mocha'
+# require File.expand_path( File.join("lib","plugin_basic_tests"),
RailsParent.parent )
+#
+# class LanguageControllerTest < ActionController::TestCase
+# fixtures :accounts
+#
+# Test_data = {:language => {
+# :current => "cs_CZ",
+# :utf8 => "true",
+# :rootlocale => "false"
+# }}
+# def setup
+# @model = Language
+# @controller = LanguageController.new
+# @request = ActionController::TestRequest.new
+# # http://railsforum.com/viewtopic.php?id=1719
+# @request.session[:account_id] = 1 # defined in fixtures
+# @data = Test_data
+# end
+#
+# include PluginBasicTests
+# #another specific controller test like correct parsing arguments
+# #or specific exceptions
+# end
+
+module PluginBasicTests
+ def test_access_index
+ #mock model to test only controller
+ @model_class.any_instance.stubs(:read)
+ get :show
+ assert_response :success
+ end
+
+ def test_access_denied
+ #mock model to test only controller
+ @model_class.any_instance.stubs(:read)
+ @controller.stubs(:permission_check).returns(false);
+ get :show
+ assert_response :forbidden
+ end
+
+ def test_access_show_xml
+ @model_class.any_instance.stubs(:read)
+ mime = Mime::XML
+ @request.accept = mime.to_s
+ get :show, :format => :xml
+ assert_equal mime.to_s, @response.content_type
+ end
+
+ def test_access_show_json
+ @model_class.any_instance.stubs(:read)
+ mime = Mime::JSON
+ @request.accept = mime.to_s
+ get :show, :format => :json
+ assert_equal mime.to_s, @response.content_type
+ end
+
+ def test_update_noparams
+ @model_class.any_instance.stubs(:save)
+ put :update
+ assert_response :missing
+ end
+
+ def test_update_noperm
+ #ensure that nothink is saved
+ @model_class.any_instance.expects(:save).never
+
+ @controller.stubs(:permission_check).returns(false);
+
+ put :update, @data
+
+ assert_response :forbidden
+ end
+end
+
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages