Commit e90354cf authored by Christos Stavrakakis's avatar Christos Stavrakakis

Include Pool tests to Django testsuite

parent 48f9d663
......@@ -43,7 +43,7 @@ class PoolManager(object):
def add_padding(self, pool_size):
bits = find_padding(pool_size)
self.available.extend([AVAILABLE] * bits)
self.available.extend([UNAVAILABLE] * bits)
self.reserved.extend([UNAVAILABLE] * bits)
def cut_padding(self, pool_size):
......
import sys
# Copyright 2012 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 django.test import TestCase
from synnefo.db.pools import (PoolManager, EmptyPool, BridgePool,
MacPrefixPool, IPPool)
from bitarray import bitarray
# Use backported unittest functionality if Python < 2.7
try:
import unittest2 as unittest
except ImportError:
if sys.version_info < (2, 7):
raise Exception("The unittest2 package is required for Python < 2.7")
import unittest
class DummyObject():
def __init__(self, size):
......@@ -31,7 +57,7 @@ class DummyPool(PoolManager):
return value
class PoolManagerTestCase(unittest.TestCase):
class PoolManagerTestCase(TestCase):
def test_created_pool(self):
obj = DummyObject(42)
pool = DummyPool(obj)
......@@ -111,7 +137,7 @@ class PoolManagerTestCase(unittest.TestCase):
self.assertEqual(pool.reserved, bitarray('1' * 39 + '0' * 1))
class BridgePoolTestCase(unittest.TestCase):
class BridgePoolTestCase(TestCase):
def test_bridge_conversion(self):
obj = DummyObject(13)
obj.base = "bridge"
......@@ -125,7 +151,7 @@ class BridgePoolTestCase(unittest.TestCase):
self.assertEqual(pool.empty(), True)
class MacPrefixPoolTestCase(unittest.TestCase):
class MacPrefixPoolTestCase(TestCase):
def test_invalid_mac_reservation(self):
obj = DummyObject(65636)
obj.base = 'ab:ff:ff'
......@@ -133,7 +159,8 @@ class MacPrefixPoolTestCase(unittest.TestCase):
for i in range(0, 65536):
self.assertEqual(pool.is_available(i, index=True), False)
class IPPoolTestCase(unittest.TestCase):
class IPPoolTestCase(TestCase):
def test_auto_reservations(self):
obj = DummyObject(0)
network = DummyObject(0)
......@@ -158,7 +185,3 @@ class IPPoolTestCase(unittest.TestCase):
self.assertEqual(pool.is_available('192.168.2.1'), False)
self.assertEqual(pool.size(), 8)
self.assertEqual(pool.empty(), True)
if __name__ == '__main__':
unittest.main()
......@@ -32,9 +32,11 @@
# Provides automated tests for db module
from synnefo.db.models import *
from django.test import TestCase
# Import pool tests
from synnefo.db.pools.tests import *
class FlavorTestCase(TestCase):
fixtures = [ 'db_test_data' ]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment