Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from __future__ import print_function

import atexit
import copy
import logging
import threading

Expand Down Expand Up @@ -254,9 +253,7 @@ class BackgroundThreadTransport(Transport):

def __init__(self, client, name, grace_period=_DEFAULT_GRACE_PERIOD,
batch_size=_DEFAULT_MAX_BATCH_SIZE):
http = copy.deepcopy(client._http)
self.client = client.__class__(
client.project, client._credentials, http)
self.client = client

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

logger = self.client.logger(name)
self.worker = _Worker(logger)
self.worker.start()
Expand Down
32 changes: 17 additions & 15 deletions logging/tests/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,30 +414,32 @@ def test_create_sink_storage_bucket(self):
self.assertTrue(sink.exists())

def test_create_sink_pubsub_topic(self):
from google.cloud.iam import OWNER_ROLE
from google.cloud.pubsub import client as pubsub_client
import uuid

from google.cloud import pubsub_v1

SINK_NAME = 'test-create-sink-topic%s' % (_RESOURCE_ID,)
TOPIC_NAME = 'logging-test-sink%s' % (_RESOURCE_ID,)
TOPIC_NAME = '%s-%s' % ('systest', str(uuid.uuid4())[0:8])

# Create the destination topic, and set up the IAM policy to allow
# Stackdriver Logging to write into it.
pubsub_client = pubsub_client.Client()
topic = pubsub_client.topic(TOPIC_NAME)
topic.create()
self.to_delete.append(topic)
policy = topic.get_iam_policy()
new_owners = set([policy.group('[email protected]')])
new_owners.update(policy.owners)
policy[OWNER_ROLE] = new_owners
topic.set_iam_policy(policy)

TOPIC_URI = 'pubsub.googleapis.com/%s' % (topic.full_name,)
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path(Config.CLIENT.project, TOPIC_NAME)
publisher.create_topic(topic_path)

policy = publisher.get_iam_policy(topic_path)
policy.bindings.add(
role='roles/owner',
members=['group:[email protected]']
)
publisher.set_iam_policy(topic_path, policy)

TOPIC_URI = 'pubsub.googleapis.com/%s' % (topic_path,)

sink = Config.CLIENT.sink(SINK_NAME, DEFAULT_FILTER, TOPIC_URI)
self.assertFalse(sink.exists())
sink.create()
self.to_delete.append(sink)
publisher.delete_topic(topic_path)
self.assertTrue(sink.exists())

def _init_bigquery_dataset(self):
Expand Down
44 changes: 14 additions & 30 deletions logging/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,23 +560,18 @@ def test_list_metrics_with_paging(self):
})

def test_get_default_handler_app_engine(self):
import requests
import os
from google.cloud._testing import _Monkey
from google.cloud.logging.client import _APPENGINE_FLEXIBLE_ENV_VM
from google.cloud.logging.handlers import AppEngineHandler

http_mock = mock.Mock(spec=requests.Session)
credentials = _make_credentials()
deepcopy = mock.Mock(return_value=http_mock)

with _Monkey(os, environ={_APPENGINE_FLEXIBLE_ENV_VM: 'True'}):
with mock.patch('copy.deepcopy', new=deepcopy):
client = self._make_one(project=self.PROJECT,
credentials=credentials,
_use_grpc=False)
handler = client.get_default_handler()
deepcopy.assert_called_once_with(client._http)
client = self._make_one(project=self.PROJECT,
credentials=credentials,
_use_grpc=False)
handler = client.get_default_handler()

self.assertIsInstance(handler, AppEngineHandler)

Expand All @@ -598,39 +593,28 @@ def test_get_default_handler_container_engine(self):
self.assertIsInstance(handler, ContainerEngineHandler)

def test_get_default_handler_general(self):
import requests
from google.cloud.logging.handlers import CloudLoggingHandler

http_mock = mock.Mock(spec=requests.Session)
credentials = _make_credentials()
deepcopy = mock.Mock(return_value=http_mock)

with mock.patch('copy.deepcopy', new=deepcopy):
client = self._make_one(project=self.PROJECT,
credentials=credentials,
_use_grpc=False)
handler = client.get_default_handler()
deepcopy.assert_called_once_with(client._http)
client = self._make_one(project=self.PROJECT,
credentials=credentials,
_use_grpc=False)
handler = client.get_default_handler()

self.assertIsInstance(handler, CloudLoggingHandler)

def test_setup_logging(self):
import requests

http_mock = mock.Mock(spec=requests.Session)
deepcopy = mock.Mock(return_value=http_mock)
setup_logging = mock.Mock(spec=[])

credentials = _make_credentials()

with mock.patch('copy.deepcopy', new=deepcopy):
with mock.patch('google.cloud.logging.client.setup_logging',
new=setup_logging):
client = self._make_one(project=self.PROJECT,
credentials=credentials,
_use_grpc=False)
client.setup_logging()
deepcopy.assert_called_once_with(client._http)
with mock.patch('google.cloud.logging.client.setup_logging',
new=setup_logging):
client = self._make_one(project=self.PROJECT,
credentials=credentials,
_use_grpc=False)
client.setup_logging()

setup_logging.assert_called()

Expand Down