Skip to content

Commit

Permalink
more review
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill Prin committed Nov 21, 2016
1 parent 0b4060d commit 4477d59
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions logging/unit_tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import mock
import unittest


Expand Down Expand Up @@ -582,41 +581,45 @@ def test_get_default_handler_container_engine(self):

self.assertIsInstance(handler, ContainerEngineHandler)

@mock.patch('copy.deepcopy')
def test_get_default_handler_general(self, deepcopy):
def test_get_default_handler_general(self):
import httplib2
import mock
from google.cloud.logging.handlers import CloudLoggingHandler

http_mock = mock.Mock()
deepcopy.return_value = http_mock

http_mock = mock.Mock(spec=httplib2.Http)
credentials = _Credentials()
client = self._make_one(project=self.PROJECT,
credentials=credentials,
use_gax=False)
handler = client.get_default_handler()
deepcopy = mock.Mock(return_value=http_mock)

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

self.assertIsInstance(handler, CloudLoggingHandler)
self.assertTrue(credentials.authorized, http_mock)

@mock.patch('copy.deepcopy')
def test_setup_logging(self, deepcopy):
from google.cloud._testing import _Monkey
import google.cloud.logging.client as MUT
def test_setup_logging(self):
import httplib2
import mock

http_mock = mock.Mock()
deepcopy.return_value = http_mock
http_mock = mock.Mock(spec=httplib2.Http)
deepcopy = mock.Mock(return_value=http_mock)
setup_logging = mock.Mock()

credentials = _Credentials()
client = self._make_one(project=self.PROJECT,
credentials=credentials,
use_gax=False)

client.get_default_handler()

setup_logging_mock = _SetupLogging()
with _Monkey(MUT, setup_logging=setup_logging_mock):
client.setup_logging()
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_gax=False)
client.setup_logging()
deepcopy.assert_called_once_with(client._connection.http)

self.assertTrue(setup_logging_mock.called)
setup_logging.assert_called()
self.assertTrue(credentials.authorized, http_mock)


Expand Down

0 comments on commit 4477d59

Please sign in to comment.