Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
1a1571db
Commit
1a1571db
authored
Mar 29, 2013
by
Christos Stavrakakis
Browse files
Simple tests for synnefo.quotas
parent
ab896c50
Changes
3
Hide whitespace changes
Inline
Side-by-side
snf-cyclades-app/synnefo/db/models_factory.py
View file @
1a1571db
...
...
@@ -192,3 +192,7 @@ class MacPrefixPoolTableFactory(factory.Factory):
FACTORY_FOR
=
models
.
MacPrefixPoolTable
size
=
100
base
=
'aa:00:0'
class
QuotaHolderSerialFactory
(
factory
.
Factory
):
FACTORY_FOR
=
models
.
QuotaHolderSerial
snf-cyclades-app/synnefo/quotas/models.py
0 → 100644
View file @
1a1571db
snf-cyclades-app/synnefo/quotas/tests.py
0 → 100644
View file @
1a1571db
#!/usr/bin/env python
#
# -*- coding: utf-8 -*-
#
# Copyright 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
#
#
from
mock
import
patch
from
django.test
import
TestCase
from
synnefo.db
import
models_factory
as
mfactory
from
synnefo
import
quotas
from
synnefo.quotas
import
util
class
GetDBHoldingsTestCase
(
TestCase
):
def
test_no_holdings
(
self
):
users
=
[
"dummy_user1"
,
"dummy_user2"
]
holdings
=
util
.
get_db_holdings
(
users
=
users
)
self
.
assertEqual
(
holdings
,
{})
def
test_vm_holdings
(
self
):
flavor
=
mfactory
.
FlavorFactory
(
cpu
=
24
,
ram
=
8192
,
disk
=
20
,
disk_template
=
'drbd'
)
mfactory
.
VirtualMachineFactory
()
mfactory
.
VirtualMachineFactory
(
flavor
=
flavor
,
userid
=
"user1"
)
user_holdings
=
{
"user1"
:
{
"vm"
:
1
,
"cpu"
:
24
,
"disk"
:
21474836480
,
"ram"
:
8589934592
}}
holdings
=
util
.
get_db_holdings
(
users
=
[
"user1"
])
self
.
assertEqual
(
holdings
,
user_holdings
)
holdings
=
util
.
get_db_holdings
()
self
.
assertEqual
(
holdings
[
"user1"
],
user_holdings
[
"user1"
])
def
test_network_holdings
(
self
):
mfactory
.
NetworkFactory
(
userid
=
"user1"
)
mfactory
.
NetworkFactory
(
userid
=
"user2"
)
user_holdings
=
{
"user2"
:
{
"network.private"
:
1
}}
holdings
=
util
.
get_db_holdings
(
users
=
[
"user2"
])
self
.
assertEqual
(
holdings
,
user_holdings
)
holdings
=
util
.
get_db_holdings
()
self
.
assertEqual
(
holdings
[
"user2"
],
user_holdings
[
"user2"
])
@
patch
(
"synnefo.quotas.get_quotaholder_pending"
)
class
ResolvePendingTestCase
(
TestCase
):
def
setUp
(
self
):
self
.
p1
=
mfactory
.
QuotaHolderSerialFactory
(
serial
=
20
,
pending
=
True
)
self
.
p1
=
mfactory
.
QuotaHolderSerialFactory
(
serial
=
30
,
pending
=
True
)
self
.
a1
=
mfactory
.
QuotaHolderSerialFactory
(
serial
=
15
,
accepted
=
True
)
self
.
a2
=
mfactory
.
QuotaHolderSerialFactory
(
serial
=
25
,
accepted
=
True
)
self
.
r1
=
mfactory
.
QuotaHolderSerialFactory
(
serial
=
18
,
rejected
=
True
)
self
.
r2
=
mfactory
.
QuotaHolderSerialFactory
(
serial
=
23
,
rejected
=
True
)
def
test_no_pending
(
self
,
qh
):
qh
.
return_value
=
[]
pending
=
quotas
.
resolve_pending_commissions
()
self
.
assertEqual
(
pending
,
([],
[]))
def
test_1
(
self
,
qh
):
qh
.
return_value
=
[
21
,
25
,
28
]
pending
=
quotas
.
resolve_pending_commissions
()
self
.
assertEqual
(
pending
,
([
25
],
[
28
,
21
]))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment