]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Enable to specify context on POST requests during unittests
authorYushiro FURUKAWA <y.furukawa_2@jp.fujitsu.com>
Thu, 19 Feb 2015 10:11:27 +0000 (19:11 +0900)
committerYushiro FURUKAWA <y.furukawa_2@jp.fujitsu.com>
Thu, 19 Mar 2015 05:38:32 +0000 (14:38 +0900)
NeutronDbPluginV2TestCase has a method 'new_create_request'
to send 'POST' request. But, it doesn't have a argument 'context'.
So, we can not execute create-test as a tenant-user(NOT admin user)

  e.g. FWaaS resources can not test with the context in creating.

This fix enables to specify 'context' when executing new_create_request.

Closes-Bug:  #1423470
Related-Bug: #1408236
Change-Id: Id8dc8cff87ca658e86c192b8da047f0c62989a4e

neutron/tests/unit/test_db_plugin.py

index 0a0def87d59bf2d387ec7e0c269f76d1f73ac5d9..5c9fb64bec2b835666738e72b279f6558bfc9076 100644 (file)
@@ -199,9 +199,9 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase,
                                           query_string=params, context=context)
 
     def new_create_request(self, resource, data, fmt=None, id=None,
-                           subresource=None):
+                           subresource=None, context=None):
         return self._req('POST', resource, data, fmt, id=id,
-                         subresource=subresource)
+                         subresource=subresource, context=context)
 
     def new_list_request(self, resource, fmt=None, params=None,
                          subresource=None):
@@ -2650,6 +2650,20 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
         self.assertEqual(4, subnet['subnet']['ip_version'])
         self.assertIn('name', subnet['subnet'])
 
+    def test_create_subnet_with_network_different_tenant(self):
+        with self.network(shared=False, tenant_id='tenant1') as network:
+            ctx = context.Context(user_id='non_admin',
+                                  tenant_id='tenant2',
+                                  is_admin=False)
+            data = {'subnet': {'network_id': network['network']['id'],
+                    'cidr': '10.0.2.0/24',
+                    'ip_version': '4',
+                    'gateway_ip': '10.0.2.1'}}
+            req = self.new_create_request('subnets', data,
+                                          self.fmt, context=ctx)
+            res = req.get_response(self.api)
+            self.assertEqual(webob.exc.HTTPNotFound.code, res.status_int)
+
     def test_create_two_subnets(self):
         gateway_ips = ['10.0.0.1', '10.0.1.1']
         cidrs = ['10.0.0.0/24', '10.0.1.0/24']