def test_validate_bad_pres(): """Test bad Presentation messages.""" versions = [('1.4', PRES_BAD_FIXTURES_14), ('1.5', PRES_BAD_FIXTURES_15), ('2.0', PRES_BAD_FIXTURES_20)] for protocol_version, fixture in versions: const = get_const(protocol_version) for name, payload in fixture.items(): sub_type = const.Presentation[name] msg = Message('1;0;0;0;{};{}\n'.format(sub_type, payload)) with pytest.raises(vol.Invalid): msg.validate(protocol_version)
def test_validate_internal(): """Test Internal messages.""" versions = [('1.4', INTERNAL_FIXTURES_14), ('1.5', INTERNAL_FIXTURES_15), ('2.0', INTERNAL_FIXTURES_20)] for protocol_version, fixture in versions: gateway = get_gateway(protocol_version) const = get_const(protocol_version) for name, payload in fixture.items(): if isinstance(payload, dict): _payload = payload.get('payload') return_value = payload.get('return') else: _payload = payload return_value = None sub_type = const.Internal[name] msg = Message('1;255;3;0;{};{}\n'.format(sub_type, _payload)) valid = msg.validate(protocol_version) assert valid == { 'node_id': 1, 'child_id': 255, 'type': 3, 'ack': 0, 'sub_type': sub_type, 'payload': _payload } ret = gateway.logic('1;255;3;0;{};{}\n'.format(sub_type, _payload)) if return_value is None: assert ret is None, 'Version: {} Message: {}'.format( protocol_version, msg) else: assert ret, 'Version: {} Message: {}'.format( protocol_version, msg)
def test_validate_internal(): """Test Internal messages.""" versions = [('1.4', INTERNAL_FIXTURES_14), ('1.5', INTERNAL_FIXTURES_15), ('2.0', INTERNAL_FIXTURES_20)] for protocol_version, fixture in versions: const = get_const(protocol_version) for name, payload in fixture.items(): sub_type = const.Internal[name] msg = Message('1;255;3;0;{};{}\n'.format(sub_type, payload)) valid = msg.validate(protocol_version) assert valid == { 'node_id': 1, 'child_id': 255, 'type': 3, 'ack': 0, 'sub_type': sub_type, 'payload': payload }
def test_validate_set(): """Test Set messages.""" versions = [('1.4', SET_FIXTURES_14), ('1.5', SET_FIXTURES_15), ('2.0', SET_FIXTURES_20)] for protocol_version, fixture in versions: const = get_const(protocol_version) for name, payload in fixture.items(): sub_type = const.SetReq[name] msg = Message('1;0;1;0;{};{}\n'.format(sub_type, payload)) valid = msg.validate(protocol_version) assert valid == { 'node_id': 1, 'child_id': 0, 'type': 1, 'ack': 0, 'sub_type': sub_type, 'payload': payload }
def test_validate_pres(): """Test Presentation messages.""" versions = [('1.4', PRES_FIXTURES_14), ('1.5', PRES_FIXTURES_15), ('2.0', PRES_FIXTURES_20)] for protocol_version, fixture in versions: gateway = get_gateway(protocol_version) const = get_const(protocol_version) for name, payload in fixture.items(): sub_type = const.Presentation[name] msg = Message('1;0;0;0;{};{}\n'.format(sub_type, payload)) valid = msg.validate(protocol_version) assert valid == { 'node_id': 1, 'child_id': 0, 'type': 0, 'ack': 0, 'sub_type': sub_type, 'payload': payload } ret = gateway.logic('1;0;0;0;{};{}\n'.format(sub_type, payload)) assert ret is None