Example #1
0
 def test_get_entity_miss_entity_no_default(self):
     from google.cloud.storage.acl import _ACLEntity
     TYPE = 'type'
     ID = 'id'
     entity = _ACLEntity(TYPE, ID)
     acl = self._makeOne()
     acl.loaded = True
     self.assertEqual(acl.get_entity(entity), None)
 def test_get_entity_miss_entity_no_default(self):
     from google.cloud.storage.acl import _ACLEntity
     TYPE = 'type'
     ID = 'id'
     entity = _ACLEntity(TYPE, ID)
     acl = self._makeOne()
     acl.loaded = True
     self.assertIsNone(acl.get_entity(entity))
Example #3
0
 def test_has_entity_miss_entity(self):
     from google.cloud.storage.acl import _ACLEntity
     TYPE = 'type'
     ID = 'id'
     entity = _ACLEntity(TYPE, ID)
     acl = self._makeOne()
     acl.loaded = True
     self.assertFalse(acl.has_entity(entity))
 def test_has_entity_miss_entity(self):
     from google.cloud.storage.acl import _ACLEntity
     TYPE = 'type'
     ID = 'id'
     entity = _ACLEntity(TYPE, ID)
     acl = self._makeOne()
     acl.loaded = True
     self.assertFalse(acl.has_entity(entity))
Example #5
0
 def test_get_entity_miss_entity_w_default(self):
     from google.cloud.storage.acl import _ACLEntity
     DEFAULT = object()
     TYPE = 'type'
     ID = 'id'
     entity = _ACLEntity(TYPE, ID)
     acl = self._makeOne()
     acl.loaded = True
     self.assertTrue(acl.get_entity(entity, DEFAULT) is DEFAULT)
 def test_get_entity_miss_entity_w_default(self):
     from google.cloud.storage.acl import _ACLEntity
     DEFAULT = object()
     TYPE = 'type'
     ID = 'id'
     entity = _ACLEntity(TYPE, ID)
     acl = self._makeOne()
     acl.loaded = True
     self.assertIs(acl.get_entity(entity, DEFAULT), DEFAULT)
 def test_add_entity_miss_eager(self):
     from google.cloud.storage.acl import _ACLEntity
     TYPE = 'type'
     ID = 'id'
     ROLE = 'role'
     entity = _ACLEntity(TYPE, ID)
     entity.grant(ROLE)
     acl = self._makeOne()
     acl.loaded = True
     acl.add_entity(entity)
     self.assertTrue(acl.loaded)
     self.assertEqual(list(acl), [{'entity': 'type-id', 'role': ROLE}])
     self.assertEqual(list(acl.get_entities()), [entity])
Example #8
0
 def test_add_entity_miss_eager(self):
     from google.cloud.storage.acl import _ACLEntity
     TYPE = 'type'
     ID = 'id'
     ROLE = 'role'
     entity = _ACLEntity(TYPE, ID)
     entity.grant(ROLE)
     acl = self._makeOne()
     acl.loaded = True
     acl.add_entity(entity)
     self.assertTrue(acl.loaded)
     self.assertEqual(list(acl),
                      [{'entity': 'type-id', 'role': ROLE}])
     self.assertEqual(list(acl.get_entities()), [entity])
Example #9
0
    def test_add_entity_miss_eager(self):
        from google.cloud.storage.acl import _ACLEntity

        TYPE = "type"
        ID = "id"
        ROLE = "role"
        entity = _ACLEntity(TYPE, ID)
        entity.grant(ROLE)
        acl = self._make_one()
        acl.loaded = True
        acl.add_entity(entity)
        self.assertTrue(acl.loaded)
        self.assertEqual(list(acl), [{"entity": "type-id", "role": ROLE}])
        self.assertEqual(list(acl.get_entities()), [entity])
 def test_add_entity_hit(self):
     from google.cloud.storage.acl import _ACLEntity
     TYPE = 'type'
     ID = 'id'
     ENTITY_VAL = '%s-%s' % (TYPE, ID)
     ROLE = 'role'
     entity = _ACLEntity(TYPE, ID)
     entity.grant(ROLE)
     acl = self._makeOne()
     acl.loaded = True
     before = acl.entity(TYPE, ID)
     acl.add_entity(entity)
     self.assertTrue(acl.loaded)
     self.assertIsNot(acl.get_entity(ENTITY_VAL), before)
     self.assertIs(acl.get_entity(ENTITY_VAL), entity)
     self.assertEqual(list(acl), [{'entity': 'type-id', 'role': ROLE}])
     self.assertEqual(list(acl.get_entities()), [entity])
Example #11
0
 def test_add_entity_hit(self):
     from google.cloud.storage.acl import _ACLEntity
     TYPE = 'type'
     ID = 'id'
     ENTITY_VAL = '%s-%s' % (TYPE, ID)
     ROLE = 'role'
     entity = _ACLEntity(TYPE, ID)
     entity.grant(ROLE)
     acl = self._makeOne()
     acl.loaded = True
     before = acl.entity(TYPE, ID)
     acl.add_entity(entity)
     self.assertTrue(acl.loaded)
     self.assertFalse(acl.get_entity(ENTITY_VAL) is before)
     self.assertTrue(acl.get_entity(ENTITY_VAL) is entity)
     self.assertEqual(list(acl),
                      [{'entity': 'type-id', 'role': ROLE}])
     self.assertEqual(list(acl.get_entities()), [entity])
Example #12
0
    def test_add_entity_hit(self):
        from google.cloud.storage.acl import _ACLEntity

        TYPE = "type"
        ID = "id"
        ENTITY_VAL = "%s-%s" % (TYPE, ID)
        ROLE = "role"
        entity = _ACLEntity(TYPE, ID)
        entity.grant(ROLE)
        acl = self._make_one()
        acl.loaded = True
        before = acl.entity(TYPE, ID)
        acl.add_entity(entity)
        self.assertTrue(acl.loaded)
        self.assertIsNot(acl.get_entity(ENTITY_VAL), before)
        self.assertIs(acl.get_entity(ENTITY_VAL), entity)
        self.assertEqual(list(acl), [{"entity": "type-id", "role": ROLE}])
        self.assertEqual(list(acl.get_entities()), [entity])
Example #13
0
    def test_add_entity_miss_lazy(self):
        from google.cloud.storage.acl import _ACLEntity

        TYPE = "type"
        ID = "id"
        ROLE = "role"
        entity = _ACLEntity(TYPE, ID)
        entity.grant(ROLE)
        acl = self._make_one()

        _reload = FakeReload(acl)
        acl.reload = _reload
        acl.loaded = False

        acl.add_entity(entity)
        self.assertTrue(acl.loaded)
        self.assertEqual(list(acl), [{"entity": "type-id", "role": ROLE}])
        self.assertEqual(list(acl.get_entities()), [entity])
        self.assertTrue(acl.loaded)
        self.assertEqual(_reload.timeouts_used[0], self._get_default_timeout())