Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_quota(self):
self.assertEqual(_parse_quota([]), [])
self.assertEqual(
_parse_quota([b'"User quota" (STORAGE 586720 4882812)']),
[Quota('User quota', 'STORAGE', 586720, 4882812)]
)
self.assertEqual(
_parse_quota([
b'"User quota" (STORAGE 586720 4882812)',
b'"Global quota" (MESSAGES 42 1000)'
]),
[
Quota('User quota', 'STORAGE', 586720, 4882812),
Quota('Global quota', 'MESSAGES', 42, 1000)
]
)
self.assertEqual(
_parse_quota([
b'"User quota" (STORAGE 586720 4882812 MESSAGES 42 1000)',
]),
[
Quota('User quota', 'STORAGE', 586720, 4882812),
Quota('User quota', 'MESSAGES', 42, 1000)
]
_parse_quota([
b'"User quota" (STORAGE 586720 4882812)',
b'"Global quota" (MESSAGES 42 1000)'
]),
[
Quota('User quota', 'STORAGE', 586720, 4882812),
Quota('Global quota', 'MESSAGES', 42, 1000)
]
)
self.assertEqual(
_parse_quota([
b'"User quota" (STORAGE 586720 4882812 MESSAGES 42 1000)',
]),
[
Quota('User quota', 'STORAGE', 586720, 4882812),
Quota('User quota', 'MESSAGES', 42, 1000)
]
def test_parse_quota(self):
self.assertEqual(_parse_quota([]), [])
self.assertEqual(
_parse_quota([b'"User quota" (STORAGE 586720 4882812)']),
[Quota('User quota', 'STORAGE', 586720, 4882812)]
)
self.assertEqual(
_parse_quota([
b'"User quota" (STORAGE 586720 4882812)',
b'"Global quota" (MESSAGES 42 1000)'
]),
[
Quota('User quota', 'STORAGE', 586720, 4882812),
Quota('Global quota', 'MESSAGES', 42, 1000)
]
)
self.assertEqual(
_parse_quota([
b'"User quota" (STORAGE 586720 4882812 MESSAGES 42 1000)',
]),
[
def test__get_quota(self):
self.client._command_and_check = Mock()
self.client._command_and_check.return_value = (
[b'"User quota" (MESSAGES 42 1000)']
)
quotas = self.client._get_quota('foo')
self.client._command_and_check.assert_called_once_with(
'getquota', '"foo"'
)
self.assertEqual(quotas, [Quota('User quota', 'MESSAGES', 42, 1000)])
def test_set_quota(self):
self.client._raw_command_untagged = Mock()
self.client._raw_command_untagged.return_value = (
[b'"User quota" (STORAGE 42 1000 MESSAGES 42 1000)']
)
quotas = [
Quota('User quota', 'STORAGE', 42, 1000),
Quota('User quota', 'MESSAGES', 42, 1000)
]
resp = self.client.set_quota(quotas)
self.client._raw_command_untagged.assert_called_once_with(
b'SETQUOTA', [b'"User quota"', b'(STORAGE 1000 MESSAGES 1000)'],
uid=False, response_name='QUOTA'
)
self.assertListEqual(resp, quotas)
def test_set_quota(self):
self.client._raw_command_untagged = Mock()
self.client._raw_command_untagged.return_value = (
[b'"User quota" (STORAGE 42 1000 MESSAGES 42 1000)']
)
quotas = [
Quota('User quota', 'STORAGE', 42, 1000),
Quota('User quota', 'MESSAGES', 42, 1000)
]
resp = self.client.set_quota(quotas)
self.client._raw_command_untagged.assert_called_once_with(
b'SETQUOTA', [b'"User quota"', b'(STORAGE 1000 MESSAGES 1000)'],
uid=False, response_name='QUOTA'
)
self.assertListEqual(resp, quotas)
def _parse_quota(quota_rep):
quota_rep = parse_response(quota_rep)
rv = list()
for quota_root, quota_resource_infos in as_pairs(quota_rep):
for quota_resource_info in as_triplets(quota_resource_infos):
rv.append(Quota(
quota_root=to_unicode(quota_root),
resource=to_unicode(quota_resource_info[0]),
usage=quota_resource_info[1],
limit=quota_resource_info[2]
))
return rv