File: test_utils.py

package info (click to toggle)
python-pykube-ng 22.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 424 kB
  • sloc: python: 2,336; makefile: 44
file content (44 lines) | stat: -rw-r--r-- 1,858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from pykube.utils import join_url_path
from pykube.utils import obj_merge


def test_obj_merge():
    assert obj_merge({}, {}) == {}
    assert obj_merge({"a": 1}, {}) == {"a": 1}
    assert obj_merge({}, {"b": 2}) == {"b": 2}
    assert obj_merge({"a": []}, {"a": []}) == {"a": []}
    assert obj_merge({"a": [1, 2]}, {"a": []}) == {"a": [1, 2]}
    assert obj_merge({"a": []}, {"a": [1, 2]}) == {"a": [1, 2]}
    assert obj_merge({"a": [1, 2]}, {"a": [3, 4]}) == {"a": [1, 2]}
    assert obj_merge({"a": {"b": [1, 2]}}, {"a": {"b": [3, 4, 5], "c": [1, 2]}}) == {
        "a": {"b": [1, 2, 5], "c": [1, 2]}
    }

    assert obj_merge(
        {"a": {"e": [1, 2], "f": [5, 6]}},
        {"a": {"e": [3, 4]}, "b": ["1"]},
        is_strategic=False,
    ) == {"a": {"e": [1, 2], "f": [5, 6]}}
    assert obj_merge({"a": []}, {"a": [1, 2]}, is_strategic=False) == {"a": []}
    assert obj_merge({"a": {"b": [1, 2]}}, {"a": [1, 2]}, is_strategic=False) == {
        "a": {"b": [1, 2]}
    }
    assert obj_merge(
        {"a": {"b": [1, 2]}}, {"a": {"b": [], "c": [1, 2]}}, is_strategic=False
    ) == {"a": {"b": [1, 2]}}
    assert obj_merge(
        {"a": {"b": [1, 2]}}, {"a": {"b": [3, 4, 5], "c": [1, 2]}}, is_strategic=False
    ) == {"a": {"b": [1, 2]}}


def test_join_url_path():
    assert join_url_path() == "/"
    assert join_url_path("") == "/"
    assert join_url_path("", "/") == "/"
    assert join_url_path("first", "") == "/first"
    assert join_url_path("first", "/") == "/first/"
    assert join_url_path("first", "second") == "/first/second"
    assert join_url_path("/first", "second/") == "/first/second"
    assert join_url_path("first", "second", "") == "/first/second"
    assert join_url_path("first", "/", "second", "", "") == "/first/second"
    assert join_url_path("/first", "second", "", join_empty=True) == "/first/second/"