def __init__(self): self.test = globalConfig.test self.urlBase = globalConfig.apiUrl self.type = IMMEDIATE_ACTIVATION self.activationTimestamp = "0:0" self.actionList = [] self.activationID = None self._callInstance = Call(self.urlBase + "map/activations")
def assembleInputObject(self): """Create JSON representation of an Input""" toReturn = {} resourceList = ['parent', 'channels', 'caps', 'properties'] for resource in resourceList: url = "{}/{}".format(self.url, resource) call = Call(url) toReturn[resource] = call.get() return toReturn
def delete(self): url = self.urlBase + "map/activations/{}".format(self.activationID) deleteCall = Call(url) deleteCall.expectedCode = 204 deleteCall.string = True deleteCall.delete() deleteCall.expectedCode = 404 try: deleteCall.get() except NMOSTestException: msg = "Activation still present at {} after deletion".format(url) raise NMOSTestException(self.test.FAIL(msg))
def assembleOutputObject(self): """Create JSON representation of an Output""" toReturn = {} resourceList = { 'sourceid': 'source_id', 'channels': 'channels', 'caps': 'caps', 'properties': 'properties' } for apiId, ioId in resourceList.items(): url = "{}{}".format(self.url, apiId) call = Call(url) toReturn[ioId] = call.get() if toReturn['source_id'] == "null": toReturn['source_id'] = None return toReturn
class Activation: def __init__(self): self.test = globalConfig.test self.urlBase = globalConfig.apiUrl self.type = IMMEDIATE_ACTIVATION self.activationTimestamp = "0:0" self.actionList = [] self.activationID = None self._callInstance = Call(self.urlBase + "map/activations") def addAction(self, action): self.actionList.append(action) def _activationObject(self): activationObject = {"mode": self.type} if self.type != IMMEDIATE_ACTIVATION: activationObject['requested_time'] = self.activationTimestamp return activationObject def _actionObject(self): actionObject = {} for action in self.actionList: actionObject.update(action.toJSON()) return actionObject def _buildPOSTObject(self): postObject = { 'activation': self._activationObject(), 'action': self._actionObject() } return postObject def _setExpectedResponseCode(self): if self.type == IMMEDIATE_ACTIVATION: self._callInstance.expectedCode = 200 else: self._callInstance.expectedCode = 202 def _getActivationIDFromActivationResponse(self, activationResponse): try: activationID = list(activationResponse)[0] except IndexError: msg = self.test.FAIL( "Could not find activation ID in activation response") raise NMOSTestException(msg) try: activationID = int(activationID) except ValueError: msg = self.test.FAIL( "Activations IDs must be an int, got {}".format(activationID)) raise NMOSTestException(msg) self._checkActivationId(activationID) self.activationID = activationID def _checkActivationId(self, activationId): if not re.match("^[0-9]+$", str(activationId)): msg = self.test.FAIL( "Activation response code {} did" " not match require regex.".format(activationId)) raise NMOSTestException(msg) def fireActivation(self): postObject = self._buildPOSTObject() self._setExpectedResponseCode() self._callInstance.responseSchema = globalConfig.testSuite.get_schema( globalConfig.apiKey, "POST", "/map/activations", 200) activationResponse = self._callInstance.post(postObject) self._getActivationIDFromActivationResponse(activationResponse) return self.activationID def delete(self): url = self.urlBase + "map/activations/{}".format(self.activationID) deleteCall = Call(url) deleteCall.expectedCode = 204 deleteCall.string = True deleteCall.delete() deleteCall.expectedCode = 404 try: deleteCall.get() except NMOSTestException: msg = "Activation still present at {} after deletion".format(url) raise NMOSTestException(self.test.FAIL(msg)) def checkLock(self): postObject = self._buildPOSTObject() self._callInstance.expectedCode = 423 self._callInstance.post(postObject) def checkReject(self): postObject = self._buildPOSTObject() self._callInstance.expectedCode = 400 self._callInstance.responseSchema = globalConfig.testSuite.get_schema( globalConfig.apiKey, "POST", "/map/activations", 400) self._callInstance.post(postObject)
def buildJSONObject(self): call = Call(self.url) return call.get()
def getIOList(ioType): url = "{}{}s".format(globalConfig.apiUrl, ioType) call = Call(url) call.expectedCode = 200 response = call.get() return trimTrailingSlashesInList(response)
def getIOAsJSON(self): ioResourceURL = "{}{}".format(self.url, "io") call = Call(ioResourceURL) return call.get()