Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_decode_payload_alldata(caplog):
with caplog.at_level(logging.DEBUG):
# Bootstrap the core machinery without MQTT.
core_bootstrap(configfile=configfile)
# Proof that decoding a valid JSON payload decodes it appropriately.
outcome = decode_payload(section='test/alldata', topic='bar', payload='{"baz": "qux"}')
assert outcome['topic'] == 'bar'
assert outcome['baz'] == 'qux'
assert outcome['alldata-key'] == 'alldata-value'
def test_decode_payload_foo(caplog):
with caplog.at_level(logging.DEBUG):
# Bootstrap the core machinery without MQTT.
core_bootstrap(configfile=configfile)
# Proof that decoding an unconfigured thing yields nothing sensible.
outcome = decode_payload(section='foo', topic='bar', payload='baz')
assert outcome['topic'] == 'bar'
assert outcome['payload'] == 'baz'
assert 'Cannot decode JSON object, payload=baz' in caplog.text, caplog.text
def test_decode_payload_json(caplog):
with caplog.at_level(logging.DEBUG):
# Bootstrap the core machinery without MQTT.
core_bootstrap(configfile=configfile)
# Proof that decoding a valid JSON payload decodes it appropriately.
outcome = decode_payload(section='foo', topic='bar', payload='{"baz": "qux"}')
assert outcome['topic'] == 'bar'
assert outcome['payload'] == '{"baz": "qux"}'
assert outcome['baz'] == 'qux'
def test_decode_payload_datamap(caplog):
with caplog.at_level(logging.DEBUG):
# Bootstrap the core machinery without MQTT.
core_bootstrap(configfile=configfile)
# Proof that decoding a valid JSON payload decodes it appropriately.
outcome = decode_payload(section='test/datamap', topic='bar', payload='{"baz": "qux"}')
assert outcome['topic'] == 'bar'
assert outcome['baz'] == 'qux'
assert outcome['datamap-key'] == 'datamap-value'