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
2 changes: 0 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ omit =
*/_generated/*.py
# Packages in the "google.cloud" package that we don't own.
*/google/cloud/gapic/*
fail_under = 100
show_missing = True
exclude_lines =
# Re-enable the standard pragma

This comment was marked as spam.

This comment was marked as spam.

pragma: NO COVER
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ install:

script:
- tox -e py27
- (cd core && tox -e py27)
- tox -e py34
- (cd core && tox -e py34)
- tox -e lint
- tox -e cover
- (cd core && tox -e cover)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

- tox -e system-tests
- tox -e system-tests3
- scripts/update_docs.sh
Expand Down
13 changes: 13 additions & 0 deletions core/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[run]
branch = True

[report]
omit =
*/google/cloud/_testing.py
fail_under = 100
show_missing = True
exclude_lines =
# Re-enable the standard pragma
pragma: NO COVER
# Ignore debug-only repr
def __repr__
4 changes: 4 additions & 0 deletions core/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include README.rst
graft google
graft unit_tests
global-exclude *.pyc

This comment was marked as spam.

This comment was marked as spam.

20 changes: 20 additions & 0 deletions core/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Core Helpers for Google Cloud Python Client Library
===================================================

This library is not meant to stand-alone. Instead it defines
common helpers (e.g. base ``Client`` and ``Connection`` classes)
used by all of the ``google-cloud-*``.


- `Homepage`_
- `API Documentation`_

.. _Homepage: https://googlecloudplatform.github.io/google-cloud-python/
.. _API Documentation: http://googlecloudplatform.github.io/google-cloud-python/

Quick Start
-----------

::

$ pip install --upgrade google-cloud-core
20 changes: 20 additions & 0 deletions core/google/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
20 changes: 20 additions & 0 deletions core/google/cloud/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2014 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"""The base of the API call URL."""

DEFAULT_USER_AGENT = 'gcloud-python/{0}'.format(
get_distribution('google-cloud').version)
get_distribution('google-cloud-core').version)

This comment was marked as spam.

"""The user agent for google-cloud-python requests."""


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
72 changes: 72 additions & 0 deletions core/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

This comment was marked as spam.

This comment was marked as spam.


from setuptools import find_packages
from setuptools import setup


PACKAGE_ROOT = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(PACKAGE_ROOT, 'README.rst')) as file_obj:

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.

This comment was marked as spam.

README = file_obj.read()

# NOTE: This is duplicated throughout and we should try to
# consolidate.
SETUP_BASE = {
'author': 'Google Cloud Platform',
'author_email': '[email protected]',
'scripts': [],
'url': 'https://github.com/GoogleCloudPlatform/google-cloud-python',
'license': 'Apache 2.0',
'platforms': 'Posix; MacOS X; Windows',
'include_package_data': True,
'zip_safe': False,
'classifiers': [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Topic :: Internet',
],
}

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.



REQUIREMENTS = [
'httplib2 >= 0.9.1',
'googleapis-common-protos',
'oauth2client >= 2.0.1, < 3.0.0dev',
'protobuf >= 3.0.0',
'six',
]

setup(
name='google-cloud-core',
version='0.20.0dev',
description='API Client library for Google Cloud: Core Helpers',
long_description=README,
namespace_packages=[
'google',
'google.cloud',
],
packages=find_packages(),
install_requires=REQUIREMENTS,
**SETUP_BASE
)
29 changes: 29 additions & 0 deletions core/tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[tox]
envlist =
py27,py34,py35,cover

[testing]
deps =
pytest
covercmd =
py.test --quiet \
--cov=google.cloud \
--cov=unit_tests \
--cov-config {toxinidir}/.coveragerc \
unit_tests

[testenv]
commands =
py.test --quiet {posargs} unit_tests
deps =
{[testing]deps}

[testenv:cover]
basepython =
python2.7
commands =
{[testing]covercmd}
deps =
{[testenv]deps}
coverage
pytest-cov
13 changes: 13 additions & 0 deletions core/unit_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
13 changes: 13 additions & 0 deletions core/unit_tests/streaming/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2016 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ def _getTargetClass(self):
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)

