def test_fail_emit(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) adapter.properties.content_type = '0' * 256 with pytest.raises(AdapterEmitError): adapter.emit(tevent().json)
def test_emit_closed(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) with pytest.raises(AdapterClosedError): assert adapter.emit(tevent().json) is None assert_amqp_closed(adapter)
def test_emit_ensure_connection_after_emit_failure(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) # This message is invalid so we should not be able to emit with pytest.raises(AdapterEmitPermanentError) as excinfo: assert adapter.emit(AdapterEmitPermanentError) is None assert isinstance(excinfo.value, AdapterEmitPermanentError) # Set system and ensure it's accepted event_json = tevent().json assert adapter.emit(event_json) is None assert_amqp_open(adapter, result)
def test_emit(self): event = tevent() event_json = event.json adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) assert adapter.emit(event_json) is None assert_amqp_open(adapter, result)
def test_emit_closed_channel(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) adapter.channel.close() with pytest.raises(AdapterClosedError): assert adapter.emit(tevent().json) is None adapter.close() assert_amqp_closed(adapter)
def test_fail_emit_permanent(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) # Make this fail by assertion error for 100% cov restore = pika.spec.Basic.Ack try: with pytest.raises(AdapterEmitPermanentError) as excinfo: adapter.channel._delivery_confirmation = True pika.spec.Basic.Ack = None assert adapter.emit(tevent().json) is None finally: pika.spec.Basic.Ack = restore assert isinstance(excinfo.value, AdapterError) adapter.close() assert_amqp_closed(adapter)
def test_fail_closed_via_pika(self): def _flush_output(*args, **kwargs): raise pika.exceptions.ProtocolSyntaxError adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) # Make this fail by assertion error for 100% cov restore = adapter.channel._flush_output try: with pytest.raises(AdapterClosedError) as excinfo: adapter.channel._flush_output = _flush_output assert adapter.emit(tevent().json) is None finally: adapter.channel._flush_output = restore assert isinstance(excinfo.value, AdapterClosedError) adapter.close() assert_amqp_closed(adapter)