Example #1
0
    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)
Example #2
0
    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)
Example #3
0
    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)
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
    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)
Example #7
0
    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)
Example #8
0
    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)
Example #9
0
 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__)
Example #10
0
    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)
Example #11
0
    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)
Example #12
0
    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)
Example #13
0
    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)
Example #14
0
 def adapter_factory():
     return AmqpAdapter(_amqp_url)
Example #15
0
    def test_open(self):
        adapter = AmqpAdapter(_amqp_url)
        assert_amqp_closed(adapter)

        result = adapter.open()
        assert_amqp_open(adapter, result)
Example #16
0
 def test_init(self):
     adapter = AmqpAdapter(_amqp_url)
     assert_amqp_closed(adapter)
Example #17
0
 def test_from_url(self):
     adapter = AmqpAdapter.from_url(_amqp_url)
     assert_amqp_closed(adapter)