Revision d44c236b api/tests.py
b/api/tests.py | ||
---|---|---|
349 | 349 |
owner=choice(users), |
350 | 350 |
sourceimage=choice(images), |
351 | 351 |
hostid=str(i), |
352 |
ipfour='0.0.0.0', |
|
353 |
ipsix='::1', |
|
354 | 352 |
flavor=choice(flavors)) |
355 | 353 |
|
356 | 354 |
def create_server_metadata(n=1): |
... | ... | |
366 | 364 |
for i in range(n): |
367 | 365 |
Network.objects.create( |
368 | 366 |
name='Network%d' % (i + 1), |
369 |
owner=choice(users)) |
|
367 |
owner=choice(users), |
|
368 |
state='ACTIVE') |
|
370 | 369 |
|
371 | 370 |
|
372 | 371 |
class AssertInvariant(object): |
... | ... | |
860 | 859 |
machines = VirtualMachine.objects.all() |
861 | 860 |
for network in Network.objects.all(): |
862 | 861 |
n = randint(0, self.SERVERS) |
863 |
network.machines.add(*sample(machines, n))
|
|
864 |
network.save()
|
|
865 |
|
|
862 |
for machine in sample(machines, n):
|
|
863 |
machine.nics.create(network=network)
|
|
864 |
|
|
866 | 865 |
def test_list_networks(self): |
867 | 866 |
networks = self.list_networks() |
868 | 867 |
for net in Network.objects.all(): |
... | ... | |
882 | 881 |
|
883 | 882 |
class CreateNetwork(BaseTestCase): |
884 | 883 |
def test_create_network(self): |
885 |
self.assertEqual(self.list_networks(), [])
|
|
884 |
before = self.list_networks()
|
|
886 | 885 |
self.create_network('net') |
887 |
networks = self.list_networks() |
|
888 |
self.assertEqual(len(networks), 1) |
|
889 |
network = networks[0] |
|
890 |
self.assertEqual(network['name'], 'net') |
|
886 |
after = self.list_networks() |
|
887 |
self.assertEqual(len(after) - len(before), 1) |
|
888 |
found = False |
|
889 |
for network in after: |
|
890 |
if network['name'] == 'net': |
|
891 |
found = True |
|
892 |
break |
|
893 |
self.assertTrue(found) |
|
891 | 894 |
|
892 | 895 |
|
893 | 896 |
class GetNetworkDetails(BaseTestCase): |
... | ... | |
932 | 935 |
def test_delete_network(self): |
933 | 936 |
networks = self.list_networks() |
934 | 937 |
network = choice(networks) |
938 |
while network['id'] == 1: |
|
939 |
network = choice(networks) |
|
935 | 940 |
network_id = network['id'] |
936 | 941 |
self.delete_network(network_id) |
937 |
|
|
938 |
response = self.client.get('/api/v1.1/networks/%d' % network_id)
|
|
939 |
self.assertItemNotFound(response)
|
|
942 |
|
|
943 |
net = self.get_network_details(network_id)
|
|
944 |
self.assertEqual(net['status'], 'DELETED')
|
|
940 | 945 |
|
941 | 946 |
networks.remove(network) |
942 | 947 |
self.assertEqual(self.list_networks(), networks) |
Also available in: Unified diff