foreman_datacenter 1.24.0 → 1.24.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/lib/foreman_datacenter/version.rb +1 -1
  3. data/test/controllers/foreman_datacenter/device_roles_controller_test.rb +133 -0
  4. data/test/controllers/foreman_datacenter/device_types_contoller_test.rb +108 -47
  5. data/test/controllers/foreman_datacenter/devices_controller_test.rb +132 -0
  6. data/test/controllers/foreman_datacenter/manufacturers_controller_test.rb +133 -0
  7. data/test/controllers/foreman_datacenter/platforms_contoller_test.rb +91 -48
  8. data/test/controllers/foreman_datacenter/rack_groups_contoller_test.rb +90 -43
  9. data/test/controllers/foreman_datacenter/racks_contoller_test.rb +111 -42
  10. data/test/controllers/foreman_datacenter/sites_contoller_test.rb +108 -81
  11. data/test/datacenter_helper.rb +8 -1
  12. data/test/factories/device.rb +5 -0
  13. data/test/factories/device_role.rb +6 -0
  14. data/test/factories/device_type.rb +30 -0
  15. data/test/factories/rack_group.rb +13 -14
  16. data/test/fixtures/foreman_datacenter/device_roles.yml +0 -1
  17. data/test/integration/foreman_datacenter/device_role_test.rb +35 -0
  18. data/test/integration/foreman_datacenter/device_type_test.rb +33 -0
  19. data/test/integration/foreman_datacenter/manufacturer_test.rb +33 -0
  20. data/test/integration/foreman_datacenter/platform_test.rb +35 -0
  21. data/test/integration/foreman_datacenter/rack_group_test.rb +35 -25
  22. data/test/integration/foreman_datacenter/rack_test.rb +37 -25
  23. data/test/integration/foreman_datacenter/site_test.rb +39 -29
  24. data/test/unit/foreman_datacenter_test.rb +1 -1
  25. metadata +53 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b31588dc6a151742a438a98274b00ee81f4a3c8143908585f5e370a23a415548
4
- data.tar.gz: cd83b79baba8e169481b049df1c1d691da1fa1d9d2bac8d42742578deaf58f24
3
+ metadata.gz: d92338ad9dbcbb8535e563a11151dc94e5f0cf0e4ca2b67aaa80cc025bf553e5
4
+ data.tar.gz: 0a26582a81e88b47f3205cfe9ab278cfc7e809a864d4e1f9b4cf73ce6ccb0a82
5
5
  SHA512:
6
- metadata.gz: ae8cd3fffb336f93af36419e7a8ebf7e43e8f067da22e9a0492ca89b463cf3e0dde558808d028534dc145bb2e1be7d05a6ae2cf6519f1b13188dd016fa7b9479
7
- data.tar.gz: 3343207b606cf6d557bf2a16816b7b3f701a665bd688ffe8dd4593eb23cfdeee7306118ce84fd5f64843cd3fb3b69d1fc614045c85095a609fecb6d60aa2acd0
6
+ metadata.gz: 829d263770d9b13f7f31ac94142e53654036eb7499debac6855e3287215d7afc389e62de47c0fe97fcc1cfd881e185887d1d765f66b62d666f9a46a32d5dcbf3
7
+ data.tar.gz: 0e76d5be4b412cd6f3df9890ef45d36a5465f7b7f1ad55b1c07b2472670d5ef414e176af5f8133e311f491675a1540de09cd70da8e0ed47b4f67b14e9bfb781f
@@ -1,3 +1,3 @@
1
1
  module ForemanDatacenter
2
- VERSION = '1.24.0'.freeze
2
+ VERSION = '1.24.1'.freeze
3
3
  end
