def testGoodMappings(self): ontology = self._gaObject for term in self._oboReader: self.assertIn(term.id, ontology.getTermIds(term.name)) gaTerm = ontology.getGaTermByName(term.name) self.assertTrue(protocol.validate(protocol.toJson(gaTerm), OntologyTerm)) self.assertEqual(gaTerm.term, term.name) self.assertIn(gaTerm.term_id, ontology.getTermIds(term.name))
def validateRequest(self, jsonDict, requestClass): """ Ensures the jsonDict corresponds to a valid instance of requestClass Throws an error if the data is invalid """ if self._requestValidation: if not protocol.validate(jsonDict, requestClass): raise exceptions.RequestValidationFailureException( jsonDict, requestClass)
def sendSearchRequest(self, path, request, responseClass): """ Sends the specified protocol request instance as JSON, and parses the result into an instance of the specified response. """ response = self.sendJsonPostRequest(path, protocol.toJson(request)) self.assertEqual(200, response.status_code) responseData = protocol.fromJson(response.data, responseClass) self.assertTrue( protocol.validate(protocol.toJson(responseData), responseClass)) return responseData
def sendSearchRequest(self, path, request, responseClass): """ Sends the specified protocol request instance as JSON, and parses the result into an instance of the specified response. """ response = self.sendJsonPostRequest(path, protocol.toJson(request)) # self.assertEqual(200, response.status_code) federated search can return 404 responseData = self.deserialize(response.data, responseClass) # responseData = protocol.fromProtobufString(response.data, # responseClass) self.assertTrue( protocol.validate(protocol.toJson(responseData), responseClass)) return responseData
def sendSearchRequest(self, path, request, responseClass): """ Sends the specified protocol request instance as JSON, and parses the result into an instance of the specified response. """ response = self.sendJsonPostRequest(path, protocol.toJson(request)) # self.assertEqual(200, response.status_code) federated search can return 404 response_json = json.loads(response.data) response = json.dumps(response_json.get('results', {})) responseData = protocol.deserialize(response, self.serialization, responseClass) self.assertTrue( protocol.validate(protocol.toJson(responseData), responseClass)) return responseData
def testValidate(self): classes = protocol.getProtocolClasses() for clazz in classes: obj = clazz() jsonStr = protocol.toJson(obj) protocol.validate(jsonStr, clazz)