Debian Codegraph @

ansible_collections/community/clickhouse/tests/unit/plugins/modules/test_clickhouse_client.py

raw
1 from __future__ import (absolute_import, division, print_function)
2
3 __metaclass__ = type
4
5 import pytest
6 from uuid import UUID
7 from decimal import Decimal
8 from ipaddress import IPv4Address, IPv6Address
9
10
11 from ansible_collections.community.clickhouse.plugins.modules.clickhouse_client import (
12 is_uuid,
13 vals_to_supported,
14 replace_val_in_tuple,
15 )
16
17
18 @pytest.mark.parametrize(
19 'input_params,result',
20 [
21 ('e66c72d8-fbd2-c174-0df3-7cbfd0c3d635', True),
22 ('qwerty123', False),
23 ('meaningless text', False),
24 ('d1659f3e-83fe-3845-f1be-5fada6046b67', True),
25 ]
26 )
27 def test_is_uuid(input_params, result):
28 # Testing the function is_uuid
29 assert is_uuid(input_params) == result
30
31
32 @pytest.mark.parametrize(
33 'input_params,result',
34 [
35 (((1, 2, 3, 4), 3, 5),
36 (1, 2, 3, 5)
37 ),
38 (((1, 2, 3, 4), 2, 5),
39 (1, 2, 5, 4)
40 ),
41 (((1, 2, 3, 4), 1, 5),
42 (1, 5, 3, 4)
43 ),
44 (((1, 2), 0, 5),
45 (5, 2)
46 ),
47 ]
48 )
49 def test_replace_val_in_tuple(input_params, result):
50 # Testing the function replace_val_in_tuple
51 assert replace_val_in_tuple(*input_params) == result
52
53
54 @pytest.mark.parametrize(
55 'input_params,result',
56 [
57 ([
58 ('default', UUID('e66c72d8-fbd2-c174-0df3-7cbfd0c3d635')),
59 ('test', UUID('4bfbe653-9137-0ea6-b97d-dc391ec9a919')),
60 ], [
61 ('default', 'e66c72d8-fbd2-c174-0df3-7cbfd0c3d635'),
62 ('test', '4bfbe653-9137-0ea6-b97d-dc391ec9a919'),
63 ],),
64 ([
65 ('localhost', IPv4Address('127.0.0.1')),
66 ('non_routable', IPv4Address('0.0.0.0')),
67 ], [
68 ('localhost', '127.0.0.1'),
69 ('non_routable', '0.0.0.0'),
70 ],),
71 ([
72 ('localhost', IPv6Address('::1')),
73 ('non_routable', IPv6Address('::')),
74 ], [
75 ('localhost', '::1'),
76 ('non_routable', '::'),
77 ],),
78 ([
79 ('pi', Decimal('3.14159')),
80 ('e', Decimal('2.71828')),
81 ], [
82 ('pi', 3.14159),
83 ('e', 2.71828),
84 ],),
85 ]
86 )
87 def test_vals_to_supported(input_params, result):
88 # Testing the function vals_to_supported
89 assert vals_to_supported(input_params) == result