@@ -0,0 +1,133 @@
1
+ require_relative '../../test_plugin_helper'
2
+
3
+ module ForemanDatacenter
4
+ class DeviceRolesControllerTest < ActionController::TestCase
5
+ describe ForemanDatacenter::DeviceRolesController do
6
+ setup do
7
+ @model = ForemanDatacenter::DeviceRole.first
8
+ end
9
+
10
+ basic_index_test 'device_roles'
11
+ basic_new_test
12
+ basic_edit_test 'device_role'
13
+ basic_pagination_per_page_test
14
+ basic_pagination_rendered_test
15
+
16
+ def test_create_invalid
17
+ ForemanDatacenter::DeviceRole.any_instance.stubs(:valid?).returns(false)
18
+ post :create, params: { :device_role => {:name => nil} }, session: set_session_user
19
+ assert_template 'new'
20
+ end
21
+
22
+ def test_create_valid(name = "test device_role")
23
+ ForemanDatacenter::DeviceRole.any_instance.stubs(:valid?).returns(true)
24
+ post :create, params: { :device_role => {:name => name, :color => 'Teal'} }, session: set_session_user
25
+ assert_redirected_to device_roles_url
26
+ end
27
+
28
+ def test_update_invalid
29
+ ForemanDatacenter::DeviceRole.any_instance.stubs(:valid?).returns(false)
30
+ put :update, params: { :id => @model.to_param, :device_role => {:name => "3243", :color => "Red"} }, session: set_session_user
31
+ assert_template 'edit'
32
+ end
33
+
34
+ def test_update_valid
35
+ ForemanDatacenter::DeviceRole.any_instance.stubs(:valid?).returns(true)
36
+ put :update, params: { :id => @model.to_param, :device_role => {:name => @model.name, :color => "Green"} }, session: set_session_user
37
+ assert_redirected_to device_roles_url
38
+ end
39
+
40
+ def test_destroy
41
+ test_create_valid "tobedeleted_test"
42
+ @new_dr = ForemanDatacenter::DeviceRole.find_by_name("tobedeleted_test")
43
+ delete :destroy, params: { :id => @new_dr.id }, session: set_session_user
44
+ assert_redirected_to device_roles_url
45
+ assert !ForemanDatacenter::DeviceRole.exists?(@new_dr.id)
46
+ end
47
+
48
+ test "should not get index when not permitted" do
49
+ setup_user
50
+ get :index, session: { :user => users(:one).id, :expires_at => 5.minutes.from_now }
51
+ assert_response :forbidden
52
+ assert_includes @response.body, 'view_device_roles'
53
+ end
54
+
55
+ test 'should not get show when not permitted' do
56
+ setup_user
57
+ get :show, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
58
+ assert_response :forbidden
59
+ assert_includes @response.body, 'view_device_roles'
60
+ end
61
+
62
+ test 'should not get edit when not permitted' do
63
+ setup_user
64
+ get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
65
+ assert_response :forbidden
66
+ assert_includes @response.body, 'edit_device_roles'
67
+ end
68
+
69
+ test "should get index" do
70
+ setup_user("Viewer")
71
+ get :index, session: set_session_user
72
+ assert_response :success
73
+ assert_template 'index'
74
+ end
75
+
76
+ test 'should get show' do
77
+ setup_user("Viewer")
78
+ get :show, params: { :id => @model.id }, session: set_session_user
79
+ assert_response :success
80
+ assert_template 'show'
81
+ end
82
+
83
+ test 'should not get edit with viewer permissions' do
84
+ setup_user("Viewer")
85
+ get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
86
+ assert_response :forbidden
87
+ assert_includes @response.body, 'edit_device_roles'
88
+ end
89
+
90
+ test 'should get edit' do
91
+ get :edit, params: { :id => @model.id }, session: set_session_user
92
+ assert_response :success
93
+ assert_template 'edit'
94
+ end
95
+
96
+ def setup_user(role = "")
97
+ @request.session[:user] = users(:one).id
98
+ users(:one).roles = [Role.default]
99
+ users(:one).roles << Role.find_by_name(role) if role != ""
100
+ # users(:one).roles = [Role.default, Role.find_by_name("Viewer")]
101
+ end
102
+
103
+ test "should_render_404_when_device_role_is_not_found" do
104
+ get :show, params: { id: 'no.such.device.role' }, session: set_session_user
105
+ assert_response :not_found
106
+ assert_template 'common/404'
107
+ end
108
+
109
+ test "should_not_destroy_device_role_when_not_permitted" do
110
+ setup_user
111
+ assert_difference('ForemanDatacenter::DeviceRole.count', 0) do
112
+ delete :destroy, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
113
+ end
114
+ assert_response :forbidden
115
+ end
116
+
117
+ test "should search by name" do
118
+ get :index, params: {:search => "name=\"device_role_1\""}, session: set_session_user
119
+ assert_response :success
120
+ refute_empty assigns(:device_roles)
121
+ assert assigns(:device_roles).include?(device_roles(:one))
122
+ end
123
+
124
+ test "should search by color" do
125
+ get :index, params: {:search => "color=\"Teal\""}, session: set_session_user
126
+ assert_response :success
127
+ refute_empty assigns(:device_roles)
128
+ assert assigns(:device_roles).include?(device_roles(:one))
129
+ end
130
+
131
+ end
132
+ end
133
+ end
@@ -13,78 +13,139 @@ module ForemanDatacenter
13
13
  basic_pagination_per_page_test
