Debian Codegraph @

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

raw
1 # This code is part of Ansible, but is an independent component.
2 # This particular file snippet, and this file snippet only, is BSD licensed.
3 # Modules you write using this snippet, which is embedded dynamically by Ansible
4 # still belong to the author of the module, and may assign their own license
5 # to the complete work.
6 #
7 # Copyright (c) 2018, Johannes Brunswicker <[email protected]>
8 #
9 # Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
10 # SPDX-License-Identifier: BSD-2-Clause
11
12 from __future__ import annotations
13
14 from ansible_collections.community.general.plugins.module_utils._utm_utils import UTM
15
16
17 class FakeModule:
18 def __init__(self, params):
19 self.params = params
20
21
22 def test_combine_headers_returns_only_default():
23 expected = {"Accept": "application/json", "Content-type": "application/json"}
24 module = FakeModule(
25 params={
26 "utm_protocol": "utm_protocol",
27 "utm_host": "utm_host",
28 "utm_port": 1234,
29 "utm_token": "utm_token",
30 "name": "FakeName",
31 "headers": {},
32 }
33 )
34 result = UTM(module, "endpoint", [])._combine_headers()
35 assert result == expected
36
37
38 def test_combine_headers_returns_only_default2():
39 expected = {"Accept": "application/json", "Content-type": "application/json"}
40 module = FakeModule(
41 params={
42 "utm_protocol": "utm_protocol",
43 "utm_host": "utm_host",
44 "utm_port": 1234,
45 "utm_token": "utm_token",
46 "name": "FakeName",
47 }
48 )
49 result = UTM(module, "endpoint", [])._combine_headers()
50 assert result == expected
51
52
53 def test_combine_headers_returns_combined():
54 expected = {"Accept": "application/json", "Content-type": "application/json", "extraHeader": "extraHeaderValue"}
55 module = FakeModule(
56 params={
57 "utm_protocol": "utm_protocol",
58 "utm_host": "utm_host",
59 "utm_port": 1234,
60 "utm_token": "utm_token",
61 "name": "FakeName",
62 "headers": {"extraHeader": "extraHeaderValue"},
63 }
64 )
65 result = UTM(module, "endpoint", [])._combine_headers()
66 assert result == expected