summaryrefslogtreecommitdiffstats
path: root/tests/test_validator.py
blob: ad291a9119cd567417428eae9441983771e46d4d (plain)
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
77
78
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
113
114
115
116
117
118
119
120
121
122
123
from pytest import raises
from jsonschema import ValidationError

from onap_data_provider.validator import Validator
from onap_data_provider.versions import VersionsEnum


def test_validator_customer():
    validator = Validator()
    input_data = {
        "customers": [
            {
                "customer": {
                    "global-customer-id": "test",
                    "subscriber-name": "test",
                    "subscriber-type": "test",
                }
            }
        ]
    }
    validator.validate(VersionsEnum.NONE, input_data)
    input_data = {
        "customers": [
            {
                "customer": {
                    "global-customer-id": "test",
                    "subscriber-name": "test",
                    "subscriber-type": "test",
                }
            }
        ]
    }
    validator.validate(VersionsEnum.V1_0, input_data)

    invalid_input_data = {  # Missing subscriber-type
        "customers": [
            {"customer": {"global-customer-id": "test", "subscriber-name": "test"}}
        ]
    }
    with raises(ValidationError):
        validator.validate(VersionsEnum.V1_0, invalid_input_data)


def test_validator_vsps():
    validator = Validator()
    input_data = {
        "vsps": [
            {
                "vsp": {
                    "name": "test",
                    "vendor": "test",
                    "package": "test",
                }
            }
        ]
    }
    validator.validate(VersionsEnum.NONE, input_data)

    input_data = {
        "vsps": [
            {
                "vsp": {
                    "name": "test",
                    "vendor": "test",
                    "package": "test",
                }
            }
        ]
    }
    validator.validate(VersionsEnum.V1_0, input_data)

    input_data = {
        "vsps": [
            {
                "vsp": {
                    "name": "test",
                }
            }
        ]
    }
    with raises(ValidationError):
        validator.validate(VersionsEnum.V1_0, input_data)


def test_validator_service():
    validator = Validator()
    input_data = {
        "services": [
            {
                "service": {
                    "name": "test",
                    "resources": [
                        {"name": "test", "type": "test"},
                        {"name": "test1", "type": "test2"},
                    ],
                    "properties": [
                        {"name": "test", "type": "test", "value": "test"},
                        {"name": "test1", "type": "test1"},
                    ],
                }
            }
        ]
    }
    validator.validate(VersionsEnum.NONE, input_data)

    input_data = {
        "services": [
            {
                "service": {
                    "name": "test",
                    "resources": [
                        {"name": "test", "type": "test"},
                        {"name": "test1", "type": "test2"},
                    ],
                    "properties": [
                        {"name": "test", "type": "test", "value": "test"},
                        {"name": "test1", "type": "test1"},
                    ],
                }
            }
        ]
    }
    validator.validate(VersionsEnum.V1_0, input_data)