14
14
  basic_pagination_rendered_test
15
15
 
16
- def test_new_submit_button_id
17
- get :new, session: set_session_user
18
- assert_select "[data-id='aid_datacenter_device_types']"
19
- end
16
+ def test_create_invalid
17
+ ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(false)
18
+ post :create, params: { device_type: { model: nil } }, session: set_session_user
19
+ assert_template 'new'
20
+ end
20
21
 
21
- def test_new_cancel_button_id
22
- get :new, session: set_session_user
23
- assert_select "[data-id='aid_datacenter_device_types']"
24
- end
25
-
26
- def test_show_edit_button_id
27
- get :show, params: { :id => ForemanDatacenter::DeviceType.first.to_param }, session: set_session_user
28
- assert_select "[data-id='aid_device_types_#{ForemanDatacenter::DeviceType.first.id}_edit']"
22
+ def test_create_valid(model = "test device_type")
23
+ ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(true)
24
+ post :create, params: { device_type: { model: model, manufacturer_id: 1 } }, session: set_session_user
25
+ assert_redirected_to device_types_url
29
26
  end
30
27
 
31
- def test_show_delete_button_id
32
- get :show, params: { :id => ForemanDatacenter::DeviceType.first.to_param }, session: set_session_user
33
- assert_select "[data-id='aid_datacenter_device_types_#{ForemanDatacenter::DeviceType.first.id}']"
28
+ def test_update_invalid
29
+ ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(false)
30
+ put :update, params: { id: @model.to_param, device_type: { model: '3243', color: 'Red' } }, session: set_session_user
31
+ assert_template 'edit'
34
32
  end
35
33
 
36
- test "should_show_device_type" do
37
- setup_user
38
- get :show, params: { :id => ForemanDatacenter::DeviceType.first.to_param }, session: set_session_user
39
- assert_response :success
34
+ def test_update_valid
35
+ ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(true)
36
+ put :update, params: { id: @model.to_param, device_type: { model: @model.model, color: 'Green' } }, session: set_session_user
37
+ assert_redirected_to device_types_url
40
38
  end
41
39
 
42
40
  def test_create_invalid
43
41
  ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(false)
44
- post :create, params: { :device_type => {:model => nil} }, session: set_session_user
42
+ post :create, params: { device_type: { model: nil } }, session: set_session_user
45
43
  assert_template 'new'
46
44
  end
47
45
 
48
- def test_create_valid
49
- ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(true)
50
- post :create, params: { :device_type => {:model => 'test model'} }, session: set_session_user
51
- # assert_redirected_to device_types_url
52
- # assert_redirected_to device_type_url(ForemanDatacenter::DeviceType.first)
46
+ def test_destroy
47
+ test_create_valid "tobedeleted_test"
48
+ @new_dt = ForemanDatacenter::DeviceType.find_by_model("tobedeleted_test")
49
+ delete :destroy, params: { id: @new_dt.id }, session: set_session_user
50
+ assert_redirected_to device_types_url
51
+ assert !ForemanDatacenter::DeviceType.exists?(@new_dt.id)
53
52
  end
54
53
 
55
- def test_edit_submit_button_id
56
- get :edit, params: { :id => ForemanDatacenter::DeviceType.first }, session: set_session_user
57
- assert_select "[data-id='aid_update_foreman_datacenter_device_type']"
54
+ test "should not get index when not permitted" do
55
+ setup_user
56
+ get :index, session: { :user => users(:one).id, :expires_at => 5.minutes.from_now }
57
+ assert_response :forbidden
58
+ assert_includes @response.body, 'view_device_types'
58
59
  end
59
60
 
60
- def test_update_invalid
61
- ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(false)
62
- put :update, params: { :id => ForemanDatacenter::DeviceType.first.to_param, :device_type => {:model => "3243"} }, session: set_session_user
63
- assert_template 'edit'
61
+ test 'should not get show when not permitted' do
62
+ setup_user
63
+ get :show, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
64
+ assert_response :forbidden
65
+ assert_includes @response.body, 'view_device_types'
64
66
  end
65
67
 
66
- def test_update_valid
67
- ForemanDatacenter::DeviceType.any_instance.stubs(:valid?).returns(true)
68
- put :update, params: { :id => ForemanDatacenter::DeviceType.first.to_param, :device_type => {:model => ForemanDatacenter::DeviceType.first.model} }, session: set_session_user
69
- # assert_redirected_to device_type_url(ForemanDatacenter::DeviceType.first)
68
+ test 'should not get edit when not permitted' do
69
+ setup_user
70
+ get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
71
+ assert_response :forbidden
72
+ assert_includes @response.body, 'edit_device_types'
70
73
  end
