Revision d551c841 snf-quotaholder-app/quotaholder_django/test/simpletests.py
b/snf-quotaholder-app/quotaholder_django/test/simpletests.py | ||
---|---|---|
338 | 338 |
q0, c0, il0, el0 = self.new_quota(e0, k0, resource) |
339 | 339 |
q1, c1, il1, el1 = self.new_quota(e1, k1, resource) |
340 | 340 |
|
341 |
most = max(0, min(c0, il0, q1, el1)) |
|
341 |
most = min(c0, il0, q1, el1) |
|
342 |
if most < 0: |
|
343 |
raise AssertionError("%s <= 0" % most) |
|
344 |
|
|
342 | 345 |
r = self.qh.issue_commission(clientkey=self.client, target=e0, key=k0, |
343 | 346 |
name='something', |
344 | 347 |
provisions=[(e1, resource, most)]) |
... | ... | |
531 | 534 |
r = self.qh.get_holding(get_holding=[(e1, resource, k1)]) |
532 | 535 |
self.assertEqual(r, [(e1, resource, p) + counters + (f,)]) |
533 | 536 |
|
537 |
def test_015_release_nocapacity(self): |
|
538 |
qh = self.qh |
|
539 |
key = "key" |
|
540 |
owner = "system" |
|
541 |
owner_key = "" |
|
542 |
source = "test_015_release_nocapacity_source" |
|
543 |
resource = "resource" |
|
544 |
target = "test_015_release_nocapacity_target" |
|
545 |
flags = 0 |
|
546 |
source_create = [source, owner, key, owner_key] |
|
547 |
source_limits = [source, 6, 0, 1000, 1000] |
|
548 |
source_holding = [source, resource, key, source, flags] |
|
549 |
target_create = [target, owner, key, owner_key] |
|
550 |
target_limits = [target, 0, 5, 1000, 1000] |
|
551 |
target_holding = [target, resource, key, target, flags] |
|
552 |
|
|
553 |
failed = AssertionError("Quotaholder call failed") |
|
554 |
if qh.create_entity(create_entity=[source_create, target_create]): |
|
555 |
raise failed |
|
556 |
if qh.set_limits(set_limits=[source_limits, target_limits]): |
|
557 |
raise failed |
|
558 |
if qh.set_holding(set_holding=[source_holding, target_holding]): |
|
559 |
raise failed |
|
560 |
|
|
561 |
serial = qh.issue_commission(clientkey=self.client, target=target, key=key, |
|
562 |
name="something", provisions=[(source, resource, 5)]) |
|
563 |
qh.accept_commission(clientkey=self.client, serials=[serial]) |
|
564 |
|
|
565 |
holding = qh.get_holding(get_holding=[[source, resource, key]]) |
|
566 |
self.assertEqual(tuple(holding[0]), (source, resource, source, 0, 5, 0, 0, flags)) |
|
567 |
holding = qh.get_holding(get_holding=[[target, resource, key]]) |
|
568 |
self.assertEqual(tuple(holding[0]), (target, resource, target, 5, 0, 0, 0, flags)) |
|
569 |
|
|
570 |
if qh.reset_holding(reset_holding=[[target, resource, key, 10, 0, 0, 0]]): |
|
571 |
raise failed |
|
572 |
|
|
573 |
with self.assertRaises(NoCapacityError): |
|
574 |
qh.issue_commission(clientkey=self.client, target=target, key=key, |
|
575 |
name="something", provisions=[(source, resource, 1)]) |
|
576 |
|
|
577 |
with self.assertRaises(NoQuantityError): |
|
578 |
qh.issue_commission(clientkey=self.client, target=target, key=key, |
|
579 |
name="something", provisions=[(source, resource, -7)]) |
|
580 |
|
|
581 |
source_limits = [source, 6, 10, 1000, 1000] |
|
582 |
if qh.set_limits(set_limits=[source_limits]): |
|
583 |
raise failed |
|
584 |
|
|
585 |
serial = qh.issue_commission(clientkey=self.client, target=target, key=key, |
|
586 |
name="something", provisions=[(source, resource, -1)]) |
|
587 |
qh.accept_commission(clientkey=self.client, serials=[serial]) |
|
588 |
|
|
589 |
holding = qh.get_holding(get_holding=[[source, resource, key]]) |
|
590 |
self.assertEqual(tuple(holding[0]), (source, resource, source, 0, 5, 1, 0, flags)) |
|
591 |
holding = qh.get_holding(get_holding=[[target, resource, key]]) |
|
592 |
self.assertEqual(tuple(holding[0]), (target, resource, target, 10, 0, 0, 1, flags)) |
|
593 |
|
|
594 |
with self.assertRaises(NoCapacityError): |
|
595 |
qh.issue_commission(clientkey=self.client, target=target, key=key, |
|
596 |
name="something", provisions=[(source, resource, -10)]) |
|
597 |
|
|
534 | 598 |
|
535 | 599 |
if __name__ == "__main__": |
536 | 600 |
import sys |
Also available in: Unified diff