Exemplo n.º 1
0
def test_host_required():
    """Always needs a host, but it's the only required key"""
    with pytest.raises(exceptions.MissingKeysError):
        MQTTClient()

    args = {"connect": {"host": "localhost"}}

    MQTTClient(**args)
Exemplo n.º 2
0
    def test_no_subscribe_on_unrecognised_suback(self):
        def subscribe_success(topic, *args, **kwargs):
            return (0, 123)

        mock_client = TestSubscription.get_mock_client_with(subscribe_success)

        MQTTClient._on_subscribe(mock_client, "abc", {}, 123, 0)

        assert mock_client._subscribed == {}
Exemplo n.º 3
0
    def test_no_subscribe_on_err(self):
        def subscribe_err(topic, *args, **kwargs):
            return (1, 123)

        mock_client = TestSubscription.get_mock_client_with(subscribe_err)

        MQTTClient.subscribe(mock_client, "abc")

        assert mock_client._subscribed == {}
Exemplo n.º 4
0
    def test_handles_subscriptions(self):
        def subscribe_success(topic, *args, **kwargs):
            return (0, 123)

        mock_client = TestSubscription.get_mock_client_with(subscribe_success)

        MQTTClient.subscribe(mock_client, "abc")

        assert mock_client._subscribed[123].topic == "abc"
        assert mock_client._subscribed[123].subscribed == False
Exemplo n.º 5
0
    def fix_fake_client(self):
        args = {
            "connect": {
                "host": "localhost",
            }
        }

        return MQTTClient(**args)
Exemplo n.º 6
0
    def test_disabled_tls(self):
        """Even if there are other invalid options, disable tls and early exit
        without checking other args
        """
        args = {
            "connect": {
                "host": "localhost"
            },
            "tls": {
                "certfile": "/lcliueurhug/ropko3kork32"
            },
        }

        with pytest.raises(exceptions.MQTTTLSError):
            MQTTClient(**args)

        args["tls"]["enable"] = False

        c = MQTTClient(**args)
        assert not c._enable_tls
Exemplo n.º 7
0
    def test_invalid_tls_ver(self):
        """Bad tls versions raise exception
        """
        args = {
            "connect": {
                "host": "localhost"
            },
            "tls": {
                "tls_version": "custom_tls"
            }
        }

        with pytest.raises(exceptions.MQTTTLSError):
            MQTTClient(**args)