Skip to content

Commit

Permalink
Merge pull request #3 from gforcada/master
Browse files Browse the repository at this point in the history
Remove old scales upon image update
  • Loading branch information
vangheem committed Nov 15, 2013
2 parents 22142af + 8163ab4 commit 78b9a34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions plone/scale/storage.py
Expand Up @@ -62,6 +62,7 @@ def scale(self, factory=None, **parameters):
info = storage.get(key)
modified = self.modified and self.modified()
if info is not None and modified > info['modified']:
del storage[info['uid']]
info = None # invalidate when the image was updated
if info is None and factory:
result = factory(**parameters)
Expand Down
12 changes: 12 additions & 0 deletions plone/scale/tests/test_storage.py
Expand Up @@ -105,6 +105,18 @@ def testDeleteRemovesItemAndIndex(self):
del storage[scale['uid']]
self.assertEqual(len(storage), 0)

def testCleanUpOldItems(self):
storage = self.storage
scale_old = storage.scale(factory=self.factory, foo=23, bar=42)
next_modified = storage.modified() + 1
storage.modified = lambda: next_modified
scale_new = storage.scale(factory=self.factory, foo=23, bar=42)
self.assertEqual(len(storage), 2)
self.assertEqual(scale_new['uid'] in storage, True)
self.assertEqual(scale_old['uid'] in storage, False)
del storage[scale_new['uid']]
self.assertEqual(len(storage), 0)


def test_suite():
from unittest import defaultTestLoader
Expand Down

1 comment on commit 78b9a34

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS FAILED
Mr.roboto url : http://jenkins.plone.org/roboto/get_info?push=5f9f3818678d458fbbf436cd0f5bd016
kgs-plone.scale-plone-5.0-python-2.7 kgs [FAILURE]
kgs-plone.scale-plone-4.3-python-2.6 kgs [SUCCESS]
kgs-plone.scale-plone-4.3-python-2.7 kgs [FAILURE]

Please sign in to comment.