class TestSubscribe(unittest.TestCase):
    def setUp(self):
        self.context = MagicMock()
        self.response_queue = MagicMock()
        self.endpoint = ["BL18I:XSPRESS3", "state", "value"]
        self.delta = True
        self.subscribe = Subscribe(self.context,
                                   self.response_queue,
                                   self.endpoint,
                                   delta=self.delta)

    def test_init(self):
        self.assertEqual(self.context, self.subscribe.context)
        self.assertEqual(self.response_queue, self.subscribe.response_queue)
        self.assertEqual(self.endpoint, self.subscribe.endpoint)
        self.assertEqual(self.delta, self.subscribe.delta)
        self.assertEqual("malcolm:core/Subscribe:1.0", self.subscribe.typeid)

    def test_respond_with_update(self):
        value = MagicMock()

        self.subscribe.respond_with_update(value)

        call_arg = self.response_queue.put.call_args_list[0][0][0].to_dict()

        expected_response = Update(self.subscribe.id,
                                   self.subscribe.context,
                                   value=value).to_dict()

        self.assertEqual(call_arg, expected_response)

    def test_respond_with_delta(self):
        changes = [[["path"], "value"]]

        self.subscribe.respond_with_delta(changes)

        call_arg = self.response_queue.put.call_args_list[0][0][0].to_dict()

        expected_response = Delta(self.subscribe.id,
                                  self.subscribe.context,
                                  changes=changes).to_dict()

        self.assertEqual(call_arg, expected_response)

    def test_setters(self):
        self.subscribe.set_endpoint(["BL18I:XSPRESS3", "state", "value2"])
        self.assertEquals(["BL18I:XSPRESS3", "state", "value2"],
                          self.subscribe.endpoint)

        self.subscribe.set_delta(False)
        self.assertFalse(self.subscribe.delta)
Exemplo n.º 2
0
class TestSubscribe(unittest.TestCase):

    def setUp(self):
        self.context = MagicMock()
        self.response_queue = MagicMock()
        self.response_queue.qsize.return_value = 0
        self.endpoint = ["BL18I:XSPRESS3", "state", "value"]
        self.delta = True
        self.subscribe = Subscribe(
            self.context, self.response_queue, self.endpoint, delta=self.delta)

    def test_init(self):
        self.assertEqual(self.context, self.subscribe.context)
        self.assertEqual(self.response_queue, self.subscribe.response_queue)
        self.assertEqual(self.endpoint, self.subscribe.endpoint)
        self.assertEqual(self.delta, self.subscribe.delta)
        self.assertEqual("malcolm:core/Subscribe:1.0", self.subscribe.typeid)

    def test_respond_with_update(self):
        value = MagicMock()

        self.subscribe.respond_with_update(value)

        call_arg = self.response_queue.put.call_args_list[0][0][0].to_dict()

        expected_response = Update(self.subscribe.id, self.subscribe.context, value=value).to_dict()

        self.assertEqual(call_arg, expected_response)

    def test_respond_with_delta(self):
        changes = [[["path"], "value"]]

        self.subscribe.respond_with_delta(changes)

        call_arg = self.response_queue.put.call_args_list[0][0][0].to_dict()

        expected_response = Delta(self.subscribe.id, self.subscribe.context, changes=changes).to_dict()

        self.assertEqual(call_arg, expected_response)

    def test_setters(self):
        self.subscribe.set_endpoint(["BL18I:XSPRESS3", "state", "value2"])
        self.assertEquals(["BL18I:XSPRESS3", "state", "value2"], self.subscribe.endpoint)

        self.subscribe.set_delta(False)
        self.assertFalse(self.subscribe.delta)
Exemplo n.º 3
0
class TestSubscribe(unittest.TestCase):
    def setUp(self):
        self.callback = MagicMock()
        self.path = ["BL18I:XSPRESS3"]
        self.delta = True
        self.o = Subscribe(11, self.path, self.delta, self.callback)

    def test_init(self):
        assert self.o.typeid == "malcolm:core/Subscribe:1.0"
        assert self.o.id == 11
        assert self.o.callback == self.callback
        assert self.path == self.o.path
        assert self.delta == self.o.delta

    def test_respond_with_update(self):
        cb, response = self.o.update_response(value=5)
        assert cb == self.callback
        assert response == Update(id=11, value=5)

    def test_respond_with_delta(self):
        changes = [[["path"], "value"]]
        cb, response = self.o.delta_response(changes)
        assert cb == self.callback
        assert response == Delta(id=11, changes=changes)

    def test_setters(self):
        self.o.set_delta(False)
        assert not self.o.delta
        self.o.set_path(["BL18I:XSPRESS3", "state", "value"])
        self.o.set_id(19)
        d = self.o.to_dict()
        del d["delta"]
        assert get_doc_json("subscribe_xspress3_state_value") == d

    def test_doc(self):
        assert get_doc_json("subscribe_xspress3") == self.o.to_dict()