class TestJSONBackend(object): def setUp(self): self.client = JSONClient(webaddress) def test_login(self): self.client.login(*credentials) self.client.get_server_version() self.client.logout() def test_wronglogin(self): ret = self.client.login("WrongUser", "wrongpw") assert ret is False def test_httpauth(self): # cheap http auth ret = requests.get(webaddress + "/getServerVersion", auth=HTTPBasicAuth(*credentials)) assertEqual(ret.status_code, 200) assert ret.text def test_jsonbody(self): payload = {'section': 'webui', 'option': 'port'} headers = {'content-type': 'application/json'} ret = requests.get(webaddress + "/getConfigValue", headers=headers, auth=HTTPBasicAuth(*credentials), data=json.dumps(payload)) assertEqual(ret.status_code, 200) assert ret.text @raises(Forbidden) def test_access(self): self.client.get_server_version() @raises(AttributeError) def test_unknown_method(self): self.client.login(*credentials) self.client.sdfdsg()
def setUp(self): self.client = JSONClient(webaddress)
# Struct - Api class elif hasattr(result, "__name__") and result.__name__ in classes: for attr, atype in zip(result.__slots__, classes[result.__name__]): self.assert_type(getattr(result, attr), atype) else: #: simple object assert isinstance(result, type_) except AssertionError: print("Assertion for {0} as {1} failed".format(result, type_)) raise def call(self, func, *args, **kwargs): result = getattr(self.api, func)(*args, **kwargs) self.assert_type(result, methods[func]) return result def __getattr__(self, item): def call(*args, **kwargs): return self.call(item, *args, **kwargs) return call if __name__ == '__main__': from pyload.rpc.jsonclient import JSONClient api = ApiProxy(JSONClient(), "User", "test") api.get_server_version()
class TestJSONBackend(object): def setUp(self): self.client = JSONClient(webaddress) def test_login(self): self.client.login(*credentials) self.client.get_server_version() self.client.logout() def test_wronglogin(self): ret = self.client.login('WrongUser', 'wrongpw') assert ret is False def test_httpauth(self): # cheap http auth ret = requests.get(webaddress + '/getServerVersion', auth=HTTPBasicAuth(*credentials)) assertEqual(ret.status_code, 200) assert ret.text def test_jsonbody(self): payload = {'section': 'webui', 'option': 'port'} headers = {'content-type': 'application/json'} ret = requests.get(webaddress + '/getConfigValue', headers=headers, auth=HTTPBasicAuth(*credentials), data=json.dumps(payload)) assertEqual(ret.status_code, 200) assert ret.text @raises(Forbidden) def test_access(self): self.client.get_server_version() @raises(AttributeError) def test_unknown_method(self): self.client.login(*credentials) self.client.sdfdsg()
def enable_json(self): self.api = ApiProxy(JSONClient(webaddress))
# Struct - Api class elif hasattr(result, '__name__') and result.__name__ in classes: for attr, atype in zip(result.__slots__, classes[result.__name__]): self.assert_type(getattr(result, attr), atype) else: # simple object assert isinstance(result, type_) except AssertionError: print('Assertion for {0} as {1} failed'.format(result, type_)) raise def call(self, func, *args, **kwargs): result = getattr(self.api, func)(*args, **kwargs) self.assert_type(result, methods[func]) return result def __getattr__(self, item): def call(*args, **kwargs): return self.call(item, *args, **kwargs) return call if __name__ == '__main__': from pyload.rpc.jsonclient import JSONClient api = ApiProxy(JSONClient(), 'User', 'test') api.get_server_version()