示例#1
0
def test_private_get_publisher_raises(mock_publisher):
    client = mock_publisher.return_value
    client.create_topic.side_effect = Exception("foo")

    with pytest.raises(Exception, match="foo"):
        utils._get_publisher("a-topic")

    mock_publisher.assert_called_once_with()
    client.create_topic.assert_called_once_with("a-topic")
示例#2
0
def test_private_get_publisher(mock_publisher):
    ret_publisher = utils._get_publisher("a-topic")

    mock_publisher.assert_called_once_with()
    mock_publisher.return_value.create_topic.assert_called_once_with("a-topic")

    assert mock_publisher.return_value == ret_publisher
示例#3
0
def test_private_get_publisher_topic_exists(mock_publisher):
    client = mock_publisher.return_value
    client.create_topic.side_effect = gapi_exceptions.AlreadyExists("foo")

    ret_publisher = utils._get_publisher("a-topic")

    mock_publisher.assert_called_once_with()
    client.create_topic.assert_called_once_with("a-topic")

    assert client == ret_publisher