Exemple #1
0
class TestProtocol():
    def setup(self):
        self.client = Mock()
        self.protocol = ZBXDProtocol()

    def test_receive_key_zbxd(self):
        sent_key = KEY
        self.client.recv.side_effect = [
            self.protocol.HEADER,
            struct.pack('q', len(sent_key)),
            b(sent_key)
        ]
        received_key = self.protocol.receive_value(self.client)
        assert_is_instance(received_key, string_types)
        assert_equal(u(sent_key), received_key)

    def test_send_value(self):
        self.protocol.send_value(self.client, 1)
        self.client.sendall.assert_called_with(ANY)
        assert_is_instance(self.client.sendall.call_args[0][0], bytes)

        self.protocol.send_value(self.client, "1")
        self.client.sendall.assert_called_with(ANY)
        assert_is_instance(self.client.sendall.call_args[0][0], bytes)

    def test_floats_are_not_sent_in_scientific_notation(self):
        self.protocol.send_value(self.client, 1.06828003857e+12)
        sent_message = self.client.sendall.call_args[0][0]
        decoded_message = sent_message.decode('utf-8')
        assert_not_in('e+', decoded_message)
        assert_not_in('E+', decoded_message)
Exemple #2
0
 def setup(self):
     self.client = Mock()
     self.protocol = ZBXDProtocol()