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)
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 == {}
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 == {}
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
def fix_fake_client(self): args = { "connect": { "host": "localhost", } } return MQTTClient(**args)
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
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)