root / snf-cyclades-app / synnefo / quotas / tests.py @ 62c86226
History | View | Annotate | Download (3.9 kB)
1 |
#!/usr/bin/env python
|
---|---|
2 |
#
|
3 |
# -*- coding: utf-8 -*-
|
4 |
#
|
5 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
6 |
#
|
7 |
# Redistribution and use in source and binary forms, with or
|
8 |
# without modification, are permitted provided that the following
|
9 |
# conditions are met:
|
10 |
#
|
11 |
# 1. Redistributions of source code must retain the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer.
|
14 |
#
|
15 |
# 2. Redistributions in binary form must reproduce the above
|
16 |
# copyright notice, this list of conditions and the following
|
17 |
# disclaimer in the documentation and/or other materials
|
18 |
# provided with the distribution.
|
19 |
#
|
20 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
21 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
23 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
24 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
27 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
28 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
29 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
30 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31 |
# POSSIBILITY OF SUCH DAMAGE.
|
32 |
#
|
33 |
# The views and conclusions contained in the software and
|
34 |
# documentation are those of the authors and should not be
|
35 |
# interpreted as representing official policies, either expressed
|
36 |
# or implied, of GRNET S.A.
|
37 |
#
|
38 |
#
|
39 |
from mock import patch |
40 |
from django.test import TestCase |
41 |
from synnefo.db import models_factory as mfactory |
42 |
|
43 |
from synnefo import quotas |
44 |
from synnefo.quotas import util |
45 |
|
46 |
|
47 |
class GetDBHoldingsTestCase(TestCase): |
48 |
def test_no_holdings(self): |
49 |
holdings = util.get_db_holdings(user=None)
|
50 |
self.assertEqual(holdings, {})
|
51 |
|
52 |
def test_vm_holdings(self): |
53 |
flavor = mfactory.FlavorFactory(cpu=24, ram=8192, disk=20, |
54 |
disk_template='drbd')
|
55 |
mfactory.VirtualMachineFactory() |
56 |
mfactory.VirtualMachineFactory(flavor=flavor, userid="user1")
|
57 |
user_holdings = {"user1": {"cyclades.vm": 1, |
58 |
"cyclades.cpu": 24, |
59 |
"cyclades.disk": 21474836480, |
60 |
"cyclades.ram": 8589934592}} |
61 |
holdings = util.get_db_holdings(user="user1")
|
62 |
self.assertEqual(holdings, user_holdings)
|
63 |
holdings = util.get_db_holdings() |
64 |
self.assertEqual(holdings["user1"], user_holdings["user1"]) |
65 |
|
66 |
def test_network_holdings(self): |
67 |
mfactory.NetworkFactory(userid="user1")
|
68 |
mfactory.NetworkFactory(userid="user2")
|
69 |
user_holdings = {"user2": {"cyclades.network.private": 1}} |
70 |
holdings = util.get_db_holdings(user="user2")
|
71 |
self.assertEqual(holdings, user_holdings)
|
72 |
holdings = util.get_db_holdings() |
73 |
self.assertEqual(holdings["user2"], user_holdings["user2"]) |
74 |
|
75 |
|
76 |
@patch("synnefo.quotas.get_quotaholder_pending") |
77 |
class ResolvePendingTestCase(TestCase): |
78 |
def setUp(self): |
79 |
self.p1 = mfactory.QuotaHolderSerialFactory(serial=20, pending=True) |
80 |
self.p1 = mfactory.QuotaHolderSerialFactory(serial=30, pending=True) |
81 |
self.a1 = mfactory.QuotaHolderSerialFactory(serial=15, accepted=True) |
82 |
self.a2 = mfactory.QuotaHolderSerialFactory(serial=25, accepted=True) |
83 |
self.r1 = mfactory.QuotaHolderSerialFactory(serial=18, rejected=True) |
84 |
self.r2 = mfactory.QuotaHolderSerialFactory(serial=23, rejected=True) |
85 |
|
86 |
def test_no_pending(self, qh): |
87 |
qh.return_value = [] |
88 |
pending = quotas.resolve_pending_commissions() |
89 |
self.assertEqual(pending, ([], []))
|
90 |
|
91 |
def test_1(self, qh): |
92 |
qh.return_value = [21, 25, 28] |
93 |
pending = quotas.resolve_pending_commissions() |
94 |
self.assertEqual(pending, ([25], [28, 21])) |