Debian Codegraph @

ansible_collections/community/general/tests/unit/plugins/module_utils/test__keycloak.py

raw
1 # Copyright (c) Ansible Project
2 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
3 # SPDX-License-Identifier: GPL-3.0-or-later
4
5 from __future__ import annotations
6
7 import unittest
8
9 from ansible_collections.community.general.plugins.module_utils._keycloak import is_struct_included
10
11
12 class KeycloakIsStructIncludedTestCase(unittest.TestCase):
13 dict1 = dict(
14 test1="test1", test2=dict(test1="test1", test2="test2"), test3=["test1", dict(test="test1", test2="test2")]
15 )
16 dict2 = dict(
17 test1="test1",
18 test2=dict(test1="test1", test2="test2", test3="test3"),
19 test3=["test1", dict(test="test1", test2="test2"), "test3"],
20 test4="test4",
21 )
22 dict3 = dict(
23 test1="test1",
24 test2=dict(test1="test1", test2="test23", test3="test3"),
25 test3=["test1", dict(test="test1", test2="test23"), "test3"],
26 test4="test4",
27 )
28
29 dict5 = dict(
30 test1="test1",
31 test2=dict(test1=True, test2="test23", test3="test3"),
32 test3=["test1", dict(test="test1", test2="test23"), "test3"],
33 test4="test4",
34 )
35
36 dict6 = dict(
37 test1="test1",
38 test2=dict(test1="true", test2="test23", test3="test3"),
39 test3=["test1", dict(test="test1", test2="test23"), "test3"],
40 test4="test4",
41 )
42 dict7 = [
43 {
44 "roles": ["view-clients", "view-identity-providers", "view-users", "query-realms", "manage-users"],
45 "clientid": "master-realm",
46 },
47 {"roles": ["manage-account", "view-profile", "manage-account-links"], "clientid": "account"},
48 ]
49 dict8 = [
50 {"roles": ["view-clients", "query-realms", "view-users"], "clientid": "master-realm"},
51 {"roles": ["manage-account-links", "view-profile", "manage-account"], "clientid": "account"},
52 ]
53
54 def test_trivial(self):
55 self.assertTrue(is_struct_included(self.dict1, self.dict1))
56
57 def test_equals_with_dict2_bigger_than_dict1(self):
58 self.assertTrue(is_struct_included(self.dict1, self.dict2))
59
60 def test_not_equals_with_dict2_bigger_than_dict1(self):
61 self.assertFalse(is_struct_included(self.dict2, self.dict1))
62
63 def test_not_equals_with_dict1_different_than_dict3(self):
64 self.assertFalse(is_struct_included(self.dict1, self.dict3))
65
66 def test_equals_with_dict5_contain_bool_and_dict6_contain_true_string(self):
67 self.assertFalse(is_struct_included(self.dict5, self.dict6))
68 self.assertFalse(is_struct_included(self.dict6, self.dict5))
69
70 def test_not_equals_dict7_dict8_compare_dict7_with_list_bigger_than_dict8_but_reverse_equals(self):
71 self.assertFalse(is_struct_included(self.dict7, self.dict8))
72 self.assertTrue(is_struct_included(self.dict8, self.dict7))