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_close_never_opened(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) # Close should allow calls even if never opened assert adapter.close() is None assert_amqp_closed(adapter)
def test_open_failure(self): adapter = AmqpAdapter( 'amqps://*****:*****@example.com:5672/services') assert_amqp(adapter) with pytest.raises(AdapterClosedError) as excinfo: adapter.open() assert isinstance(excinfo.value, AdapterError)
def test_flush(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) # A noop with adapter: assert adapter.flush() is None assert_amqp_closed(adapter)
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_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_close(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) assert adapter.close() is None assert_amqp_closed(adapter) # this makes sure con/chan is None # Close should allow multiple close calls assert adapter.close() 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__call__(self): adapter = AmqpAdapter(_amqp_url) cloned = adapter() assert not (cloned is None) assert not (cloned == adapter) assert_amqp(cloned) assert dict(adapter.properties.__dict__) == dict( cloned.properties.__dict__)
def test_emit_no_channel(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) adapter.channel.close() adapter.channel = None with pytest.raises(AdapterClosedError): assert adapter.emit(tevent().json) is None adapter.close() assert_amqp_closed(adapter)
def test_emit_closed_connection(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result) adapter.connection.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)
def adapter_factory(): return AmqpAdapter(_amqp_url)
def test_open(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter) result = adapter.open() assert_amqp_open(adapter, result)
def test_init(self): adapter = AmqpAdapter(_amqp_url) assert_amqp_closed(adapter)
def test_from_url(self): adapter = AmqpAdapter.from_url(_amqp_url) assert_amqp_closed(adapter)