Exemple #1
0
    def test_failure(self, mocker):
        get_mock = mocker.patch.object(utils, "get")
        get_mock.side_effect = errors.Error("Bad error")
        set_module_args(name="sample-role-binding")

        with pytest.raises(AnsibleFailJson):
            role_binding_info.main()
Exemple #2
0
    def test_missing_single_role_binding(self, mocker):
        get_mock = mocker.patch.object(utils, "get")
        get_mock.return_value = None
        set_module_args(name="sample-role-binding")

        with pytest.raises(AnsibleExitJson) as context:
            role_binding_info.main()

        assert context.value.args[0]["objects"] == []
Exemple #3
0
    def test_get_single_role_binding(self, mocker):
        get_mock = mocker.patch.object(utils, "get")
        get_mock.return_value = 1
        set_module_args(name="test-role-binding")

        with pytest.raises(AnsibleExitJson) as context:
            role_binding_info.main()

        _client, path = get_mock.call_args[0]
        assert path == "/api/core/v2/namespaces/default/rolebindings/test-role-binding"
        assert context.value.args[0]["objects"] == [1]
Exemple #4
0
    def test_get_all_role_bindings(self, mocker):
        get_mock = mocker.patch.object(utils, "get")
        get_mock.return_value = [1, 2, 3]
        set_module_args(namespace="my")

        with pytest.raises(AnsibleExitJson) as context:
            role_binding_info.main()

        _client, path = get_mock.call_args[0]
        assert path == "/api/core/v2/namespaces/my/rolebindings"
        assert context.value.args[0]["objects"] == [1, 2, 3]