Revision 0dae1b9f snf-cyclades-app/synnefo/neutron/tests/api.py

b/snf-cyclades-app/synnefo/neutron/tests/api.py
116 116

  
117 117
class SubnetTest(BaseAPITest):
118 118
    def test_list_subnets(self):
119
        '''Test Subnet list'''
119
        '''Test list subnets without data'''
120 120
        response = self.get(SUBNETS_URL)
121 121
        self.assertSuccess(response)
122 122
        subnets = json.loads(response.content)
123 123
        self.assertEqual(subnets, {'subnets': []})
124 124

  
125
    def test_list_subnets_data(self):
126
        '''Test list subnets with data'''
127
        test_net = mf.NetworkFactory()
128
        test_subnet_ipv4 = mf.SubnetFactory(network=test_net)
129
        test_subnet_ipv6 = mf.SubnetFactory(network=test_net, ipversion=6,
130
                                            cidr='2620:0:2d0:200::7/32')
131
        response = self.get(SUBNETS_URL, user=test_net.userid)
132
        self.assertSuccess(response)
133

  
125 134
    def test_get_subnet(self):
126
        '''Test get info of a subnet'''
127
        url = join_urls(SUBNETS_URL, '42')
128
        response = self.get(url)
135
        '''Test get info of a single subnet'''
136
        test_net = mf.NetworkFactory()
137
        test_subnet = mf.SubnetFactory(network=test_net)
138
        url = join_urls(SUBNETS_URL, str(test_subnet.id))
139
        response = self.get(url, user=test_net.userid)
129 140
        self.assertSuccess(response)
130
        subnet = json.loads(response.content)
131
        self.assertEqual(subnet, {'subnet': []})
132 141

  
133 142
    def test_get_subnet_404(self):
134 143
        '''Test get info of a subnet that doesn't exist'''
135
        url = join_urls(SUBNETS_URL, '52')
144
        url = join_urls(SUBNETS_URL, '42')
136 145
        response = self.get(url)
137 146
        self.assertItemNotFound(response)
138 147

  
139
    #def test_subnet_delete_not_found(self):
140
     #   '''Test delete a subnet that doesn't exist'''
141
     #   # FIX ME
142
     #   url = join_urls(SUBNETS_URL, '52')
143
     #   response = self.get(url)
144
     #   self.assertItemNotFound(response)
145

  
146 148
    def test_subnet_delete(self):
147 149
        '''Test delete a subnet -- not supported'''
148 150
        url = join_urls(SUBNETS_URL, '42')
149
        response = self.get(url)
151
        response = self.delete(url)
152
        self.assertBadRequest(response)
153

  
154
   # def test_create_subnet_success(self):
155
   #     '''Test create a subnet successfully'''
156
   #     test_net = mf.NetworkFactory()
157
   #     request = {
158
   #         'subnet': {
159
   #             'network_id': test_net.id,
160
   #             'cidr': '10.0.3.0/24',
161
   #             'ip_version': 4}
162
   #     }
163
   #     response = self.post(SUBNETS_URL, test_net.userid,
164
   #                          json.dumps(request), "json")
165
   #     self.assertSuccess(response)
166

  
167
    def test_create_subnet_with_invalid_network_id(self):
168
        '''Test create a subnet with a network id that doesn't exist'''
169
        test_net = mf.NetworkFactory()
170
        request = {
171
            'subnet': {
172
                'network_id': '42',
173
                'cidr': '10.0.3.0/24',
174
                'ip_version': 4}
175
        }
176
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
177
                             "json")
150 178
        self.assertItemNotFound(response)
151 179

  
152 180
    def test_create_subnet_with_malformed_ipversion(self):
153 181
        '''Create a subnet with a malformed ip_version type'''
182
        test_net = mf.NetworkFactory()
154 183
        request = {
155 184
            'subnet': {
156
                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
185
                'network_id': test_net.id,
157 186
                'cidr': '10.0.3.0/24',
158 187
                'ip_version': 8}
159 188
        }
160
        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
189
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
190
                             "json")
161 191
        self.assertBadRequest(response)
162 192

  
163 193
    def test_create_subnet_with_invalid_cidr(self):
164 194
        '''Create a subnet with an invalid cidr'''
195
        test_net = mf.NetworkFactory()
165 196
        request = {
166 197
            'subnet': {
167
                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
198
                'network_id': test_net.id,
168 199
                'cidr': '192.168.3.0/8'}
169 200
        }
170
        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
201
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
202
                             "json")
171 203
        self.assertBadRequest(response)
172 204

  
173 205
    def test_create_subnet_with_invalid_gateway(self):
174 206
        '''Create a subnet with a gateway outside of the subnet range'''
207
        test_net = mf.NetworkFactory()
175 208
        request = {
176 209
            'subnet': {
177
                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
210
                'network_id': test_net.id,
178 211
                'cidr': '192.168.3.0/24',
179 212
                'gateway_ip': '192.168.0.1'}
180 213
        }
181
        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
214
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
215
                             "json")
182 216
        self.assertBadRequest(response)
183 217

  
184
    def test_create_subnet_with_long_name(self):
218
    def test_create_subnet_with_invalid_name(self):
185 219
        '''Create a subnet with an invalid subnet name'''
220
        test_net = mf.NetworkFactory()
186 221
        request = {
187 222
            'subnet': {
188
                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
223
                'network_id': test_net.id,
189 224
                'cidr': '192.168.3.0/24',
190
                'name': 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
191
                        'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
192
                        'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'}
225
                'name': 'a' * 300}
193 226
        }
194
        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
227
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
228
                             "json")
195 229
        self.assertBadRequest(response)
196 230

  
197 231
    def test_create_subnet_with_invalid_dhcp(self):
198 232
        '''Create a subnet with an invalid dhcp value'''
233
        test_net = mf.NetworkFactory()
199 234
        request = {
200 235
            'subnet': {
201
                'network_id': 'ed2e3c10-2e43-4297-9006-2863a2d1abbc',
236
                'network_id': test_net.id,
202 237
                'cidr': '192.168.3.0/24',
203 238
                'enable_dhcp': 'None'}
204 239
        }
205
        response = self.post(SUBNETS_URL, "user9", json.dumps(request), "json")
240
        response = self.post(SUBNETS_URL, test_net.userid, json.dumps(request),
241
                             "json")
206 242
        self.assertBadRequest(response)

Also available in: Unified diff