71
74
 
72
- def test_destroy
73
- device_type = ForemanDatacenter::DeviceType.first
74
- # architecture.hosts.delete_all
75
- # architecture.hostgroups.delete_all
76
- delete :destroy, params: { :id => device_type.id }, session: set_session_user
77
- assert_redirected_to device_types_url
78
- assert !ForemanDatacenter::DeviceType.exists?(device_type.id)
75
+ test "should get index" do
76
+ setup_user("Viewer")
77
+ get :index, session: set_session_user
78
+ assert_response :success
79
+ assert_template 'index'
80
+ end
81
+
82
+ test 'should get show' do
83
+ setup_user("Viewer")
84
+ get :show, params: { :id => @model.id }, session: set_session_user
85
+ assert_response :success
86
+ assert_template 'show'
87
+ end
88
+
89
+ test 'should not get edit with viewer permissions' do
90
+ setup_user("Viewer")
91
+ get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
92
+ assert_response :forbidden
93
+ assert_includes @response.body, 'edit_device_types'
79
94
  end
80
95
 
81
- def setup_user
96
+ test 'should get edit' do
97
+ get :edit, params: { :id => @model.id }, session: set_session_user
98
+ assert_response :success
99
+ assert_template 'edit'
100
+ end
101
+
102
+ def setup_user(role = "")
82
103
  @request.session[:user] = users(:one).id
83
- users(:one).roles = [Role.default, Role.find_by_name('Viewer')]
104
+ users(:one).roles = [Role.default]
105
+ users(:one).roles << Role.find_by_name(role) if role != ""
106
+ # users(:one).roles = [Role.default, Role.find_by_name("Viewer")]
107
+ end
108
+
109
+ test "should_render_404_when_device_type_is_not_found" do
110
+ get :show, params: { id: 'no.such.device.type' }, session: set_session_user
111
+ assert_response :not_found
112
+ assert_template 'common/404'
84
113
  end
85
114
 
86
- def get_factory_name
87
- :device_type
115
+ test "should_not_destroy_device_type_when_not_permitted" do
116
+ setup_user
117
+ assert_difference('ForemanDatacenter::DeviceType.count', 0) do
118
+ delete :destroy, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
119
+ end
120
+ assert_response :forbidden
121
+ end
122
+
123
+ test "should search by model" do
124
+ get :index, params: {:search => "model=\"DeviceType_1NONE\""}, session: set_session_user
125
+ assert_response :success
126
+ refute_empty assigns(:device_types)
127
+ assert assigns(:device_types).include?(device_types(:one))
128
+ end
129
+
130
+ test "should search by manufacturer" do
131
+ get :index, params: {:search => "manufacturer=\"manufacturer_1\""}, session: set_session_user
132
+ assert_response :success
133
+ refute_empty assigns(:device_types)
134
+ assert assigns(:device_types).include?(device_types(:one))
135
+ end
136
+
137
+ test "should search by subdevice role" do
138
+ get :index, params: {:search => "subdevice_role=\"None\""}, session: set_session_user
139
+ assert_response :success
140
+ refute_empty assigns(:device_types)
141
+ assert assigns(:device_types).include?(device_types(:one))
142
+ end
143
+
144
+ test "should search by U height" do
145
+ get :index, params: {:search => "u_height=\"1\""}, session: set_session_user
146
+ assert_response :success
147
+ refute_empty assigns(:device_types)
148
+ assert assigns(:device_types).include?(device_types(:one))
88
149
  end
89
150
  end
90
151
  end
