Пример #1
0
def mqtt_settings() -> MqttSettings:
    uid = time()
    return MqttSettings(hostname='localhost',
                        port=MQTT_LISTEN_PORT,
                        cert_dir=TEST_DATA_DIR,
                        topic_req="squeeze-req-%s" % uid,
                        topic_resp="squeeze-resp-%s" % uid)
Пример #2
0
 def mqtt_settings(self) -> MqttSettings:
     uid = time()
     test_mqtt_settings = MqttSettings(hostname='test.mosquitto.org',
                                       port=8883,
                                       cert_dir=TEST_DATA_DIR,
                                       topic_req="squeeze-req-%s" % uid,
                                       topic_resp="squeeze-resp-%s" % uid)
     return test_mqtt_settings
Пример #3
0
def fake_client():
    c = EchoingFakeClient(MqttSettings())
    c.connect()
    yield c
    c.disconnect()
    del c
Пример #4
0
 def test_configured(self):
     m = MqttSettings()
     m.hostname = None
     c = m.configured
     assert not c
Пример #5
0
 def test_get_conf_file_raises(self):
     c = NoTlsCustomClient(MqttSettings())
     with pytest.raises(Error) as e:
         c._conf_file_of("*.py")
     assert "Can't find" in str(e)
Пример #6
0
 def test_get_conf_file(self):
     c = NoTlsCustomClient(MqttSettings())
     assert c._conf_file_of("*.md")
Пример #7
0
#   squeeze-alexa is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   See LICENSE for full license

import pytest
from pytest import raises

from squeezealexa.settings import MqttSettings, SslSettings
from squeezealexa.transport.base import check_listening, Error
from squeezealexa.transport.configured import create_transport
from tests.transport.base import TimeoutServer

UNCONFIGURED_MQTT_SETTINGS = MqttSettings(hostname=None)


def test_check_listening():
    with TimeoutServer() as server:
        check_listening("localhost", server.port, timeout=1)

        wrong_port = server.port + 1
        with pytest.raises(Error) as e:
            check_listening("localhost", wrong_port, timeout=1, msg="OHNOES")
        s = str(e)
        assert ("on localhost:%d" % wrong_port) in s
        assert "OHNOES" in s


def test_create_transport_uses_full_ca_path():
Пример #8
0
def test_create_transport_uses_cert_path():
    ssls = SslSettings()
    ssls.cert_file_path = "/foo/bar"
    with raises(Error) as e:
        create_transport(ssls, MqttSettings())
    assert ("cert '%s'" % ssls.cert_file_path) in str(e)