Mailinglist Archive: yast-devel (152 mails)

< Previous Next >
[yast-devel] Rest-service and basic tests
  • From: Josef Reidinger <jreidinger@xxxxxxx>
  • Date: Tue, 07 Jul 2009 10:02:39 +0200
  • Message-id: <4A53011F.2090001@xxxxxxx>
Hi,
I write tests for time module after language module and find, that some
tests is same and maybe should be added automatic, to ensure that all
rest-service module act in basic situation same. Basic tests should be
if it return same MIME-type on calls, if they correctly handle no
permissions and if they act correctly on non-valid update data.
Do you have any idea how add that tests automatic to each module's
testsuite (and how automatic mockup model)?

my basic tests how it could look like:
def test_access_show
Systemtime.any_instance.stubs(:read)
get :show
assert_response :success
end

def test_access_denied
#mock model to test only controller
Systemtime.any_instance.stubs(:read)
@controller.stubs(:permission_check).returns(false);
get :show
assert_response :forbidden
end

def test_access_show_xml
Systemtime.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
Systemtime.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
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
--
Josef Reidinger
YaST team
maintainer of perl-Bootloader, YaST2-Repair, webyast modules language
and time


--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages