Skip to content

Commit 63dd484

Browse files
author
user
committed
Extract fetching IS-11 resources to set_up_tests
# Conflicts: # nmostesting/suites/IS1101Test.py
1 parent 14bccb2 commit 63dd484

File tree

2 files changed

+178
-119
lines changed

2 files changed

+178
-119
lines changed

nmostesting/IS11Utils.py

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Copyright (C) 2022 Advanced Media Workflow Association
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from . import TestHelper
16+
from .NMOSUtils import NMOSUtils
17+
18+
19+
class IS11Utils(NMOSUtils):
20+
def __init__(self, url):
21+
NMOSUtils.__init__(self, url)
22+
23+
# TODO: Remove the duplication (IS05Utils)
24+
def get_senders(self):
25+
"""Gets a list of the available senders on the API"""
26+
toReturn = []
27+
valid, r = TestHelper.do_request("GET", self.url + "senders/")
28+
if valid and r.status_code == 200:
29+
try:
30+
for value in r.json():
31+
toReturn.append(value[:-1])
32+
except ValueError:
33+
pass
34+
return toReturn
35+
36+
# TODO: Remove the duplication (IS05Utils)
37+
def get_receivers(self):
38+
"""Gets a list of the available receivers on the API"""
39+
toReturn = []
40+
valid, r = TestHelper.do_request("GET", self.url + "receivers/")
41+
if valid and r.status_code == 200:
42+
try:
43+
for value in r.json():
44+
toReturn.append(value[:-1])
45+
except ValueError:
46+
pass
47+
return toReturn
48+
49+
# TODO: Remove the duplication (IS05Utils)
50+
def get_inputs(self):
51+
"""Gets a list of the available inputs on the API"""
52+
toReturn = []
53+
valid, r = TestHelper.do_request("GET", self.url + "inputs/")
54+
if valid and r.status_code == 200:
55+
try:
56+
for value in r.json():
57+
toReturn.append(value[:-1])
58+
except ValueError:
59+
pass
60+
return toReturn
61+
62+
# TODO: Remove the duplication (IS05Utils)
63+
def get_outputs(self):
64+
"""Gets a list of the available outputs on the API"""
65+
toReturn = []
66+
valid, r = TestHelper.do_request("GET", self.url + "outputs/")
67+
if valid and r.status_code == 200:
68+
try:
69+
for value in r.json():
70+
toReturn.append(value[:-1])
71+
except ValueError:
72+
pass
73+
return toReturn
74+
75+
# TODO: Remove the duplication (IS05Utils)
76+
def checkCleanRequest(self, method, dest, data=None, code=200):
77+
"""Checks a request can be made and the resulting json can be parsed"""
78+
status, response = TestHelper.do_request(method, self.url + dest, json=data)
79+
if not status:
80+
return status, response
81+
82+
message = "Expected status code {} from {}, got {}.".format(code, dest, response.status_code)
83+
if response.status_code == code:
84+
return True, response
85+
else:
86+
return False, message
87+
88+
# TODO: Remove the duplication (IS05Utils)
89+
def checkCleanRequestJSON(self, method, dest, data=None, code=200):
90+
valid, response = self.checkCleanRequest(method, dest, data, code)
91+
if valid:
92+
try:
93+
return True, response.json()
94+
except Exception:
95+
# Failed parsing JSON
96+
return False, "Invalid JSON received"
97+
else:
98+
return valid, response

0 commit comments

Comments
 (0)