commit 0dae1b9ffd1f5b84d7d9785ed77db13845ff76b8
Author: Dionysis Grigoropoulos <dgrig@grnet.gr>
Date:   Fri Sep 27 17:24:53 2013 +0300

    cyclades: Neutron API add subnet tests, bug fixes

diff --git a/snf-cyclades-app/synnefo/neutron/tests/api.py b/snf-cyclades-app/synnefo/neutron/tests/api.py
index 9f8d766..bdb03b8 100644
--- a/snf-cyclades-app/synnefo/neutron/tests/api.py
+++ b/snf-cyclades-app/synnefo/neutron/tests/api.py
@@ -116,91 +116,127 @@ class NetworkTest(BaseAPITest):
 
 class SubnetTest(BaseAPITest):
     def test_list_subnets(self):
-        '''Test Subnet list'''
+        '''Test list subnets without data'''
         response = self.get(SUBNETS_URL)
         self.assertSuccess(response)
         subnets = json.loads(response.content)
         self.assertEqual(subnets, {'subnets': []})
 
+    def test_list_subnets_data(self):
+        '''Test list subnets with data'''
+        test_net = mf.NetworkFactory()
+        test_subnet_ipv4 = mf.SubnetFactory(network=test_net)
+        test_subnet_ipv6 = mf.SubnetFactory(network=test_net, ipversion=6,
+                                            cidr='2620:0:2d0:200::7/32')
+        response = self.get(SUBNETS_URL, user=test_net.userid)
+        self.assertSuccess(response)
+
     def test_get_subnet(self):
-        '''Test get info of a subnet'''
-        url = join_urls(SUBNETS_URL, '42')
-        response = self.get(url)
+        '''Test get info of a single subnet'''
+        test_net = mf.NetworkFactory()
+        test_subnet = mf.SubnetFactory(network=test_net)
+        url = join_urls(SUBNETS_URL, str(test_subnet.id))
+        response = self.get(url, user=test_net.userid)
         self.assertSuccess(response)
-        subnet = json.loads(response.content)
-        self.assertEqual(subnet, {'subnet': []})
 
     def test_get_subnet_404(self):
         '''Test get info of a subnet that doesn't exist'''
-        url = join_urls(SUBNETS_URL, '52')
+        url = join_urls(SUBNETS_URL, '42')
         response = self.get(url)
         self.assertItemNotFound(response)
 
-    #def test_subnet_delete_not_found(self):
-     #   '''Test delete a subnet that doesn't exist'''
-     #   # FIX ME
-     #   url = join_urls(SUBNETS_URL, '52')
-     #   response = self.get(url)
-     #   self.assertItemNotFound(response)
-
     def test_subnet_delete(self):
         '''Test delete a subnet -- not supported'''
         url = join_urls(SUBNETS_URL, '42')
-        response = self.get(url)
+        response = self.delete(url)
+        self.assertBadRequest(response)
+
+   # def test_create_subnet_success(self):
+   #     '''Test create a subnet successfully'''
+   #     test_net = mf.NetworkFactory()
+   #     request = {
+   #         'subnet': {
+   #             'network_id': test_net.id,
+   #             'cidr': '10.0.3.0/24',
+   #             'ip_version': 4}
+   #     }
+   #     response = self.post(SUBNETS_URL, test_net.userid,
+   #                          json.dumps(request), "json")
+   #     self.assertSuccess(response)
+
+    def test_create_subnet_with_invalid_network_id(self):
+        '''Test create a subnet with a network id that doesn't exist'''
+        test_net = mf.NetworkFactory()
+        request = {
+            'subnet': {
+                'network_id': '42',
+                'cidr': '10.0.3.0/24',
+                'ip_version': 4}
+        }
+        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
+                             "json")
         self.assertItemNotFound(response)
 
     def test_create_subnet_with_malformed_ipversion(self):
         '''Create a subnet with a malformed ip_version type'''
+        test_net = mf.NetworkFactory()
         request = {
             'subnet': {
-                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
+                'network_id': test_net.id,
                 'cidr': '10.0.3.0/24',
                 'ip_version': 8}
         }
-        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
+        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
+                             "json")
         self.assertBadRequest(response)
 
     def test_create_subnet_with_invalid_cidr(self):
         '''Create a subnet with an invalid cidr'''
+        test_net = mf.NetworkFactory()
         request = {
             'subnet': {
-                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
+                'network_id': test_net.id,
                 'cidr': '192.168.3.0/8'}
         }
-        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
+        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
+                             "json")
         self.assertBadRequest(response)
 
     def test_create_subnet_with_invalid_gateway(self):
         '''Create a subnet with a gateway outside of the subnet range'''
+        test_net = mf.NetworkFactory()
         request = {
             'subnet': {
-                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
+                'network_id': test_net.id,
                 'cidr': '192.168.3.0/24',
                 'gateway_ip': '192.168.0.1'}
         }
-        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
+        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
+                             "json")
         self.assertBadRequest(response)
 
-    def test_create_subnet_with_long_name(self):
+    def test_create_subnet_with_invalid_name(self):
         '''Create a subnet with an invalid subnet name'''
+        test_net = mf.NetworkFactory()
         request = {
             'subnet': {
-                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
+                'network_id': test_net.id,
                 'cidr': '192.168.3.0/24',
-                'name': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
-                        'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
-                        'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'}
+                'name': 'a' * 300}
         }
-        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
+        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
+                             "json")
         self.assertBadRequest(response)
 
     def test_create_subnet_with_invalid_dhcp(self):
         '''Create a subnet with an invalid dhcp value'''
+        test_net = mf.NetworkFactory()
         request = {
             'subnet': {
-                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
+                'network_id': test_net.id,
                 'cidr': '192.168.3.0/24',
                 'enable_dhcp': 'None'}
         }
-        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
+        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
+                             "json")
         self.assertBadRequest(response)
