class WebserviceTestCase(unittest.NoxTestCase): def configure(self, configuration): pass def install(self): lmgr = DefaultLogin(backup=FailureExceptionLogin()) self.wsc = AsyncNOXWSClient("127.0.0.1", 443, https=True, loginmgr=lmgr) def getInterface(self): return str(WebserviceTestCase) def _response_ok(self, r): self.failUnless(isinstance(r, AsyncNOXWSResponse), "Response is not an instance of AsyncNOXWSResponse") body = r.getExpectedBody(httplib.OK, "text/plain") match = re.search("GET /ws.v1/doc", body) self.failIf( match == None, "Did not find 'GET /ws.v1/doc' request documentation in the response." ) def _response_err(self, e): e.raiseException() def run_test(self): d = self.wsc.get("/ws.v1/doc") d.addCallback(self._response_ok) d.addErrback(self._response_err) return d
class WebserviceTestCase(unittest.NoxTestCase): def configure(self, configuration): pass def install(self): lmgr = DefaultLogin(backup=FailureExceptionLogin()) self.wsc = AsyncNOXWSClient("127.0.0.1", 443, https=True, loginmgr=lmgr) def getInterface(self): return str(WebserviceTestCase) def _response_ok(self, r): self.failUnless(isinstance(r, AsyncNOXWSResponse), "Response is not an instance of AsyncNOXWSResponse") body = r.getExpectedBody(httplib.OK, "text/plain") match = re.search("GET /ws.v1/doc", body) self.failIf(match == None, "Did not find 'GET /ws.v1/doc' request documentation in the response.") def _response_err(self, e): e.raiseException() def run_test(self): d = self.wsc.get("/ws.v1/doc") d.addCallback(self._response_ok) d.addErrback(self._response_err) return d
def install(self): lmgr = DefaultLogin(backup=FailureExceptionLogin()) self.wsc = AsyncNOXWSClient("127.0.0.1", 443, https=True, loginmgr=lmgr)
class ComponentWsTestCase(unittest.NoxTestCase): version_search = '(\d\.)*\d' version_example = '1.2.3' uptime_example = '1234' name_search = '(.+\.)*.+' name_example = 'abc.xyz' def configure(self, configuration): pass def install(self): lmgr = DefaultLogin(backup=FailureExceptionLogin()) self.wsc = AsyncNOXWSClient("127.0.0.1", 443, https=True, loginmgr=lmgr) def getInterface(self): return str(ComponentWsTestCase) def _response_err(self, e): e.raiseException() def check_version(self): d = self.wsc.get("/ws.v1/nox/version") d.addCallback(self._version_ok) d.addErrback(self._response_err) return d def _version_ok(self, r): self.failUnless(isinstance(r, AsyncNOXWSResponse), "Response is not an instance of AsyncNOXWSResponse") body = r.getExpectedBody(httplib.OK, "application/json") val = eval(body) self.failIf(type(val) != str, "Version '%s' is not a string." % body) match = re.search(self.version_search, val) self.failIf(match == None, "Version '%s' did not match expected '%s' format." % (body, self.version_example)) def check_uptime(self): d = self.wsc.get("/ws.v1/nox/uptime") d.addCallback(self._uptime_ok) d.addErrback(self._response_err) return d def _uptime_ok(self, r): self.failUnless(isinstance(r, AsyncNOXWSResponse), "Response is not an instance of AsyncNOXWSResponse") body = r.getExpectedBody(httplib.OK, "application/json") val = eval(body) self.failIf(type(val) != int, "Uptime '%s' is non-integral." % body) self.failIf(val < 0, "Uptime '%s' is negative." % body) def check_components(self): d = self.wsc.get("/ws.v1/nox/components") d.addCallback(self._components_ok) d.addErrback(self._response_err) return d def _components_ok(self, r): self.failUnless(isinstance(r, AsyncNOXWSResponse), "Response is not an instance of AsyncNOXWSResponse") body = r.getExpectedBody(httplib.OK, "application/json") d = eval(body) for c in d['items']: n = c['name'] match = re.search(self.name_search, n) self.failIf(match == None, "Component name '%s' did not match expected '%s' format." % (n,self.name_example)) v = c['version'] match = re.search('(\d\.)*\d', v) self.failIf(match == None, "Component %s: version '%s' did not match expected '%s' format." % (n,v,self.version_example)) u = c['uptime'] self.failIf(type(u) != int, "Component %s: uptime '%s' non-integral." % (n,u)) self.failIf(u < 0, "Component %s: uptime '%s' negative." % (n,u))
class ComponentWsTestCase(unittest.NoxTestCase): version_search = '(\d\.)*\d' version_example = '1.2.3' uptime_example = '1234' name_search = '(.+\.)*.+' name_example = 'abc.xyz' def configure(self, configuration): pass def install(self): lmgr = DefaultLogin(backup=FailureExceptionLogin()) self.wsc = AsyncNOXWSClient("127.0.0.1", 443, https=True, loginmgr=lmgr) def getInterface(self): return str(ComponentWsTestCase) def _response_err(self, e): e.raiseException() def check_version(self): d = self.wsc.get("/ws.v1/nox/version") d.addCallback(self._version_ok) d.addErrback(self._response_err) return d def _version_ok(self, r): self.failUnless(isinstance(r, AsyncNOXWSResponse), "Response is not an instance of AsyncNOXWSResponse") body = r.getExpectedBody(httplib.OK, "application/json") val = eval(body) self.failIf(type(val) != str, "Version '%s' is not a string." % body) match = re.search(self.version_search, val) self.failIf( match == None, "Version '%s' did not match expected '%s' format." % (body, self.version_example)) def check_uptime(self): d = self.wsc.get("/ws.v1/nox/uptime") d.addCallback(self._uptime_ok) d.addErrback(self._response_err) return d def _uptime_ok(self, r): self.failUnless(isinstance(r, AsyncNOXWSResponse), "Response is not an instance of AsyncNOXWSResponse") body = r.getExpectedBody(httplib.OK, "application/json") val = eval(body) self.failIf(type(val) != int, "Uptime '%s' is non-integral." % body) self.failIf(val < 0, "Uptime '%s' is negative." % body) def check_components(self): d = self.wsc.get("/ws.v1/nox/components") d.addCallback(self._components_ok) d.addErrback(self._response_err) return d def _components_ok(self, r): self.failUnless(isinstance(r, AsyncNOXWSResponse), "Response is not an instance of AsyncNOXWSResponse") body = r.getExpectedBody(httplib.OK, "application/json") d = eval(body) for c in d['items']: n = c['name'] match = re.search(self.name_search, n) self.failIf( match == None, "Component name '%s' did not match expected '%s' format." % (n, self.name_example)) v = c['version'] match = re.search('(\d\.)*\d', v) self.failIf( match == None, "Component %s: version '%s' did not match expected '%s' format." % (n, v, self.version_example)) u = c['uptime'] self.failIf( type(u) != int, "Component %s: uptime '%s' non-integral." % (n, u)) self.failIf(u < 0, "Component %s: uptime '%s' negative." % (n, u))