Revision 6e4e100b snf-quotaholder-app/quotaholder_django/test/simpletests.py

b/snf-quotaholder-app/quotaholder_django/test/simpletests.py
1
# Copyright 2012 GRNET S.A. All rights reserved.
1
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
2 2
#
3 3
# Redistribution and use in source and binary forms, with or
4 4
# without modification, are permitted provided that the following
......
370 370
        self.new_quota(et1, kt1, resource, (0, 15, 3, 20))
371 371
        self.new_quota(et2, kt2, resource, (0, 15, 20, 20))
372 372

  
373
        try:
373
        with self.assertRaises(NoQuantityError) as cm:
374 374
            self.qh.issue_commission(clientkey=self.client, target=et1, key=kt1,
375 375
                                     name='something',
376 376
                                     provisions=[(es1, resource, 12)])
377
        except NoQuantityError, e:
378
            self.assertEqual(e.source, es1)
379
            self.assertEqual(e.target, et1)
380
            self.assertEqual(e.resource, resource)
381
            self.assertEqual(e.limit, 10)
382
            self.assertEqual(e.requested, 12)
383
            self.assertEqual(e.current, 0)
384

  
385
            r = self.qh.issue_commission(clientkey=self.client, target=et1,
386
                                         key=kt1,
387
                                         name='something',
388
                                         provisions=[(es1, resource, 2)])
389
            self.assertGreater(r, 0)
390

  
391
        try:
377
        e = cm.exception
378
        self.assertEqual(e.source, es1)
379
        self.assertEqual(e.target, et1)
380
        self.assertEqual(e.resource, resource)
381
        self.assertEqual(int(e.limit), 10)
382
        self.assertEqual(int(e.requested), 12)
383
        self.assertEqual(int(e.current), 0)
384

  
385
        r = self.qh.issue_commission(clientkey=self.client, target=et1,
386
                                     key=kt1,
387
                                     name='something',
388
                                     provisions=[(es1, resource, 2)])
389
        self.assertGreater(r, 0)
390

  
391
        with self.assertRaises(ImportLimitError) as cm:
392 392
            self.qh.issue_commission(clientkey=self.client, target=et1, key=kt1,
393 393
                                     name='something',
394 394
                                     provisions=[(es1, resource, 2)])
395
        except ImportLimitError, e:
396
            self.assertEqual(e.source, es1)
397
            self.assertEqual(e.target, et1)
398
            self.assertEqual(e.resource, resource)
399
            self.assertEqual(e.limit, 3)
400
            self.assertEqual(e.requested, 2)
401
            self.assertEqual(e.current, 2)
402

  
403
            r = self.qh.issue_commission(clientkey=self.client, target=et2,
404
                                         key=kt2,
405
                                         name='something',
406
                                         provisions=[(es2, resource, 9)])
407
            self.assertGreater(r, 0)
408

  
409
        try:
395
        e = cm.exception
396
        self.assertEqual(e.source, es1)
397
        self.assertEqual(e.target, et1)
398
        self.assertEqual(e.resource, resource)
399
        self.assertEqual(int(e.limit), 3)
400
        self.assertEqual(int(e.requested), 2)
401
        self.assertEqual(int(e.current), 2)
402

  
403
        r = self.qh.issue_commission(clientkey=self.client, target=et2,
404
                                     key=kt2,
405
                                     name='something',
406
                                     provisions=[(es2, resource, 9)])
407
        self.assertGreater(r, 0)
408

  
409
        with self.assertRaises(NoCapacityError) as cm:
410 410
            self.qh.issue_commission(clientkey=self.client, target=et2,
411 411
                                     key=kt2,
412 412
                                     name='something',
413 413
                                     provisions=[(es2, resource, 1),
414
                                                 (es1, resource, 2)])
415
        except NoCapacityError, e:
416
            self.assertEqual(e.source, es1)
417
            self.assertEqual(e.target, et2)
418
            self.assertEqual(e.resource, resource)
419
            self.assertEqual(e.limit, 10)
420
            self.assertEqual(e.requested, 2)
421
            # 9 actual + 1 from the first provision
422
            self.assertEqual(e.current, 10)
414
                                                 (es1, resource, 6)])
415
        e = cm.exception
416
        self.assertEqual(e.source, es1)
417
        self.assertEqual(e.target, et2)
418
        self.assertEqual(e.resource, resource)
419
        self.assertEqual(int(e.limit), 15)
420
        self.assertEqual(int(e.requested), 6)
421
        # 9 actual + 1 from the first provision
422
        self.assertEqual(int(e.current), 10)
423 423

  
424 424

  
425 425
    def test_010_list_holdings(self):

Also available in: Unified diff