コード例 #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-cluster-role")

        with pytest.raises(AnsibleFailJson):
            cluster_role_info.main()
コード例 #2
0
    def test_missing_single_cluster_role(self, mocker):
        get_mock = mocker.patch.object(utils, "get")
        get_mock.return_value = None
        set_module_args(name="sample-cluster-role")

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

        assert context.value.args[0]["objects"] == []
コード例 #3
0
    def test_get_single_cluster_role(self, mocker):
        get_mock = mocker.patch.object(utils, "get")
        get_mock.return_value = 1
        set_module_args(name="test-cluster-role")

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

        _client, path = get_mock.call_args[0]
        assert path == "/api/core/v2/clusterroles/test-cluster-role"
        assert context.value.args[0]["objects"] == [1]
コード例 #4
0
    def test_get_all_cluster_roles(self, mocker):
        get_mock = mocker.patch.object(utils, "get")
        get_mock.return_value = [1, 2, 3]
        set_module_args()

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

        _client, path = get_mock.call_args[0]
        assert path == "/clusterroles"
        assert context.value.args[0]["objects"] == [1, 2, 3]