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
77
78
79
80
81
82
83
84
"""Test case for Mapping protocols"""
import unittest
import json
import os
import requests
from .base import Base
HOST = os.getenv("HOST", default="localhost")
PORT = os.getenv("PORT", default="8080")
API_KEY = os.getenv("API_KEY", "only4testingpurpose")
class TestMappingProtocols(Base):
"""Test case for Mapping protocols class"""
def test_that_mapping_protocols_default_value_is_set(self) -> None:
"""Test that mapping protocols default value is set"""
response = requests.post(
url=f"http://{HOST}:{PORT}/api/plugins/rps/mapping/",
json={
"source": "https://truc00.com/api",
"target": "http://10.10.10.10:1800/api",
},
headers={"Authorization": f"Token {API_KEY}"},
timeout=5,
)
self.assertEqual(response.status_code, 201)
self.mapping_id = json.loads(response.content)["id"]
content = json.loads(response.content)
self.assertEqual(content["protocols"], ["http_https"])
def test_that_mapping_protocols_are_not_valid(self) -> None:
"""Test that mapping protocols are not valid"""
response = requests.post(
url=f"http://{HOST}:{PORT}/api/plugins/rps/mapping/",
json={
"source": "https://truc00.com/api",
"target": "http://10.10.10.10:1800/api",
"protocols": ["thisisnotavalidprotocol", "websocket", "anotherone"],
},
headers={"Authorization": f"Token {API_KEY}"},
timeout=5,
)
self.assertEqual(response.status_code, 400)
self.assertEqual(
response.content,
b'{"protocols":{"0":["\\"thisisnotavalidprotocol\\" is not a valid choice."],'
+ b'"2":["\\"anotherone\\" is not a valid choice."]}}',
)
def test_that_mapping_protocols_are_valid(self) -> None:
"""Test that mapping protocols are not valid"""
response = requests.post(
url=f"http://{HOST}:{PORT}/api/plugins/rps/mapping/",
json={
"source": "https://truc00.com/api",
"target": "http://10.10.10.10:1800/api",
"protocols": ["http_https", "websocket"],
},
headers={"Authorization": f"Token {API_KEY}"},
timeout=5,
)
self.assertEqual(response.status_code, 201)
self.mapping_id = json.loads(response.content)["id"]
content = json.loads(response.content)
self.assertEqual(content["protocols"], ["http_https", "websocket"])
if __name__ == "__main__":
unittest.main()