def test_ctor_closed_stream(self):
class _Stream(object):
closed = True

start = 0
bufsize = 4
bufstream = self._makeOne(_Stream, start, bufsize)
self.assertIs(bufstream._stream, _Stream)
self.assertEqual(bufstream._start_pos, start)
self.assertEqual(bufstream._buffer_pos, 0)
self.assertEqual(bufstream._buffered_data, b'')
self.assertTrue(bufstream._stream_at_end)
self.assertEqual(bufstream._end_pos, 0)

def test_ctor_start_zero_longer_than_buffer(self):
from io import BytesIO
CONTENT = b'CONTENT GOES HERE'
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,41 @@ def test_http_w_creds(self):
def test_user_agent_format(self):
from pkg_resources import get_distribution
expected_ua = 'gcloud-python/{0}'.format(
get_distribution('google-cloud').version)
get_distribution('google-cloud-core').version)
conn = self._makeOne()
self.assertEqual(conn.USER_AGENT, expected_ua)

def test__create_scoped_credentials_with_scoped_credentials(self):
klass = self._getTargetClass()
scoped_creds = object()
scope = 'google-specific-scope'
credentials = _Credentials(scoped=scoped_creds)

result = klass._create_scoped_credentials(credentials, scope)
self.assertIs(result, scoped_creds)
self.assertEqual(credentials._create_scoped_calls, 1)
self.assertEqual(credentials._scopes, [scope])

def test__create_scoped_credentials_without_scope_required(self):
klass = self._getTargetClass()
credentials = _Credentials()

result = klass._create_scoped_credentials(credentials, None)
self.assertIs(result, credentials)
self.assertEqual(credentials._create_scoped_calls, 1)
self.assertEqual(credentials._scopes, [])

def test__create_scoped_credentials_non_scoped_credentials(self):
klass = self._getTargetClass()
credentials = object()
result = klass._create_scoped_credentials(credentials, None)
self.assertIs(result, credentials)

def test__create_scoped_credentials_no_credentials(self):
klass = self._getTargetClass()
result = klass._create_scoped_credentials(None, None)
self.assertIsNone(result)


class TestJSONConnection(unittest.TestCase):

Expand Down Expand Up @@ -375,16 +406,21 @@ def request(self, **kw):

class _Credentials(object):

_scopes = None

def __init__(self, authorized=None):
def __init__(self, authorized=None, scoped=None):
self._authorized = authorized
self._scoped = scoped
self._scoped_required = scoped is not None
self._create_scoped_calls = 0
self._scopes = []

def authorize(self, http):
self._called_with = http
return self._authorized

def create_scoped_required(self):
self._create_scoped_calls += 1
return False
return self._scoped_required

def create_scoped(self, scope):
self._scopes.append(scope)
return self._scoped
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ def test_html_when_json_expected(self):
self.assertEqual(exception.message, content)
self.assertEqual(list(exception.errors), [])

def test_without_use_json(self):
from google.cloud.exceptions import TooManyRequests

content = u'error-content'
response = _Response(TooManyRequests.code)
exception = self._callFUT(response, content, use_json=False)

self.assertIsInstance(exception, TooManyRequests)
self.assertEqual(exception.message, content)
self.assertEqual(list(exception.errors), [])


class _Response(object):
def __init__(self, status):
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions scripts/verify_included_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
])
PACKAGES = (
'',
'core',
)


Expand Down
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@


REQUIREMENTS = [
'httplib2 >= 0.9.1',
'googleapis-common-protos',
'oauth2client >= 2.0.1',
'protobuf >= 3.0.0',
'six',
'google-cloud-core',
]

GRPC_PACKAGES = [
Expand All @@ -72,7 +68,7 @@

setup(
name='google-cloud',
version='0.19.0',
version='0.20.0dev',
description='API Client library for Google Cloud',
long_description=README,
namespace_packages=[
Expand Down
Loading