@@ -0,0 +1,132 @@
1
+ require_relative '../../test_plugin_helper'
2
+
3
+ module ForemanDatacenter
4
+ class DevicesControllerTest < ActionController::TestCase
5
+ describe ForemanDatacenter::DevicesController do
6
+ setup do
7
+ @model = ForemanDatacenter::Device.first
8
+ end
9
+
10
+ basic_index_test 'devices'
11
+ basic_new_test
12
+ basic_edit_test 'device'
13
+ basic_pagination_per_page_test
14
+ basic_pagination_rendered_test
15
+
16
+ # def test_create_invalid
17
+ # ForemanDatacenter::Device.any_instance.stubs(:valid?).returns(false)
18
+ # post :create, params: { device: { name: nil } }, session: set_session_user
19
+ # assert_template 'new'
20
+ # end
21
+
22
+ # def test_create_valid(name = "test rg")
23
+ # ForemanDatacenter::Device.any_instance.stubs(:valid?).returns(true)
24
+ # post :create, params: { device: { name: name } }, session: set_session_user
25
+ # assert_redirected_to devices_url
26
+ # end
27
+
28
+ # def test_update_invalid
29
+ # ForemanDatacenter::Device.any_instance.stubs(:valid?).returns(false)
30
+ # put :update, params: { id: @model.to_param, device: { name: '3243' } }, session: set_session_user
31
+ # assert_template 'edit'
32
+ # end
33
+
34
+ # def test_update_valid
35
+ # ForemanDatacenter::Device.any_instance.stubs(:valid?).returns(true)
36
+ # put :update, params: { id: @model.to_param, device: { name: @model.name } }, session: set_session_user
37
+ # assert_redirected_to devices_url
38
+ # end
39
+
40
+ # def test_destroy
41
+ # test_create_valid "tobedeleted_test"
42
+ # @new_rg = ForemanDatacenter::Device.find_by_name("tobedeleted_test")
43
+ # delete :destroy, params: { id: @new_rg.id }, session: set_session_user
44
+ # assert_redirected_to devices_url
45
+ # assert !ForemanDatacenter::Device.exists?(@new_rg.id)
46
+ # end
47
+
48
+ # test "should not get index when not permitted" do
49
+ # setup_user
50
+ # get :index, session: { :user => users(:one).id, :expires_at => 5.minutes.from_now }
51
+ # assert_response :forbidden
52
+ # assert_includes @response.body, 'view_devices'
53
+ # end
54
+
55
+ # test 'should not get show when not permitted' do
56
+ # setup_user
57
+ # get :show, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
58
+ # assert_response :forbidden
59
+ # assert_includes @response.body, 'view_devices'
60
+ # end
61
+
62
+ # test 'should not get edit when not permitted' do
63
+ # setup_user
64
+ # get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
65
+ # assert_response :forbidden
66
+ # assert_includes @response.body, 'edit_devices'
67
+ # end
68
+
69
+ # test "should get index" do
70
+ # setup_user("Viewer")
71
+ # get :index, session: set_session_user
72
+ # assert_response :success
73
+ # assert_template 'index'
74
+ # end
75
+
76
+ # test 'should get show' do
77
+ # setup_user("Viewer")
78
+ # get :show, params: { :id => @model.id }, session: set_session_user
79
+ # assert_response :success
80
+ # assert_template 'show'
81
+ # end
82
+
83
+ # test 'should not get edit with viewer permissions' do
84
+ # setup_user("Viewer")
85
+ # get :edit, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
86
+ # assert_response :forbidden
87
+ # assert_includes @response.body, 'edit_devices'
88
+ # end
89
+
90
+ # test 'should get edit' do
91
+ # get :edit, params: { :id => @model.id }, session: set_session_user
92
+ # assert_response :success
93
+ # assert_template 'edit'
94
+ # end
95
+
96
+ # def setup_user(role = "")
97
+ # @request.session[:user] = users(:one).id
98
+ # users(:one).roles = [Role.default]
99
+ # users(:one).roles << Role.find_by_name(role) if role != ""
100
+ # # users(:one).roles = [Role.default, Role.find_by_name("Viewer")]
101
+ # end
102
+
103
+ # test "should_render_404_when_rack_is_not_found" do
104
+ # get :show, params: { id: 'no.such.rack.group' }, session: set_session_user
105
+ # assert_response :not_found
106
+ # assert_template 'common/404'
107
+ # end
108
+
109
+ # test "should_not_destroy_device_when_not_permitted" do
110
+ # setup_user
111
+ # assert_difference('ForemanDatacenter::Device.count', 0) do
112
+ # delete :destroy, params: { :id => @model.id }, session: {:user => users(:one).id, :expires_at => 5.minutes.from_now}
113
+ # end
114
+ # assert_response :forbidden
115
+ # end
116
+
117
+ # test "should search by name" do
118
+ # get :index, params: {:search => "name=\"device_1\""}, session: set_session_user
119
+ # assert_response :success
120
+ # refute_empty assigns(:devices)
121
+ # assert assigns(:devices).include?(devices(:one))
122
+ # end
123
+
124
+ # test "should search by site" do
125
+ # get :index, params: {:search => "site=\"site_1\""}, session: set_session_user
126
+ # assert_response :success
127
+ # refute_empty assigns(:devices)
128
+ # assert assigns(:devices).include?(devices(:one))
129
+ # end
130
+ end
131
+ end
132
+ end