示例#1
0
def test_get_publisher_config_raises(config_key, exp_msg, config, auth_client,
                                     publisher_client, caplog, emulator):
    """Raise with improper configuration."""
    changes_chnl = asyncio.Queue()
    config.pop(config_key)

    with pytest.raises(exceptions.GCPConfigError) as e:
        client = plugins.get_publisher(config, changes_chnl)
        client.publisher.create_topic.assert_not_called()

    e.match(exp_msg)
    assert 1 == len(caplog.records)
示例#2
0
def test_get_publisher_raises(config, auth_client, publisher_client, caplog,
                              emulator):
    """Raise when there's an issue creating a Google Pub/Sub topic."""
    changes_chnl = asyncio.Queue()
    publisher_client.return_value.create_topic.side_effect = [Exception('fooo')]

    with pytest.raises(exceptions.GCPGordonJanitorError) as e:
        client = plugins.get_publisher(config, changes_chnl)

        client.publisher.create_topic.assert_called_once_with(client.topic)
        e.match(f'Error trying to create topic "{client.topic}"')

    assert 1 == len(caplog.records)
示例#3
0
def test_get_publisher_topic_exists(config, auth_client, publisher_client,
                                    emulator):
    """Do not raise if topic already exists."""
    changes_chnl = asyncio.Queue()
    exp = google_exceptions.AlreadyExists('foo')
    publisher_client.return_value.create_topic.side_effect = [exp]

    short_topic = config['topic']
    client = plugins.get_publisher(config, changes_chnl)

    exp_topic = f'projects/{config["project"]}/topics/{short_topic}'
    assert 60 == client.cleanup_timeout
    assert client.publisher is not None
    assert not client._messages
    assert exp_topic == client.topic

    client.publisher.create_topic.assert_called_once_with(exp_topic)
示例#4
0
def test_get_publisher(local, timeout, exp_timeout, topic, config,
                       auth_client, publisher_client, emulator, monkeypatch):
    """Happy path to initialize a Publisher client."""
    changes_chnl = asyncio.Queue()

    if local:
        monkeypatch.setenv('PUBSUB_EMULATOR_HOST', True)

    if timeout:
        config['cleanup_timeout'] = timeout

    config['topic'] = topic
    client = plugins.get_publisher(config, changes_chnl)

    topic = topic.split('/')[-1]
    exp_topic = f'projects/{config["project"]}/topics/{topic}'
    assert exp_timeout == client.cleanup_timeout
    assert client.publisher is not None
    assert not client._messages

    client.publisher.create_topic.assert_called_once_with(exp_topic)