Changeset 6607


Ignore:
Timestamp:
Jan 15, 2009, 10:53:01 PM (16 years ago)
Author:
roland
Message:

Work in progress.. I am splitting unittests up in multiplefiles, so that they
become more maintainable.

Location:
trunk/exodus/tests
Files:
1 added
2 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/exodus/tests/base.py

    r6606 r6607  
    22
    33class BootstrapTestCase(unittest.TestCase):
     4
    45    def setUp(self):
    56        from django.test.client import Client
     
    1314        from exodus.models import Location
    1415        loc1 = Location.objects.create(description = 'ASW',
    15                 latitude = '15.12345',
    16                 longitude = '16.12345')
     16                latitude = '15.12345', longitude = '16.12345')
    1717        loc2 = Location.objects.create(description = 'Rapenburg',
    18                 latitude = '27.12345',
    19                 longitude = '28.12345')
     18                latitude = '27.12345', longitude = '28.12345')
    2019        loc3 = Location.objects.create(description = 'Lepelenburg',
    21                 latitude = '37.12345',
    22                 longitude = '48.12345')
     20                latitude = '37.12345', longitude = '48.12345')
    2321        loc4 = Location.objects.create(description = 'Neude',
    24                 latitude = '57.12345',
    25                 longitude = '58.12345')
    26         import pdb; pdb.set_trace() ;
     22                latitude = '57.12345', longitude = '58.12345')
     23
     24        # We assume the wleiden.net network is already created via initial_data.
     25        from exodus.models import Network
     26        network = Network.objects.get(pk=1)
     27        # create multiple nodes.
     28        from exodus.models import Node
     29        nod1 = Node.objects.create(name='Roland', location=loc1, status='up',
     30            network=network, masterip='172.16.0.1') 
     31        nod2 = Node.objects.create(name='Rick', location=loc2, status='up',
     32            network=network, masterip='172.16.1.1') 
     33        nod3 = Node.objects.create(name='Andrea', location=loc3, status='up',
     34            network=network, masterip='172.16.2.1') 
    2735
    2836    def tearDown(self):
  • TabularUnified trunk/exodus/tests/test_wllogic.py

    r6606 r6607  
     1import unittest
     2from exodus.tests.base import BootstrapTestCase
     3
     4class WLLogic(BootstrapTestCase):
     5
     6    def test_get_direction_choices(self):
     7        from exodus.wllogic import get_direction_choices as gdc
     8        self.failUnlessEqual(gdc('nw'), 'north-west')
     9        self.failUnlessEqual(gdc('n'), 'north')
     10
     11    def test_new_ssid_for_(self):
     12        class nic(object):
     13            iface = 'ath0'     
     14            class node(object):
     15                name = 'CeTIM'
     16                class network(object):
     17                    name = 'wleiden.net'
     18        from exodus.wllogic import new_ssid
     19        ssid = new_ssid(nic())       
     20       
     21        self.failUnlessEqual(ssid, 'ath0.CeTIM.wleiden.net')
     22
     23    def test_parse_show_addr(self):
     24        ip = '172.16.2.0'
     25        from exodus.wllogic import parse_addr
     26        parsed = parse_addr(ip)
     27        self.failUnlessEqual(str(parsed), '2886730240')
     28
     29        from exodus.wllogic import show_addr
     30        o_ip = show_addr(parsed)
     31        self.failUnlessEqual(o_ip, ip)
     32
     33        # when using an address larger then 256, move 1 address up.
     34        ip = '172.16.2.256'
     35        o_ip = show_addr(parse_addr(ip))
     36        self.failUnlessEqual(o_ip, '172.16.3.0')
     37
     38    def test_netmask2subnet(self):
     39        from wllogic import netmask2subnet
     40
     41        self.failUnlessRaises(ValueError, netmask2subnet, 33)
     42        self.failUnlessRaises(ValueError, netmask2subnet, -1)
     43
     44        valid_subnet = netmask2subnet(30)
     45        self.failUnlessEqual(str(valid_subnet), '17179869180')
     46   
     47    def test_get_subnet(self):
     48        from wllogic import get_subnet
     49        self.failUnlessRaises(ValueError, get_subnet, -1)
     50        self.failUnlessRaises(ValueError, get_subnet, 33)
     51       
     52        valid_netmask = get_subnet(30)
     53        self.failUnless(valid_netmask, '255.255.255.252')
     54   
     55    def test_network(self):
     56        from wllogic import network
     57        from wllogic import show_addr
     58        network_addr = show_addr(network('172.18.5.10', 24))
     59        self.failUnlessEqual(network_addr, '172.18.5.0')
     60
     61    def test_broadcast(self):
     62        from wllogic import broadcast
     63        from wllogic import show_addr
     64       
     65        broadcast_addr = show_addr(broadcast('172.16.5.232', 24))
     66        self.failUnlessEqual(broadcast_addr, '172.16.5.255')
     67
     68        self.failUnlessRaises(ValueError, broadcast, '172.16.5.1', -1)
     69        self.failUnlessRaises(ValueError, broadcast, '172.16.5.1', 33)
     70   
     71    def test_get_network(self):
     72        from wllogic import get_network
     73        network_addr = get_network('172.17.2.2', 30)
     74        self. failUnlessEqual(network_addr, '172.17.2.0')
     75
     76        self.failUnlessRaises(ValueError, get_network, '172.17.2.0', -1)
     77        self.failUnlessRaises(ValueError, get_network, '172.17.2.0', 33)
     78
     79    def test_get_broadcast(self):
     80        from wllogic import get_broadcast
     81        broadcast_addr = get_broadcast('172.17.2.2', 24)
     82        self.failUnlessEqual(broadcast_addr, '172.17.2.255')
     83       
     84        self.failUnlessRaises(ValueError, get_broadcast, '172.17.2.0', -1)
     85        self.failUnlessRaises(ValueError, get_broadcast, '172.17.2.0', 33)
     86
     87    def test_free_master_ip(self):
     88        from wllogic import free_master_ip
     89        from exodus.models import Network, Node
     90        nodes = Node.objects.all()
     91        ip_list = []
     92        for i in nodes:
     93            ip_list.append(i.masterip)
     94        network = Network.objects.get(pk=1)
     95        ip = free_master_ip(network)
     96        self.failIf(ip in ip_list)
     97        self.failUnlessEqual(ip, '172.16.2.1')
     98
     99    def test_calc_subnet(self):
     100        from wllogic import calc_subnet
     101        self.failUnlessEqual(calc_subnet(1), 32)
     102        self.failUnlessRaises(ValueError, calc_subnet, 0)
     103        self.failUnlessRaises(ValueError, calc_subnet, 255)
     104
     105        l = []
     106        for i in range(1,255):
     107            l.append(calc_subnet(i))
     108        k = []
     109        for i in range(24,33):
     110            k.append(l.count(i))
     111        n = [128, 64, 32, 16, 8, 4, 1, 0, 1]
     112        self.failUnlessEqual(k,n)
     113
     114    def test_CHOICES(self):
     115        from wllogic import MASTER, MANAGED
     116        self.failUnlessEqual(MASTER, 'ms')
     117        self.failUnlessEqual(MANAGED, 'mn')
     118       
     119class Link(unittest.TestCase):
     120    def setUp(self):
     121        class link(object):
     122            def __init__(self, type, node):
     123                self.type = type
     124                self.node = node
     125
     126        self.link00 = link('eth', 1)
     127        self.link01 = link('eth', 2)
     128        self.link10 = link('11a', 1)
     129        self.link11 = link('11a', 2)
     130        self.link20 = link('11b', 1)
     131        self.link21 = link('11b', 2)
     132        self.link30 = link('11g', 1)           
     133        self.link31 = link('11g', 2)
     134
     135    def test_link_has_compat_type(self):
     136        from wllogic import link_has_compat_type
     137       
     138        # test link to self
     139        self.failUnless(link_has_compat_type(self.link00.type,
     140                                self.link00.type))
     141        # test eth
     142        self.failUnless(link_has_compat_type(self.link00.type,
     143                                self.link01.type))
     144        # test 11a
     145        self.failUnless(link_has_compat_type(self.link10.type,
     146                                 self.link11.type))
     147        # test 11b
     148        self.failUnless(link_has_compat_type(self.link20.type,
     149                                self.link21.type))
     150        # test 11g
     151        self.failUnless(link_has_compat_type(self.link30.type,
     152                                self.link31.type))
     153        # test 11b vs 11g
     154        self.failUnless(link_has_compat_type(self.link20.type,
     155                                self.link30.type))
     156        self.failUnless(link_has_compat_type(self.link30.type,
     157                                self.link20.type))
     158
     159        # test fail eth vs 11a
     160        self.failIf(link_has_compat_type(self.link00, self.link10))
     161        # test fail eth vs 11b
     162        self.failIf(link_has_compat_type(self.link00, self.link20))
     163        # test fail eth vs 11g
     164        self.failIf(link_has_compat_type(self.link00, self.link30))
     165        # test fail 11a vs 11b
     166        self.failIf(link_has_compat_type(self.link10, self.link20))
     167        # test fail 11a vs 11g
     168        self.failIf(link_has_compat_type(self.link10, self.link30))
     169   
     170    def test_link_not_same_node(self):
     171        from wllogic import link_is_not_to_itself
     172        self.failUnless(link_is_not_to_itself(self.link00, self.link01))
     173        self.failIf(link_is_not_to_itself(self.link20, self.link30))
     174   
     175    def test_link_is_wireless(self):
     176        from wllogic import link_is_wireless
     177        self.failIf(link_is_wireless(self.link00))
     178        self.failUnless(link_is_wireless(self.link10))
     179        self.failUnless(link_is_wireless(self.link20))
     180        self.failUnless(link_is_wireless(self.link30))
     181def suite():
     182    s = unittest.TestSuite()
     183    s.addTest(unittest.makeSuite(WLLogic))
     184
     185    return s
Note: See TracChangeset for help on using the changeset viewer.