def test_minimal_asset_parameters(self, mocker):
        sync_mock = mocker.patch.object(utils, "sync")
        sync_mock.return_value = True, {}
        set_module_args(name="test_asset",
                        builds=[
                            dict(
                                url="http://example.com/asset.tar.gz",
                                sha512="sha512String",
                            ),
                        ])

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

        state, _client, path, payload, check_mode, _do_differ = sync_mock.call_args[
            0]
        assert state == "present"
        assert path == "/api/core/v2/namespaces/default/assets/test_asset"
        assert payload == dict(
            builds=[
                dict(
                    url="http://example.com/asset.tar.gz",
                    sha512="sha512String",
                ),
            ],
            metadata=dict(
                name="test_asset",
                namespace="default",
            ),
        )
        assert check_mode is False
Beispiel #2
0
    def test_all_asset_parameters(self, mocker):
        sync_mock = mocker.patch.object(utils, "sync")
        sync_mock.return_value = True, {}
        set_module_args(
            name="test_asset",
            state="absent",
            url="http://example.com/asset.tar.gz",
            sha512="sha512String",
            filters=["a", "b", "c"],
            headers={"header": "h"},
            labels={"region": "us-west-1"},
            annotations={"playbook": 12345},
        )

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

        state, _client, path, payload, check_mode = sync_mock.call_args[0]
        assert state == "absent"
        assert path == "/assets/test_asset"
        assert payload == dict(
            url="http://example.com/asset.tar.gz",
            sha512="sha512String",
            filters=["a", "b", "c"],
            headers={"header": "h"},
            metadata=dict(
                name="test_asset",
                namespace="default",
                labels={"region": "us-west-1"},
                annotations={"playbook": "12345"},
            ),
        )
        assert check_mode is False
    def test_failure_empty_builds(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_asset",
            builds=[],
        )

        with pytest.raises(AnsibleFailJson):
            asset.main()
Beispiel #4
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_asset",
            url="http://example.com/asset.tar.gz",
            sha512="sha512String",
        )

        with pytest.raises(AnsibleFailJson):
            asset.main()