Passed
Pull Request — master (#90)
by Antonio
05:03
created

test_evc_create.test_additional_properties()   A

Complexity

Conditions 2

Size

Total Lines 24
Code Lines 22

Duplication

Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 22
nop 0
dl 24
loc 24
rs 9.352
c 0
b 0
f 0
1
"""
2
EVC creation test
3
"""
4
import os
5
import json
6
import requests
7
8
9 View Code Duplication
def test_required():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
10
    """test should_fail_due_to_missing_name_attribute_on_payload"""
11
    actual_dir = os.getcwd()
12
    evc_params = actual_dir + "/tests/oas/evc_params.json"
13
    with open(evc_params, encoding="utf8") as json_file:
14
        json_data = json.load(json_file)
15
        json_file.close()
16
    url = json_data["url"]
17
    headers = json_data["headers"]
18
    payload = {
19
        "enabled": True,
20
        "uni_a": json_data["uni_a"],
21
        "uni_z": json_data["uni_z"],
22
        "bandwidth": json_data["bandwidth"],
23
        "dynamic_backup_path": True,
24
    }
25
    request_data = json.dumps(payload)
26
    response = requests.post(url=url, data=request_data, headers=headers)
27
    json_response = response.json()
28
    assert response.status_code == 400
29
    message = json.loads(json_response["description"]).get("message")
30
    assert "required" in message["error_validator"]
31
32
33 View Code Duplication
def test_additional_properties():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
34
    """test should_fail_due_to_additional_properties_on_payload"""
35
    actual_dir = os.getcwd()
36
    evc_params = actual_dir + "/tests/oas/evc_params.json"
37
    with open(evc_params, encoding="utf8") as json_file:
38
        json_data = json.load(json_file)
39
        json_file.close()
40
    url = json_data["url"]
41
    headers = json_data["headers"]
42
    payload = {
43
        "name": "EVC_1",
44
        "enabled": True,
45
        "uni_a": json_data["uni_a"],
46
        "uni_z": json_data["uni_z"],
47
        "bandwidth": json_data["bandwidth"],
48
        "dynamic_backup_path": True,
49
        "active": True,
50
    }
51
    request_data = json.dumps(payload)
52
    response = requests.post(url=url, data=request_data, headers=headers)
53
    json_response = response.json()
54
    message = json.loads(json_response["description"]).get("message")
55
    assert response.status_code == 400
56
    assert "additionalProperties" in message["error_validator"]
57
58
59
def test_pattern():
60
    """test should_fail_due_to_invalid_mac_address_on_payload"""
61
    actual_dir = os.getcwd()
62
    evc_params = actual_dir + "/tests/oas/evc_params.json"
63
    with open(evc_params, encoding="utf8") as json_file:
64
        json_data = json.load(json_file)
65
        json_file.close()
66
    url = json_data["url"]
67
    headers = json_data["headers"]
68
    json_data["uni_z"]["interface_id"] = "zz:00:00:00:00:00:00:01:1"
69
    payload = {
70
        "name": "EVC_1",
71
        "enabled": True,
72
        "uni_a": json_data["uni_a"],
73
        "uni_z": json_data["uni_z"],
74
        "bandwidth": json_data["bandwidth"],
75
        "dynamic_backup_path": True,
76
    }
77
    request_data = json.dumps(payload)
78
    response = requests.post(url=url, data=request_data, headers=headers)
79
    json_response = response.json()
80
    message = json.loads(json_response["description"]).get("message")
81
    assert response.status_code == 400
82
    assert "pattern" in message["error_validator"]
83
84
85
def test_type():
86
    """test should_fail_due_to_invalid_mac_address_on_payload"""
87
    actual_dir = os.getcwd()
88
    evc_params = actual_dir + "/tests/oas/evc_params.json"
89
    with open(evc_params, encoding="utf8") as json_file:
90
        json_data = json.load(json_file)
91
        json_file.close()
92
    url = json_data["url"]
93
    headers = json_data["headers"]
94
    payload = {
95
        "name": "EVC_1",
96
        "enabled": True,
97
        "uni_a": {
98
            "interface_id": "00:00:00:00:00:00:00:01:1",
99
            "tag": {"tag_type": 1, "value": "1"},
100
        },
101
        "uni_z": json_data["uni_z"],
102
        "bandwidth": json_data["bandwidth"],
103
        "dynamic_backup_path": True,
104
    }
105
    request_data = json.dumps(payload)
106
    response = requests.post(url=url, data=request_data, headers=headers)
107
    json_response = response.json()
108
    message = json.loads(json_response["description"]).get("message")
109
    assert response.status_code == 400
110
    assert "type" in message["error_validator"]
111