[nailgun] Refactored unit tests after review

This commit is contained in:
Mike Scherbakov 2013-01-17 16:10:27 +04:00 committed by default
parent f1eec0ad76
commit 17acbb17c4

View File

@ -8,87 +8,80 @@ class TestNetworkModels(BaseHandlers):
def test_network_group_size_of_1_creates_1_network(self):
cluster = self.create_default_cluster()
release_id = cluster.release_id
cidr = "10.0.0.0/24"
network_size = 256
name = "fixed"
access = "private"
vlan_start = 200
ng = NetworkGroup(cidr=cidr, network_size=network_size,
name=name, access=access,
release=release_id, cluster_id=cluster.id,
vlan_start=vlan_start)
kw = {'release': cluster.release_id,
'cidr': '10.0.0.0/24',
'network_size': 256,
'name': 'fixed',
'access': 'private',
'vlan_start': 200,
'cluster_id': cluster.id}
ng = NetworkGroup(**kw)
self.db.add(ng)
self.db.commit()
ng.create_networks()
nets_db = self.db.query(Network).all()
self.assertEquals(len(nets_db), 1)
self.assertEquals(nets_db[0].vlan_id, vlan_start)
self.assertEquals(nets_db[0].name, name)
self.assertEquals(nets_db[0].access, access)
self.assertEquals(nets_db[0].cidr, cidr)
self.assertEquals(nets_db[0].vlan_id, kw['vlan_start'])
self.assertEquals(nets_db[0].name, kw['name'])
self.assertEquals(nets_db[0].access, kw['access'])
self.assertEquals(nets_db[0].cidr, kw['cidr'])
def test_network_group_creates_several_networks(self):
cluster = self.create_default_cluster()
release_id = cluster.release_id
cidr = "10.0.0.0/8"
network_size = 256
name = "fixed"
access = "private"
vlan_start = 200
amount = 25
ng = NetworkGroup(cidr=cidr, network_size=network_size,
name=name, access=access,
release=release_id, cluster_id=cluster.id,
vlan_start=vlan_start, amount=amount)
kw = {'release': cluster.release_id,
'cidr': '10.0.0.0/8',
'network_size': 256,
'name': 'fixed',
'access': 'private',
'vlan_start': 200,
'amount': 25,
'cluster_id': cluster.id}
ng = NetworkGroup(**kw)
self.db.add(ng)
self.db.commit()
ng.create_networks()
nets_db = self.db.query(Network).all()
self.assertEquals(len(nets_db), amount)
self.assertEquals(nets_db[0].vlan_id, vlan_start)
self.assertEquals(nets_db[amount - 1].vlan_id, vlan_start + amount - 1)
self.assertEquals(all(x.name == name for x in nets_db), True)
self.assertEquals(all(x.access == access for x in nets_db), True)
self.assertEquals(len(nets_db), kw['amount'])
self.assertEquals(nets_db[0].vlan_id, kw['vlan_start'])
self.assertEquals(nets_db[kw['amount'] - 1].vlan_id,
kw['vlan_start'] + kw['amount'] - 1)
self.assertEquals(all(x.name == kw['name'] for x in nets_db), True)
self.assertEquals(all(x.access == kw['access'] for x in nets_db), True)
vlans_db = self.db.query(Vlan).all()
self.assertEquals(len(vlans_db), amount)
self.assertEquals(len(vlans_db), kw['amount'])
def test_network_group_slices_cidr_for_networks(self):
cluster = self.create_default_cluster()
release_id = cluster.release_id
cidr = "10.0.0.0/8"
network_size = 128
name = "fixed"
access = "private"
vlan_start = 200
amount = 2
ng = NetworkGroup(cidr=cidr, network_size=network_size,
name=name, access=access,
release=release_id, cluster_id=cluster.id,
vlan_start=vlan_start, amount=amount)
kw = {'release': cluster.release_id,
'cidr': '10.0.0.0/8',
'network_size': 128,
'name': 'fixed',
'access': 'private',
'vlan_start': 200,
'amount': 2,
'cluster_id': cluster.id}
ng = NetworkGroup(**kw)
self.db.add(ng)
self.db.commit()
ng.create_networks()
nets_db = self.db.query(Network).all()
self.assertEquals(len(nets_db), amount)
self.assertEquals(nets_db[0].cidr, "10.0.0.0/25")
self.assertEquals(nets_db[1].cidr, "10.0.0.128/25")
self.assertEquals(len(nets_db), kw['amount'])
self.assertEquals(nets_db[0].cidr, '10.0.0.0/25')
self.assertEquals(nets_db[1].cidr, '10.0.0.128/25')
self.db.refresh(ng)
self.assertEquals(ng.cidr, "10.0.0.0/24")
self.assertEquals(ng.cidr, '10.0.0.0/24')
def test_network_group_squeezes_base_cidr(self):
cluster = self.create_default_cluster()
release_id = cluster.release_id
cidr = "10.0.0.0/8"
network_size = 256
name = "fixed"
access = "private"
vlan_start = 200
amount = 2
ng = NetworkGroup(cidr=cidr, network_size=network_size,
name=name, access=access,
release=release_id, cluster_id=cluster.id,
vlan_start=vlan_start, amount=amount)
kw = {'release': cluster.release_id,
'cidr': '10.0.0.0/8',
'network_size': 256,
'name': 'fixed',
'access': 'private',
'vlan_start': 200,
'amount': 2,
'cluster_id': cluster.id}
ng = NetworkGroup(**kw)
self.db.add(ng)
self.db.commit()
ng.create_networks()
@ -97,17 +90,15 @@ class TestNetworkModels(BaseHandlers):
def test_network_group_does_not_squeezes_base_cidr(self):
cluster = self.create_default_cluster()
release_id = cluster.release_id
cidr = "172.0.0.0/24"
network_size = 64
name = "fixed"
access = "private"
vlan_start = 200
amount = 3
ng = NetworkGroup(cidr=cidr, network_size=network_size,
name=name, access=access,
release=release_id, cluster_id=cluster.id,
vlan_start=vlan_start, amount=amount)
kw = {'release': cluster.release_id,
'cidr': '172.0.0.0/24',
'network_size': 64,
'name': 'fixed',
'access': 'private',
'vlan_start': 200,
'amount': 3,
'cluster_id': cluster.id}
ng = NetworkGroup(**kw)
self.db.add(ng)
self.db.commit()
ng.create_networks()
@ -116,17 +107,15 @@ class TestNetworkModels(BaseHandlers):
def test_network_group_does_not_squeezes_base_cidr_if_amount_1(self):
cluster = self.create_default_cluster()
release_id = cluster.release_id
cidr = "172.0.0.0/8"
network_size = 256
name = "public"
access = "private"
vlan_start = 200
amount = 1
ng = NetworkGroup(cidr=cidr, network_size=network_size,
name=name, access=access,
release=release_id, cluster_id=cluster.id,
vlan_start=vlan_start, amount=amount)
kw = {'release': cluster.release_id,
'cidr': '172.0.0.0/8',
'network_size': 256,
'name': 'public',
'access': 'public',
'vlan_start': 200,
'amount': 1,
'cluster_id': cluster.id}
ng = NetworkGroup(**kw)
self.db.add(ng)
self.db.commit()
ng.create_networks()
@ -135,22 +124,20 @@ class TestNetworkModels(BaseHandlers):
def test_network_group_sets_correct_gateway_for_few_nets(self):
cluster = self.create_default_cluster()
release_id = cluster.release_id
cidr = "10.0.0.0/8"
network_size = 128
name = "fixed"
access = "private"
vlan_start = 200
amount = 2
ng = NetworkGroup(cidr=cidr, network_size=network_size,
name=name, access=access,
release=release_id, cluster_id=cluster.id,
vlan_start=vlan_start, amount=amount,
gateway_ip_index=5)
kw = {'release': cluster.release_id,
'cidr': '10.0.0.0/8',
'network_size': 128,
'name': 'fixed',
'access': 'private',
'vlan_start': 200,
'amount': 2,
'gateway_ip_index': 5,
'cluster_id': cluster.id}
ng = NetworkGroup(**kw)
self.db.add(ng)
self.db.commit()
ng.create_networks()
nets_db = self.db.query(Network).all()
self.assertEquals(len(nets_db), amount)
self.assertEquals(len(nets_db), kw['amount'])
self.assertEquals(nets_db[0].gateway, "10.0.0.5")
self.assertEquals(nets_db[1].gateway, "10.0.0.133")