diff options
author | Pierre Prinetti <pierreprinetti@users.noreply.github.com> | 2019-11-01 18:11:34 +0100 |
---|---|---|
committer | Sam Doran <sdoran@redhat.com> | 2019-11-01 13:11:34 -0400 |
commit | 2444fae2082befc33e82612c2187ad3a74e43f8c (patch) | |
tree | da2f0002fe93aeb26186d867e38662c9d435ed74 /test | |
parent | 7b7f15cb3a60a02a408dc94c20ba89909b58a862 (diff) | |
download | ansible-2444fae2082befc33e82612c2187ad3a74e43f8c.tar.gz |
Add a named parameter to the filter to_uuid (#64057)
Let the caller choose a namespace for `to_uuid` and document the
behaviour of both the default case, and the new explicit case.
This PR does not change the existing behaviour of the `to_uuid` UUIDv5
filter.
Diffstat (limited to 'test')
-rw-r--r-- | test/units/plugins/filter/test_uuid.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/units/plugins/filter/test_uuid.py b/test/units/plugins/filter/test_uuid.py new file mode 100644 index 0000000000..8a626d9a75 --- /dev/null +++ b/test/units/plugins/filter/test_uuid.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2019 Ansible Project +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +import pytest + +from ansible.module_utils._text import to_native +from ansible.plugins.filter.core import to_uuid +from ansible.errors import AnsibleFilterError + + +UUID_DEFAULT_NAMESPACE_TEST_CASES = ( + ('example.com', 'ae780c3a-a3ab-53c2-bfb4-098da300b3fe'), + ('test.example', '8e437a35-c7c5-50ea-867c-5c254848dbc2'), + ('café.example', '8a99d6b1-fb8f-5f78-af86-879768589f56'), +) + +UUID_TEST_CASES = ( + ('361E6D51-FAEC-444A-9079-341386DA8E2E', 'example.com', 'ae780c3a-a3ab-53c2-bfb4-098da300b3fe'), + ('361E6D51-FAEC-444A-9079-341386DA8E2E', 'test.example', '8e437a35-c7c5-50ea-867c-5c254848dbc2'), + ('11111111-2222-3333-4444-555555555555', 'example.com', 'e776faa5-5299-55dc-9057-7a00e6be2364'), +) + + +@pytest.mark.parametrize('value, expected', UUID_DEFAULT_NAMESPACE_TEST_CASES) +def test_to_uuid_default_namespace(value, expected): + assert expected == to_uuid(value) + + +@pytest.mark.parametrize('namespace, value, expected', UUID_TEST_CASES) +def test_to_uuid(namespace, value, expected): + assert expected == to_uuid(value, namespace=namespace) + + +def test_to_uuid_invalid_namespace(): + with pytest.raises(AnsibleFilterError) as e: + to_uuid('example.com', namespace='11111111-2222-3333-4444-555555555') + assert 'Invalid value' in to_native(e.value) |