Skip to content

Commit 5cf311f

Browse files
committed
Merge pull request #964 from dhermes/add-client-to-storage
Adding basic client class in storage.
2 parents 46db5d9 + ef42499 commit 5cf311f

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

gcloud/storage/client.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2015 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""gcloud storage client for interacting with API."""
16+
17+
18+
from gcloud.client import JSONClient
19+
from gcloud.storage.connection import Connection
20+
21+
22+
class Client(JSONClient):
23+
"""Client to bundle configuration needed for API requests.
24+
25+
:type project: string
26+
:param project: the project which the client acts on behalf of. Will be
27+
passed when creating a topic. If not passed,
28+
falls back to the default inferred from the environment.
29+
30+
:type credentials: :class:`oauth2client.client.OAuth2Credentials` or
31+
:class:`NoneType`
32+
:param credentials: The OAuth2 Credentials to use for the connection
33+
owned by this client. If not passed (and if no ``http``
34+
object is passed), falls back to the default inferred
35+
from the environment.
36+
37+
:type http: :class:`httplib2.Http` or class that defines ``request()``.
38+
:param http: An optional HTTP object to make requests. If not passed, an
39+
``http`` object is created that is bound to the
40+
``credentials`` for the current object.
41+
"""
42+
43+
_connection_class = Connection

gcloud/storage/test_client.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2015 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest2
16+
17+
18+
class TestClient(unittest2.TestCase):
19+
20+
def _getTargetClass(self):
21+
from gcloud.storage.client import Client
22+
return Client
23+
24+
def _makeOne(self, *args, **kw):
25+
return self._getTargetClass()(*args, **kw)
26+
27+
def test_ctor_connection_type(self):
28+
from gcloud.storage.connection import Connection
29+
30+
PROJECT = object()
31+
CREDENTIALS = _Credentials()
32+
33+
client = self._makeOne(project=PROJECT, credentials=CREDENTIALS)
34+
self.assertTrue(isinstance(client.connection, Connection))
35+
self.assertTrue(client.connection.credentials is CREDENTIALS)
36+
37+
38+
class _Credentials(object):
39+
40+
_scopes = None
41+
42+
@staticmethod
43+
def create_scoped_required():
44+
return True
45+
46+
def create_scoped(self, scope):
47+
self._scopes = scope
48+
return self

0 commit comments

Comments
 (0)