def test_sync_mode_detects_invalid_callback(settings): settings.HEDWIG_SYNC = True message = MessageFactory(msg_type=MessageType.vehicle_created) with pytest.raises(ValidationError) as exc_info: message.publish() assert isinstance(exc_info.value.__context__, CallbackNotFound)
def test_custom_validator(settings): settings.HEDWIG_DATA_VALIDATOR_CLASS = 'tests.validator.CustomValidator' message = MessageFactory(msg_type=MessageType.trip_created, addition_version=1, data__vin='o' * 17, validate=False) with pytest.raises(ValidationError): message.validate()
def test_validate_raises_error_invalid_schema(self): message = MessageFactory(schema='mickey-mouse', validate=False) with pytest.raises(ValidationError): self.validator.validate(message) message = MessageFactory( schema= 'https://hedwig.automatic.com/schema#/schemas/mickey-mouse/1.0', validate=False) with pytest.raises(ValidationError): self.validator.validate(message)
def test_validate_raises_error_invalid_schema(self): with pytest.raises(ValidationError) as e: MessageFactory( schema='https://wrong.host/schema#/schemas/trip_created/1.0') assert e.value.args[ 0] == 'message schema must start with "https://hedwig.automatic.com/schema"' with pytest.raises(ValidationError) as e: MessageFactory( schema= 'https://hedwig.automatic.com/schema#/schemas/trip_created/9.0' ) assert e.value.args[0] == 'definition not found in schema'
def test_validate_raises_error_invalid_schema(self): with pytest.raises(ValidationError): MessageFactory(schema='https://wrong.host/schema#/schemas/trip_created/1.0') with pytest.raises(ValidationError): MessageFactory(schema='https://hedwig.automatic.com/schema#/schemas/trip_created/9.0')
def test_validate(self): message = MessageFactory(msg_type=MessageType.trip_created, model_version=1) self.validator.validate(message)
def test_validate_raises_errors(self): with pytest.raises(ValidationError): MessageFactory(data={})
def test_validate_raises_errors(self): message = MessageFactory(data={}, validate=False) with pytest.raises(ValidationError): self.validator.validate(message)
def _message_data(): return MessageFactory.build(msg_type=MessageType.trip_created)