def test_quota_several_files_several_containers(self): container1 = self._create_container(name='container1') element1 = self._add_element(container=container1, orig_filename='image2k.png', dest_filename='the_file1.png') element2 = self._add_element(container=container1, orig_filename='image15k.png', dest_filename='the_file2.png') container2 = self._create_container(name='container2') element3 = self._add_element(container=container2, orig_filename='document15k.pdf', dest_filename='the_file3.pdf') quota = FileQuota(max_usage=20000) quota.update(container1.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 16706) self.assertFalse(quota.exceeds()) element1.the_file.delete() element2.the_file.delete() element3.the_file.delete() element1.delete() element2.delete() element3.delete() container1.delete() container2.delete()
def test_quota_several_files_several_containers(self): container1 = self._create_container(name = 'container1') element1 = self._add_element(container = container1, orig_filename = 'image2k.png', dest_filename = 'the_file1.png') element2 = self._add_element(container = container1, orig_filename = 'image15k.png', dest_filename = 'the_file2.png') container2 = self._create_container(name = 'container2') element3 = self._add_element(container = container2, orig_filename = 'document15k.pdf', dest_filename = 'the_file3.pdf') quota = FileQuota(max_usage = 20000) quota.update(container1.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 16706) self.assertFalse(quota.exceeds()) element1.the_file.delete() element2.the_file.delete() element3.the_file.delete() element1.delete() element2.delete() element3.delete() container1.delete() container2.delete()
def test_quota_empty(self): container = self._create_container(name = 'container1') quota = FileQuota() quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 0) self.assertFalse(quota.exceeds()) container.delete()
def test_quota_empty(self): container = self._create_container(name='container1') quota = FileQuota() quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 0) self.assertFalse(quota.exceeds()) container.delete()
def test_quota_one_file(self): container = self._create_container(name = 'container') element = self._add_element(container = container, orig_filename = 'image2k.png', dest_filename = 'the_file.png') quota = FileQuota() quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 2120) self.assertFalse(quota.exceeds()) element.the_file.delete() element.delete() container.delete()
def test_quota_one_file(self): container = self._create_container(name='container') element = self._add_element(container=container, orig_filename='image2k.png', dest_filename='the_file.png') quota = FileQuota() quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 2120) self.assertFalse(quota.exceeds()) element.the_file.delete() element.delete() container.delete()
def test_quota_near_limit(self): quota = FileQuota(max_usage = 6500) container = self._create_container(name = 'container1') quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 0) self.assertFalse(quota.near_limit()) element1 = self._add_element(container = container, orig_filename = 'image2k.png', dest_filename = 'the_file.png') quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 2120) self.assertFalse(quota.near_limit()) element2 = self._add_element(container = container, orig_filename = 'image2k.png', dest_filename = 'the_file.png') quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 4240) self.assertFalse(quota.near_limit()) element3 = self._add_element(container = container, orig_filename = 'image2k.png', dest_filename = 'the_file.png') quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 6360) self.assertTrue(quota.near_limit()) element1.the_file.delete() element2.the_file.delete() element3.the_file.delete() element1.delete() element2.delete() element3.delete() container.delete()
def test_quota_near_limit(self): quota = FileQuota(max_usage=6500) container = self._create_container(name='container1') quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 0) self.assertFalse(quota.near_limit()) element1 = self._add_element(container=container, orig_filename='image2k.png', dest_filename='the_file.png') quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 2120) self.assertFalse(quota.near_limit()) element2 = self._add_element(container=container, orig_filename='image2k.png', dest_filename='the_file.png') quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 4240) self.assertFalse(quota.near_limit()) element3 = self._add_element(container=container, orig_filename='image2k.png', dest_filename='the_file.png') quota.update(container.test_elements.all(), 'the_file') self.assertEqual(quota.current_usage, 6360) self.assertTrue(quota.near_limit()) element1.the_file.delete() element2.the_file.delete() element3.the_file.delete() element1.delete() element2.delete() element3.delete() container.delete()