users/groups: build again from ground up, work in progress
[opensuse:yast-web-client.git] / plugins / users / test / unit / groups_test.rb
1 require File.join(File.dirname(__FILE__),'..','test_helper')
2 require File.expand_path( File.join("test","validation_assert"), RailsParent.parent )
3 require 'mocha'
4 require 'yast_mock'
5 class UsersControllerTest < ActiveSupport::TestCase
6   # return contents of a fixture file +file+
7   def fixture(file)
8     IO.read(File.join(File.dirname(__FILE__), "..", "fixtures", file))
9   end
10
11   def setup
12     # stub what the REST is supposed to return
13     response_g_users = fixture "groups/users.xml"
14     response_groups = fixture "groups/groups.xml"
15
16     ActiveResource::HttpMock.set_authentication
17     ActiveResource::HttpMock.respond_to do |mock|
18       header = ActiveResource::HttpMock.authentication_header
19       # this is inadequate, :singular is per resource,
20       # and does NOT depend on :policy
21       # see yast-rest-service/plugins/network/config/resources/*
22       mock.resources({:"org.opensuse.yast.modules.yapi.groups" => "/groups"},
23           { :policy => "org.opensuse.yast.modules.yapi.groups"})
24       mock.permissions "org.opensuse.yast.modules.yapi.groups", { :read => true, :write => true }
25       mock.get  "/groups/users.xml", header, response_g_users, 200
26       mock.get  "/groups/.xml", header, response_groups, 200
27     end
28   end
29
30   def teardown
31     ActiveResource::HttpMock.reset!
32   end
33
34   def test_find_all
35     res = Group.find :all
36     assert res
37     assert_instance_of(Array, res)
38   end
39
40   def test_find_tester
41     res = Group.find :users
42     assert res
43   end
44 end