Ejemplo n.º 1
0
    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")
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
 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"]]])
Ejemplo n.º 4
0
 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")
Ejemplo n.º 5
0
 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"])
Ejemplo n.º 6
0
 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 []')
Ejemplo n.º 7
0
 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'")
Ejemplo n.º 8
0
 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")
Ejemplo n.º 9
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)
     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'"),
     )
Ejemplo n.º 10
0
 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'")
Ejemplo n.º 11
0
 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()),
     )
Ejemplo n.º 12
0
 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")
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
 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",
             },
         ]],
     )
Ejemplo n.º 15
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'"
         )
Ejemplo n.º 16
0
 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")
Ejemplo n.º 17
0
 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)