Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull in / reconcile all PRs for #314 #347

Merged
merged 24 commits into from
Nov 6, 2014
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d52d81f
Add support for the Bucket's 'versioning' field.
tseaver Nov 4, 2014
8477e85
Add tests asserting that 'get_metatdata' raises w/ 'versioning'.
tseaver Nov 4, 2014
037a732
Add support for the Bucket's 'logging' field.
tseaver Nov 4, 2014
c586a7c
Add CORS support to buckets.
tseaver Nov 4, 2014
b721f42
Add location support to buckets.
tseaver Nov 4, 2014
c9fa1f3
Expanded / explicit coverage and assertions for '_helpers._MetadataMi…
tseaver Nov 5, 2014
2c3725d
Remove redundant coverage for mixin methods.
tseaver Nov 5, 2014
36966e8
Stop using 'metadata' to refer to all properties in bucket/key repres…
tseaver Nov 5, 2014
79e0b05
Wrap method / attr name in single quotes.
tseaver Nov 5, 2014
7533899
Add read-only properties for non-writable bucket fields.
tseaver Nov 5, 2014
9d7fc2f
Merge branch '314-bucket_versioning_support' into 314-omnibus
tseaver Nov 5, 2014
40c03c5
Merge branch '314-bucket_logging_support' into 314-omnibus
tseaver Nov 5, 2014
1fdacb4
Merge branch '314-bucket_cors_support' into 314-omnibus
tseaver Nov 5, 2014
48677ee
Merge branch '314-bucket_location_support' into 314-omnibus
tseaver Nov 5, 2014
c3fcb2e
Re-order methods to match field order.
tseaver Nov 5, 2014
aa7afbb
Make 'lazy' test less eager.
tseaver Nov 5, 2014
5f1667a
Fix up accessor / mutators methods to use new helpers.
tseaver Nov 5, 2014
72f3e5a
Bucket has more fields than pylint wants to allow.
tseaver Nov 5, 2014
f77e593
Remove backward-compatibility aliases.
tseaver Nov 6, 2014
b8ea274
Docstring fixes.
tseaver Nov 6, 2014
262b413
Drop (unused-and-confusing) '_has_property' method.
tseaver Nov 6, 2014
25b7b5c
Use 'properties' to ensure loading before lookup.
tseaver Nov 6, 2014
13b28c2
Fix copy-paste errors in 'Bucket' accessor docstrings.
tseaver Nov 6, 2014
3eaf39d
Avoid remapping names of keys in server-side properties.
tseaver Nov 6, 2014
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
Prev Previous commit
Next Next commit
Expanded / explicit coverage and assertions for '_helpers._MetadataMi…
…xin'.
  • Loading branch information
tseaver committed Nov 5, 2014
commit c9fa1f3fd52f14c08b97b192ad8ae66132c13eb6
118 changes: 105 additions & 13 deletions gcloud/storage/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,121 @@ def _getTargetClass(self):
def _makeOne(self, *args, **kw):
return self._getTargetClass()(*args, **kw)

def test_abstract_properties(self):
metadata_object = self._makeOne()
self.assertRaises(NotImplementedError,
lambda: metadata_object.connection)
self.assertRaises(NotImplementedError,
lambda: metadata_object.path)
def _derivedClass(self, connection=None, path=None, **custom_fields):

def test_get_metadata_w_custom_field(self):
class Derived(self._getTargetClass()):
CUSTOM_METADATA_FIELDS = {'foo': 'get_foo'}
CUSTOM_METADATA_FIELDS = custom_fields

@property
def connection(self): # pragma: NO COVER
return None
def connection(self):
return connection

@property
def path(self): # pragma: NO COVER
return None
def path(self):
return path

return Derived

def test_connetction_is_abstract(self):
mixin = self._makeOne()
self.assertRaises(NotImplementedError, lambda: mixin.connection)

def test_path_is_abstract(self):
mixin = self._makeOne()
self.assertRaises(NotImplementedError, lambda: mixin.path)

def test_has_metadata_not_loaded(self):
mixin = self._makeOne()
self.assertEqual(mixin.has_metadata('nonesuch'), False)

def test_has_metadata_loaded_no_field(self):
mixin = self._makeOne(metadata={'foo': 'Foo'})
self.assertEqual(mixin.has_metadata(), True)

def test_has_metadata_loaded_miss(self):
mixin = self._makeOne(metadata={'foo': 'Foo'})
self.assertEqual(mixin.has_metadata('nonesuch'), False)

def test_has_metadata_loaded_hit(self):
mixin = self._makeOne(metadata={'extant': False})
self.assertEqual(mixin.has_metadata('extant'), True)

def test_reload_metadata(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
derived.reload_metadata()
self.assertEqual(derived.metadata, {'foo': 'Foo'})
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'GET')
self.assertEqual(kw[0]['path'], '/path')
self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})

def test_get_metadata_eager_no_field(self):
derived = self._derivedClass()(metadata={'extant': False})
self.assertEqual(derived.get_metadata(), {'extant': False})

def test_get_metadata_eager_hit(self):
derived = self._derivedClass()(metadata={'foo': 'Foo'})
self.assertEqual(derived.get_metadata('foo'), 'Foo')

derived = Derived()
def test_get_metadata_lazy_hit(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
self.assertEqual(derived.get_metadata('foo'), 'Foo')
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'GET')
self.assertEqual(kw[0]['path'], '/path')
self.assertEqual(kw[0]['query_params'], {'projection': 'noAcl'})

def test_get_metadata_w_custom_field(self):
derived = self._derivedClass(foo='get_foo')()
try:
derived.get_metadata('foo')
except KeyError as e:
self.assertTrue('get_foo' in str(e))
else: # pragma: NO COVER
self.assert_('KeyError not raised')

def test_patch_metadata(self):
connection = _Connection({'foo': 'Foo'})
derived = self._derivedClass(connection, '/path')()
self.assertTrue(derived.patch_metadata({'foo': 'Foo'}) is derived)
kw = connection._requested
self.assertEqual(len(kw), 1)
self.assertEqual(kw[0]['method'], 'PATCH')
self.assertEqual(kw[0]['path'], '/path')
self.assertEqual(kw[0]['data'], {'foo': 'Foo'})
self.assertEqual(kw[0]['query_params'], {'projection': 'full'})

def test_get_acl_not_yet_loaded(self):
class ACL(object):
loaded = False

def reload(self):
self.loaded = True

mixin = self._makeOne()
acl = mixin.acl = ACL()
self.assertTrue(mixin.get_acl() is acl)
self.assertTrue(acl.loaded)

def test_get_acl_already_loaded(self):
class ACL(object):
loaded = True
mixin = self._makeOne()
acl = mixin.acl = ACL()
self.assertTrue(mixin.get_acl() is acl) # no 'reload'


class _Connection(object):

def __init__(self, *responses):
self._responses = responses
self._requested = []

def api_request(self, **kw):
self._requested.append(kw)
response, self._responses = self._responses[0], self._responses[1:]
return response