Skip to content

Commit

Permalink
Merge pull request #41 from motivator/pr/40
Browse files Browse the repository at this point in the history
update to pr #40
  • Loading branch information
JeremyGrosser committed Jan 23, 2014
2 parents 1640cf4 + d0b9808 commit 9630ceb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/clusto/schema.py
Expand Up @@ -180,6 +180,11 @@ def next(self):
audit_log.info('increment counter entity=%s attr_key=%s value=%s', self.entity.name, self.attr_key, self.value)
return self.value

def delete(self):
audit_log.info('delete counter entity=%s attr_key=%s value=%s', self.entity.name, self.attr_key, self.value)
SESSION.delete(self)
SESSION.flush()

@classmethod
def get(cls, entity, keyname, default=0):

Expand All @@ -192,6 +197,10 @@ def get(cls, entity, keyname, default=0):

return ctr

@classmethod
def query(cls):
return SESSION.query(cls)

class ProtectedObj(object):

## this is a hack to make these objects immutable-ish
Expand Down Expand Up @@ -521,6 +530,10 @@ def __str__(self):

return str(self.name)

@property
def counters(self):
return Counter.query().filter(Counter.entity==self).all()

@property
def attrs(self):
return Attribute.query().filter(Attribute.entity==self).all()
Expand All @@ -546,6 +559,9 @@ def delete(self):
for i in self.attrs:
i.delete()

for i in self.counters:
i.delete()

if SESSION.clusto_versioning_enabled:
self.deleted_at_version = working_version()
else:
Expand Down
16 changes: 16 additions & 0 deletions src/clusto/test/drivers/categories/pooltests.py
Expand Up @@ -231,3 +231,19 @@ def testGetFromPools(self):
self.assertRaises(LookupError,
clusto.get_from_pools, 'p1', 'non-existent-pool')

def testPoolDelete(self):

p5 = Pool('p5')
d1 = clusto.get_by_name('d1')

p5.insert(d1)

clusto.flush()

self.assertTrue(isinstance(clusto.get_by_name('p5'), Pool))

clusto.get_by_name('p5').entity.delete()

clusto.flush()

self.assertRaises(LookupError, clusto.get_by_name, 'p5')

0 comments on commit 9630ceb

Please sign in to comment.