예제 #1
0
def test_client_tls_params():
    config = MQTTConfig(tls=MQTTTLSConfig(hostname='example.com',
                                          ca_file='foo',
                                          client_key='bar',
                                          client_cert='foobar'))
    tls = tls_params(config)

    assert tls['ca_certs'] == 'foo'
    assert tls['keyfile'] == 'bar'
    assert tls['certfile'] == 'foobar'
예제 #2
0
def test_client_publish_single_binary(mqtt_server):

    config = MQTTConfig()

    def publish_test():
        publish_single(config,
                       'snipskit-test/topic',
                       'foobar',
                       json_encode=False)

    threading.Timer(DELAY, publish_test).start()

    message = subscribe.simple('snipskit-test/topic')
    assert message.payload.decode('utf-8') == 'foobar'
예제 #3
0
def test_client_publish_single_json(mqtt_server):

    config = MQTTConfig()

    def publish_test():
        publish_single(config, 'snipskit-test/topic', {
            'foo': 'bar',
            'foobar': True
        })

    threading.Timer(DELAY, publish_test).start()

    message = subscribe.simple('snipskit-test/topic')
    assert json.loads(message.payload.decode('utf-8')) == {
        'foo': 'bar',
        'foobar': True
    }
예제 #4
0
def test_client_auth_params():
    config = MQTTConfig(auth=MQTTAuthConfig(username='******', password='******'))
    auth = auth_params(config)

    assert auth['username'] == 'foo'
    assert auth['password'] == 'bar'
예제 #5
0
def test_client_tls_params_without_tls():
    config = MQTTConfig()
    tls = tls_params(config)

    assert tls is None
예제 #6
0
def test_client_host_port_tls():
    config = MQTTConfig(tls=MQTTTLSConfig(hostname='example.com'))
    host, port = host_port(config)

    assert host == 'example.com'
    assert port == 1883
예제 #7
0
def test_client_host_port():
    config = MQTTConfig()
    host, port = host_port(config)

    assert host == 'localhost'
    assert port == 1883
예제 #8
0
def test_client_auth_params_without_auth():
    config = MQTTConfig()
    auth = auth_params(config)

    assert auth is None
예제 #9
0
def test_client_auth_params_without_password():
    config = MQTTConfig(auth=MQTTAuthConfig(username='******'))
    auth = auth_params(config)

    assert auth['username'] == 'foo'
    assert auth['password'] is None