Skip to content

Commit 1bdf370

Browse files
committed
Add near_limit function
1 parent 3bc8126 commit 1bdf370

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

validatedfile/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def exceeds(self, size = 0):
5454
else:
5555
return False
5656

57+
def near_limit(self):
58+
return (float(self.current_usage) / float(self.max_usage)) > 0.8
59+
5760

5861
class QuotaValidator(object):
5962

validatedfile/tests/__init__.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,44 @@ def test_quota_exceeds(self):
187187
container.delete()
188188

189189

190+
def test_quota_near_limit(self):
191+
quota = FileQuota(max_usage = 6500)
192+
193+
container = self._create_container(name = 'container1')
194+
quota.update(container.test_elements.all(), 'the_file')
195+
self.assertEqual(quota.current_usage, 0)
196+
self.assertFalse(quota.near_limit())
197+
198+
element1 = self._add_element(container = container,
199+
orig_filename = 'image2k.png',
200+
dest_filename = 'the_file.png')
201+
quota.update(container.test_elements.all(), 'the_file')
202+
self.assertEqual(quota.current_usage, 2120)
203+
self.assertFalse(quota.near_limit())
204+
205+
element2 = self._add_element(container = container,
206+
orig_filename = 'image2k.png',
207+
dest_filename = 'the_file.png')
208+
quota.update(container.test_elements.all(), 'the_file')
209+
self.assertEqual(quota.current_usage, 4240)
210+
self.assertFalse(quota.near_limit())
211+
212+
element3 = self._add_element(container = container,
213+
orig_filename = 'image2k.png',
214+
dest_filename = 'the_file.png')
215+
quota.update(container.test_elements.all(), 'the_file')
216+
self.assertEqual(quota.current_usage, 6360)
217+
self.assertTrue(quota.near_limit())
218+
219+
element1.the_file.delete()
220+
element2.the_file.delete()
221+
element3.the_file.delete()
222+
element1.delete()
223+
element2.delete()
224+
element3.delete()
225+
container.delete()
226+
227+
190228
def test_form_quota_check(self):
191229
container = self._create_container(name = 'container1')
192230

0 commit comments

Comments
 (0)