def test_get_ntp_servers_no_response(self): c = Cube((None, None)) c._socket = Mock(socket.socket) c._socket.recv = Mock(return_value=bytearray( "F:ntp.homematic.com,ntp.homematic.com", encoding='utf-8')) c.send_message = Mock() self.assertIsNone(c._ntp_servers) c.ntp_servers c.send_message.assert_called_with(FMessage()) self.assertIsNone(c.ntp_servers)
def test_get_ntp_servers(self): c = Cube((None, None)) c._socket = Mock(socket.socket) c._socket.recv = Mock(return_value=bytearray()) c.send_message = Mock() self.assertIsNone(c._ntp_servers) c.ntp_servers c.send_message.assert_called_with(FMessage()) c.handle_message( FResponse( bytearray("ntp.homematic.com,ntp.homematic.com", encoding='utf-8'))) self.assertEqual(c._ntp_servers, [u'ntp.homematic.com', u'ntp.homematic.com'])
def test_bytes_set(self): msg = FMessage(['foo', 'bar']) self.assertEqual(msg.to_bytes(), bytearray(b'f:foo,bar\r\n'))
def test_bytes_query(self): msg = FMessage() self.assertEqual(msg.to_bytes(), bytearray(b'f:\r\n'))
def test_set_ntp_servers(self): c = self._mocked_cube() c.ntp_servers = ['foo', 'bar'] c.send_message.assert_called_with(FMessage(['foo', 'bar']))
def set_ntp_servers(self, ntp_servers): self.send_message(FMessage(ntp_servers))
def get_ntp_servers(self): if self._ntp_servers is None: self.send_message(FMessage()) return self._ntp_servers