Пример #1
0
    def test_minimal_role_binding_parameters_groups(self, mocker):
        sync_mock = mocker.patch.object(utils, 'sync')
        sync_mock.return_value = True, {}
        set_module_args(
            name='test_role_binding',
            role='test_role',
            groups=['test_group'],
        )

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

        state, _client, path, payload, check_mode, _compare = sync_mock.call_args[
            0]
        assert state == 'present'
        assert path == '/api/core/v2/namespaces/default/rolebindings/test_role_binding'
        assert payload == dict(
            role_ref=dict(
                name='test_role',
                type='Role',
            ),
            subjects=[
                dict(
                    name='test_group',
                    type='Group',
                ),
            ],
            metadata=dict(
                name='test_role_binding',
                namespace='default',
            ),
        )
        assert check_mode is False
Пример #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_role_binding',
            role='test_role',
        )

        with pytest.raises(AnsibleFailJson):
            role_binding.main()
Пример #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_role_binding',
         role='test_role',
         users=['test_user'],
     )
     with pytest.raises(AnsibleFailJson):
         role_binding.main()