Esempio n. 1
0
def test_should_raise_exception_when_get_bindings_from_source_but_teapot(
        mocker: MagicMock) -> None:
    response = mock_bad_response_with_status(418)
    patch = mocker.patch('requests.get', return_value=response)
    try:
        get_bindings_from_source(broker=fake_broker(),
                                 vhost='EA',
                                 source='test')
    except Exception as e:
        assert_that(e.args[0]).is_equal_to(418)
    patch.assert_called_with(
        url='https://fake-broker/api/exchanges/EA/test/bindings/source',
        auth=('guest', 'guest'))
Esempio n. 2
0
def test_should_return_get_bindings_from_source(mocker: MagicMock) -> None:
    bindings = [{
        'source': 'one-s',
        'destination': 'one-d',
        'routing_key': 'one-r',
        'destination_type': 'queue',
        'arguments': None
    }, {
        'source': 'two-s',
        'destination': 'two-d',
        'routing_key': 'two-r',
        'destination_type': 'exchange',
        'arguments': None
    }]
    response = mock_response(bindings)
    patch = mocker.patch('requests.get', return_value=response)
    result = map(
        lambda i: i.to_dict(),
        get_bindings_from_source(broker=fake_broker(),
                                 vhost='EA',
                                 source='test'))
    assert_that(result).is_equal_to(bindings)
    patch.assert_called_with(
        url='https://fake-broker/api/exchanges/EA/test/bindings/source',
        auth=('guest', 'guest'))
Esempio n. 3
0
def test_should_return_empty_list_when_get_bindings_from_source_but_none(
        mocker: MagicMock) -> None:
    bindings: List[dict] = []
    response = mock_response(bindings)
    patch = mocker.patch('requests.get', return_value=response)
    result = map(
        lambda i: i.to_dict(),
        get_bindings_from_source(broker=fake_broker(),
                                 vhost='EA',
                                 source='test'))
    assert_that(result).is_empty()
    patch.assert_called_with(
        url='https://fake-broker/api/exchanges/EA/test/bindings/source',
        auth=('guest', 'guest'))