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")
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
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