Beispiel #1
0
    def test_minimal_cluster_role_binding_parameters_groups(self, mocker):
        sync_mock = mocker.patch.object(utils, 'sync')
        sync_mock.return_value = True, {}
        set_module_args(
            name='test_cluster_role_binding',
            cluster_role='test_cluster_role',
            groups=['test_group'],
        )

        with pytest.raises(AnsibleExitJson):
            cluster_role_binding.main()

        state, _client, path, payload, check_mode, _compare = sync_mock.call_args[
            0]
        assert state == 'present'
        assert path == '/api/core/v2/clusterrolebindings/test_cluster_role_binding'
        assert payload == dict(
            role_ref=dict(
                name='test_cluster_role',
                type='ClusterRole',
            ),
            subjects=[
                dict(
                    name='test_group',
                    type='Group',
                ),
            ],
            metadata=dict(name='test_cluster_role_binding', ),
        )
        assert check_mode is False
Beispiel #2
0
    def test_failure_missing_groups_or_users(self, mocker):
        sync_mock = mocker.patch.object(utils, 'sync')
        sync_mock.side_effect = Exception("Validation should fail but didn't")
        set_module_args(
            name='test_cluster_role_binding',
            cluster_role='test_cluster_role',
        )

        with pytest.raises(AnsibleFailJson):
            cluster_role_binding.main()
Beispiel #3
0
 def test_failure(self, mocker):
     sync_mock = mocker.patch.object(utils, 'sync')
     sync_mock.side_effect = errors.Error('Bad error')
     set_module_args(
         name='test_cluster_role_binding',
         cluster_role='test_cluster_role',
         users=['test_user'],
     )
     with pytest.raises(AnsibleFailJson):
         cluster_role_binding.main()