Skip to content

Commit d4bc450

Browse files
committed
Remove 'pure virtualness' from ACL.{reload_path,save_path}.
Addresses: #853 (comment)
1 parent 324dea7 commit d4bc450

2 files changed

Lines changed: 21 additions & 74 deletions

File tree

gcloud/storage/acl.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ class ACL(object):
172172
_URL_PATH_ELEM = 'acl'
173173
loaded = False
174174

175+
# Subclasses must override to provide these attributes (typically,
176+
# as properties).
177+
reload_path = None
178+
save_path = None
179+
175180
def __init__(self):
176181
self.entities = {}
177182

@@ -348,37 +353,6 @@ def get_entities(self):
348353
self._ensure_loaded()
349354
return list(self.entities.values())
350355

351-
@property
352-
def reload_path(self):
353-
"""Compute the path for GET API requests for this ACL.
354-
355-
This is a virtual method, expected to be implemented by subclasses.
356-
357-
:raises: :class:`NotImplementedError` if ``_reload_path`` attribute
358-
is not set on the instance.
359-
"""
360-
# Allow override for testing
361-
path = getattr(self, '_reload_path', None)
362-
if path is not None:
363-
return path
364-
raise NotImplementedError
365-
366-
@property
367-
def save_path(self):
368-
"""Compute the path for PATCH API requests for this ACL.
369-
370-
This is a virtual method, expected to be implemented by subclasses.
371-
372-
:raises: :class:`NotImplementedError` if ``_save_path`` attribute
373-
is not set on the instance.
374-
375-
"""
376-
# Allow override for testing
377-
path = getattr(self, '_save_path', None)
378-
if path is not None:
379-
return path
380-
raise NotImplementedError
381-
382356
def reload(self, connection=None):
383357
"""Reload the ACL data from Cloud Storage.
384358

gcloud/storage/test_acl.py

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -505,35 +505,13 @@ def test_get_entities_nonempty(self):
505505
entity = acl.entity(TYPE, ID)
506506
self.assertEqual(acl.get_entities(), [entity])
507507

508-
def test_reload_path_wo_attr(self):
509-
acl = self._makeOne()
510-
self.assertRaises(NotImplementedError, lambda: acl.reload_path)
511-
512-
def test_reload_path_w_attr(self):
513-
acl = self._makeOne()
514-
acl._reload_path = '/testing/acl'
515-
self.assertEqual(acl.reload_path, '/testing/acl')
516-
517-
def test_save_path_wo_attr(self):
518-
acl = self._makeOne()
519-
self.assertRaises(NotImplementedError, lambda: acl.save_path)
520-
521-
def test_save_path_w_attr(self):
522-
acl = self._makeOne()
523-
acl._save_path = '/testing'
524-
self.assertEqual(acl.save_path, '/testing')
525-
526-
def test_reload_wo_path_raises_NotImplementedError(self):
527-
acl = self._makeOne()
528-
self.assertRaises(NotImplementedError, acl.reload)
529-
530508
def test_reload_missing_w_implicit_connection(self):
531509
# https://github.com/GoogleCloudPlatform/gcloud-python/issues/652
532510
from gcloud.storage._testing import _monkey_defaults
533511
ROLE = 'role'
534512
connection = _Connection({})
535513
acl = self._makeOne()
536-
acl._reload_path = '/testing/acl'
514+
acl.reload_path = '/testing/acl'
537515
acl.loaded = True
538516
acl.entity('allUsers', ROLE)
539517
with _monkey_defaults(connection=connection):
@@ -549,7 +527,7 @@ def test_reload_missing_w_explicit_connection(self):
549527
ROLE = 'role'
550528
connection = _Connection({})
551529
acl = self._makeOne()
552-
acl._reload_path = '/testing/acl'
530+
acl.reload_path = '/testing/acl'
553531
acl.loaded = True
554532
acl.entity('allUsers', ROLE)
555533
acl.reload(connection=connection)
@@ -564,7 +542,7 @@ def test_reload_empty_result_clears_local_w_implicit_connection(self):
564542
ROLE = 'role'
565543
connection = _Connection({'items': []})
566544
acl = self._makeOne()
567-
acl._reload_path = '/testing/acl'
545+
acl.reload_path = '/testing/acl'
568546
acl.loaded = True
569547
acl.entity('allUsers', ROLE)
570548
with _monkey_defaults(connection=connection):
@@ -580,7 +558,7 @@ def test_reload_empty_result_clears_local_w_explicit_connection(self):
580558
ROLE = 'role'
581559
connection = _Connection({'items': []})
582560
acl = self._makeOne()
583-
acl._reload_path = '/testing/acl'
561+
acl.reload_path = '/testing/acl'
584562
acl.loaded = True
585563
acl.entity('allUsers', ROLE)
586564
acl.reload(connection=connection)
@@ -597,7 +575,7 @@ def test_reload_nonempty_result_w_implicit_connection(self):
597575
connection = _Connection(
598576
{'items': [{'entity': 'allUsers', 'role': ROLE}]})
599577
acl = self._makeOne()
600-
acl._reload_path = '/testing/acl'
578+
acl.reload_path = '/testing/acl'
601579
acl.loaded = True
602580
with _monkey_defaults(connection=connection):
603581
acl.reload()
@@ -613,7 +591,7 @@ def test_reload_nonempty_result_w_explicit_connection(self):
613591
connection = _Connection(
614592
{'items': [{'entity': 'allUsers', 'role': ROLE}]})
615593
acl = self._makeOne()
616-
acl._reload_path = '/testing/acl'
594+
acl.reload_path = '/testing/acl'
617595
acl.loaded = True
618596
acl.reload(connection=connection)
619597
self.assertTrue(acl.loaded)
@@ -623,17 +601,12 @@ def test_reload_nonempty_result_w_explicit_connection(self):
623601
self.assertEqual(kw[0]['method'], 'GET')
624602
self.assertEqual(kw[0]['path'], '/testing/acl')
625603

626-
def test_save_wo_path_raises_NotImplementedError(self):
627-
acl = self._makeOne()
628-
acl.loaded = True
629-
self.assertRaises(NotImplementedError, acl.save)
630-
631604
def test_save_none_set_none_passed_w_implicit_connection(self):
632605
from gcloud.storage._testing import _monkey_defaults
633606
connection = _Connection()
634607
acl = self._makeOne()
635608
acl._connection = connection
636-
acl._save_path = '/testing'
609+
acl.save_path = '/testing'
637610
with _monkey_defaults(connection=connection):
638611
acl.save()
639612
kw = connection._requested
@@ -642,7 +615,7 @@ def test_save_none_set_none_passed_w_implicit_connection(self):
642615
def test_save_none_set_none_passed_w_explicit_connection(self):
643616
connection = _Connection()
644617
acl = self._makeOne()
645-
acl._save_path = '/testing'
618+
acl.save_path = '/testing'
646619
acl.save(connection=connection)
647620
kw = connection._requested
648621
self.assertEqual(len(kw), 0)
@@ -651,7 +624,7 @@ def test_save_existing_missing_none_passed_w_implicit_connection(self):
651624
from gcloud.storage._testing import _monkey_defaults
652625
connection = _Connection({})
653626
acl = self._makeOne()
654-
acl._save_path = '/testing'
627+
acl.save_path = '/testing'
655628
acl.loaded = True
656629
with _monkey_defaults(connection=connection):
657630
acl.save()
@@ -666,7 +639,7 @@ def test_save_existing_missing_none_passed_w_implicit_connection(self):
666639
def test_save_existing_missing_none_passed_w_explicit_connection(self):
667640
connection = _Connection({})
668641
acl = self._makeOne()
669-
acl._save_path = '/testing'
642+
acl.save_path = '/testing'
670643
acl.loaded = True
671644
acl.save(connection=connection)
672645
self.assertEqual(list(acl), [])
@@ -683,7 +656,7 @@ def test_save_no_arg_w_implicit_connection(self):
683656
AFTER = [{'entity': 'allUsers', 'role': ROLE}]
684657
connection = _Connection({'acl': AFTER})
685658
acl = self._makeOne()
686-
acl._save_path = '/testing'
659+
acl.save_path = '/testing'
687660
acl.loaded = True
688661
acl.entity('allUsers').grant(ROLE)
689662
with _monkey_defaults(connection=connection):
@@ -701,7 +674,7 @@ def test_save_no_arg_w_explicit_connection(self):
701674
AFTER = [{'entity': 'allUsers', 'role': ROLE}]
702675
connection = _Connection({'acl': AFTER})
703676
acl = self._makeOne()
704-
acl._save_path = '/testing'
677+
acl.save_path = '/testing'
705678
acl.loaded = True
706679
acl.entity('allUsers').grant(ROLE)
707680
acl.save(connection=connection)
@@ -721,7 +694,7 @@ def test_save_w_arg_w_implicit_connection(self):
721694
new_acl = [{'entity': 'allUsers', 'role': ROLE1}]
722695
connection = _Connection({'acl': [STICKY] + new_acl})
723696
acl = self._makeOne()
724-
acl._save_path = '/testing'
697+
acl.save_path = '/testing'
725698
acl.loaded = True
726699
with _monkey_defaults(connection=connection):
727700
acl.save(new_acl)
@@ -743,7 +716,7 @@ def test_save_w_arg_w_explicit_connection(self):
743716
new_acl = [{'entity': 'allUsers', 'role': ROLE1}]
744717
connection = _Connection({'acl': [STICKY] + new_acl})
745718
acl = self._makeOne()
746-
acl._save_path = '/testing'
719+
acl.save_path = '/testing'
747720
acl.loaded = True
748721
acl.save(new_acl, connection)
749722
entries = list(acl)
@@ -764,7 +737,7 @@ def test_clear_w_implicit_connection(self):
764737
STICKY = {'entity': 'allUsers', 'role': ROLE2}
765738
connection = _Connection({'acl': [STICKY]})
766739
acl = self._makeOne()
767-
acl._save_path = '/testing'
740+
acl.save_path = '/testing'
768741
acl.loaded = True
769742
acl.entity('allUsers', ROLE1)
770743
with _monkey_defaults(connection=connection):
@@ -783,7 +756,7 @@ def test_clear_w_explicit_connection(self):
783756
STICKY = {'entity': 'allUsers', 'role': ROLE2}
784757
connection = _Connection({'acl': [STICKY]})
785758
acl = self._makeOne()
786-
acl._save_path = '/testing'
759+
acl.save_path = '/testing'
787760
acl.loaded = True
788761
acl.entity('allUsers', ROLE1)
789762
acl.clear(connection=connection)

0 commit comments

Comments
 (0)