def test_error_server_and_simple_client_badJSON(self): IOLoopHelper.call(self.send_message, "I am JSON (but not a dict)") resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Error:1.0", id=-1, message= "ValueError: Error decoding JSON object (didn't return OrderedDict)" ) IOLoopHelper.call(self.send_message, "I am not JSON", convert_json=False) resp = self.result.get(timeout=2) if version_info[0] == 2: assert resp == dict( typeid="malcolm:core/Error:1.0", id=-1, message= "ValueError: Error decoding JSON object (No JSON object could be decoded)" ) elif version_info[0] == 3: assert resp == dict( typeid="malcolm:core/Error:1.0", id=-1, message= "ValueError: Error decoding JSON object (Expecting value: line 1 column 1 (char 0))" ) else: raise Exception("Got bad python version info")
def test_server_and_simple_client(self): msg = OrderedDict() msg['typeid'] = "malcolm:core/Post:1.0" msg['id'] = 0 msg['path'] = ("hello", "greet") msg['parameters'] = dict(name="me") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict(typeid="malcolm:core/Return:1.0", id=0, value="Hello me")
def test_blocks_delta(self): msg = OrderedDict() msg['typeid'] = "malcolm:core/Subscribe:1.0" msg['id'] = 0 msg['path'] = (".", "blocks", "value") msg['delta'] = True IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict(typeid="malcolm:core/Delta:1.0", id=0, changes=[[[], ["hello", "server"]]])
def test_error_server_and_simple_client_no_id(self): msg = OrderedDict() msg['typeid'] = "malcolm:core/Post:1.0" msg['path'] = ("hello", "greet") msg['parameters'] = dict(name="me") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Error:1.0", id=-1, message="FieldError: id field not present in JSON message")
def test_blocks_update(self): msg = OrderedDict() msg['typeid'] = "malcolm:core/Subscribe:1.0" msg['id'] = 0 msg['path'] = (".", "blocks", "value") msg['delta'] = False IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict(typeid="malcolm:core/Update:1.0", id=0, value=["hello", "server"])
def test_error_server_and_simple_client_no_path(self): msg = OrderedDict() msg['typeid'] = "malcolm:core/Post:1.0" msg['id'] = 0 IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Error:1.0", id=0, message= 'ValueError: Expected a path with at least 1 element, got []')
def test_error_server_and_simple_client_bad_path_controller(self): msg = OrderedDict() msg['typeid'] = "malcolm:core/Post:1.0" msg['id'] = 0 msg['path'] = ("goodbye", "insult") msg['parameters'] = dict(name="me") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Error:1.0", id=0, message="ValueError: No controller registered for mri 'goodbye'")
def test_error_server_and_simple_client_bad_type(self): msg = OrderedDict() msg['typeid'] = "NotATypeID" msg['id'] = 0 msg['path'] = ("hello", "greet") msg['parameters'] = dict(name="me") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Error:1.0", id=0, message="FieldError: 'NotATypeID' not a valid typeid")
def test_error_server_and_simple_client_bad_path_attribute(self): msg = OrderedDict() msg["typeid"] = "malcolm:core/Get:1.0" msg["id"] = 0 msg["path"] = ("hello", "meat") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Error:1.0", id=0, message=("UnexpectedError: Object 'hello' of type " "'malcolm:core/Block:1.0' has no attribute 'meat'"), )
def test_error_server_and_simple_client_superfluous_params(self): msg = OrderedDict() msg['typeid'] = "malcolm:core/Get:1.0" msg['id'] = 0 msg['path'] = ("hello", "meta") msg['parameters'] = dict(name="me") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Error:1.0", id=0, message="TypeError: malcolm:core/Get:1.0 raised error: " + "__init__() got an unexpected keyword argument 'parameters'")
def test_error_server_and_simple_client_bad_path_dict_attribute(self): msg = OrderedDict() msg["typeid"] = "malcolm:core/Get:1.0" msg["id"] = 0 msg["path"] = ("hello", "greet", "meta", "takes", "elements", "bad") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Error:1.0", id=0, message=( "UnexpectedError: Object 'hello.greet.meta.takes.elements' " "of type %r has no attribute 'bad'") % type(OrderedDict()), )
def test_concurrency(self): msg1 = Post(id=0, path=["hello", "greet"], parameters=dict(name="me", sleep=2)).to_dict() msg2 = Post(id=1, path=["hello", "error"]).to_dict() IOLoopHelper.call(self.send_messages, [msg1, msg2]) resp = self.result.get(timeout=1) assert resp == dict(typeid="malcolm:core/Error:1.0", id=1, message="RuntimeError: You called method error()") resp = self.result.get(timeout=3) assert resp == dict(typeid="malcolm:core/Return:1.0", id=0, value="Hello me")
def test_error_server_and_simple_client_no_type(self): msg = OrderedDict() msg['id'] = 0 msg['path'] = ("hello", "greet") msg['parameters'] = dict(name="me") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) if version_info[0] == 2: message = "FieldError: typeid not present in keys " + \ "[u'id', u'path', u'parameters']" elif version_info[0] == 3: message = "FieldError: typeid not present in keys " + \ "['id', 'path', 'parameters']" else: raise Exception("Got bad python version info") assert resp == dict(typeid="malcolm:core/Error:1.0", id=0, message=message)
def test_blocks_delta(self): msg = OrderedDict() msg["typeid"] = "malcolm:core/Subscribe:1.0" msg["id"] = 0 msg["path"] = (".", "blocks", "value") msg["delta"] = True IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) assert resp == dict( typeid="malcolm:core/Delta:1.0", id=0, changes=[[ [], { "label": ["hello", "server"], "mri": ["hello", "server"], "typeid": "malcolm:core/Table:1.0", }, ]], )
def test_error_server_and_simple_client_bad_path_attribute(self): msg = OrderedDict() msg['typeid'] = "malcolm:core/Get:1.0" msg['id'] = 0 msg['path'] = ("hello", "meat") IOLoopHelper.call(self.send_message, msg) resp = self.result.get(timeout=2) if version_info[0] == 2: assert resp == dict( typeid="malcolm:core/Error:1.0", id=0, message= "UnexpectedError: Object [u'hello'] of type 'malcolm:core/Block:1.0' has no attribute u'meat'" ) elif version_info[0] == 3: assert resp == dict( typeid="malcolm:core/Error:1.0", id=0, message= "UnexpectedError: Object ['hello'] of type 'malcolm:core/Block:1.0' has no attribute 'meat'" )
def test_post_hello(self): IOLoopHelper.call(self.post, "hello", "greet", json_encode(dict(name="me"))) result = self.result.get(timeout=2) assert result.body.decode().strip() == json_encode("Hello me")
def test_get_hello(self): IOLoopHelper.call(self.get, "hello") result = self.result.get(timeout=2) assert result.body.decode().strip() == json_encode(self.hello._block)