test_clean_meta.py 3.69 KB
Newer Older
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# ----------------------------------------------------------------------
# noc.core.datastream.base.clean_meta tests
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------

# Third-party modules
import pytest

# NOC modules
from noc.core.datastream.base import DataStream


@pytest.mark.parametrize(
    "meta,current_meta,expected",
    [
        (
            {
                "client_groups": [],
                "pool": "default",
                "service_groups": ["6128a1bbda3903fa14f1b4eb", "6128a1bbda3903fa14f1b538"],
            },
            {"pool": "default", "service_groups": [], "client_groups": []},
            {
                "client_groups": [],
                "pool": ["default"],
                "service_groups": [["6128a1bbda3903fa14f1b4eb", "6128a1bbda3903fa14f1b538"]],
            },
        ),
        (
            {
                "client_groups": [],
                "pool": "default2",
                "service_groups": ["6128a1bbda3903fa14f1b4eb", "6128a1bbda3903fa14f1b538"],
            },
            {"pool": ["default"], "service_groups": [], "client_groups": []},
            {
                "client_groups": [],
                "pool": ["default2", "default"],
                "service_groups": [["6128a1bbda3903fa14f1b4eb", "6128a1bbda3903fa14f1b538"]],
            },
        ),
        (
            {"client_groups": [], "pool": "default2", "service_groups": []},
            {
                "pool": ["default"],
                "service_groups": ["6128a1bbda3903fa14f1b4eb", "6128a1bbda3903fa14f1b538"],
                "client_groups": [],
            },
            {
                "client_groups": [],
                "pool": ["default2", "default"],
                "service_groups": [[], ["6128a1bbda3903fa14f1b4eb", "6128a1bbda3903fa14f1b538"]],
            },
        ),
        (
            {"client_groups": [], "pool": "default2", "service_groups": []},
            {
                "pool": ["default"],
                "service_groups": [[], ["6128a1bbda3903fa14f1b4eb", "6128a1bbda3903fa14f1b538"]],
                "client_groups": [],
            },
            {
                "client_groups": [],
                "pool": ["default2", "default"],
                "service_groups": [[], ["6128a1bbda3903fa14f1b4eb", "6128a1bbda3903fa14f1b538"]],
            },
        ),
        (
            {"pool": "default", "service_groups": [], "client_groups": []},
            {},
            {"pool": ["default"], "service_groups": [], "client_groups": []},
        ),
    ],
)
77
def test_ds_clean_meta(meta, current_meta, expected):
78
    assert DataStream.clean_meta(meta, current_meta) == expected
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112


@pytest.mark.parametrize(
    "meta,meta_filter,expected",
    [
        (
            {"servers": [["ns1.example.com", "ns2.example.com"]]},
            {"meta.servers": {"$elemMatch": {"$elemMatch": {"$in": ["ns1.example.com"]}}}},
            False,
        ),
        (
            {
                "servers": [
                    ["ns3.example.com", "ns2.example.com"],
                    ["ns1.example.com", "ns2.example.com"],
                ]
            },
            {"meta.servers": {"$elemMatch": {"$elemMatch": {"$in": ["ns1.example.com"]}}}},
            True,
        ),
        (
            {"pool": ["POOL1", "POOL2"]},
            {"meta.pool": "POOL2"},
            True,
        ),
        (
            {"pool": ["POOL1", "POOL2"]},
            {"meta.pool": "POOL1"},
            False,
        ),
    ],
)
def test_ds_is_moved(meta, meta_filter, expected):
    assert DataStream.is_moved(meta, meta_filter) == expected