[yast-devel] Implemented - rest-service and basic tests
Hi, short version: I implemented basic test in rest-service lib/plugin_basic_tests.rb and all it is fully documented by rdoc. long version: At first motivation why use this tests. At first this tests ensure that all modules react same on some general situation like no permission for action or send same mime type for xml and jason. At second it force better design for some modules which allow in future easier maintenance of that modules. Last but not least is that tests alone for my modules give 70% coverage (and I add only two lines of code to test). This tests require some prerequisites which is written in documentation. This prerequisites especially force usage controller as thin layer, that ensure only correct translation of parameters to model, behavior during exception and access restriction. Rest of functionality should be in model. As example of how controller and model should look is my modules time and language (both use this tests). As example how it should not look like (no offense, it is common problem, that controller contain almost every functionality) is patch module. I follow rails convention that for model filling is used find method and for storing is used save method. and getters/setters for attributes. I attach here text of documentation as rdoc task not working good for rest-service (you can generate it manually by rdoc lib/basic_plugin_tests.rb) [1]. I welcome any comments, questions and suggestions for another tests. Also some architect (Klaus, duncan) should look if expected behavior in test is what we really expect from module. [1]: 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. 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 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 end include PluginBasicTests #another specific controller test like correct parsing arguments #or specific exceptions end -- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast modules language and time -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
update: file is now located under test directory instead lib. documentation updated. Josef Reidinger wrote:
Hi, short version: I implemented basic test in rest-service lib/plugin_basic_tests.rb and all it is fully documented by rdoc. long version: At first motivation why use this tests. At first this tests ensure that all modules react same on some general situation like no permission for action or send same mime type for xml and jason. At second it force better design for some modules which allow in future easier maintenance of that modules. Last but not least is that tests alone for my modules give 70% coverage (and I add only two lines of code to test). This tests require some prerequisites which is written in documentation. This prerequisites especially force usage controller as thin layer, that ensure only correct translation of parameters to model, behavior during exception and access restriction. Rest of functionality should be in model. As example of how controller and model should look is my modules time and language (both use this tests). As example how it should not look like (no offense, it is common problem, that controller contain almost every functionality) is patch module. I follow rails convention that for model filling is used find method and for storing is used save method. and getters/setters for attributes.
I attach here text of documentation as rdoc task not working good for rest-service (you can generate it manually by rdoc lib/basic_plugin_tests.rb) [1].
I welcome any comments, questions and suggestions for another tests. Also some architect (Klaus, duncan) should look if expected behavior in test is what we really expect from module.
[1]:
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. 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
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 end
include PluginBasicTests #another specific controller test like correct parsing arguments #or specific exceptions end
-- Josef Reidinger YaST team maintainer of perl-Bootloader, YaST2-Repair, webyast modules language and time -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org
participants (1)
-
Josef Reidinger