def test_matched_configured(self):
     conf = {'enabled': 'true', 'resource': 'POST /derp'}
     result = create_default.filter_factory(conf)(self.app)
     pkg = 'wafflehaus.neutron.ip_policy.create_default.DefaultIPPolicy'
     with patch(pkg + '._filter_policy', self.default_mock) as mock:
         result.__call__.request('/derp', method='POST')
         self.assertTrue(mock.called)
 def test_matched_configured(self):
     conf = {'enabled': 'true', 'resource': 'POST /derp'}
     result = create_default.filter_factory(conf)(self.app)
     pkg = 'wafflehaus.neutron.ip_policy.create_default.DefaultIPPolicy'
     with patch(pkg + '._filter_policy', self.default_mock) as mock:
         result.__call__.request('/derp', method='POST')
         self.assertTrue(mock.called)
 def test_body_contains_allocation_pool_smaller_than_default(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     body = self.v4_has_alloc_smaller_than_default
     resp = result.__call__.request('/v2.0/subnets', method='POST',
                                    body=body)
     self.assertTrue(200, resp.status_code)
     self.assertNotEqual(result.body, body)
     allocation_pools = self._get_allocation_pools_from_body(result.body)
     self.assertEqual(1, len(allocation_pools))
     self.assertEqual("192.168.199.85", allocation_pools[0]["start"])
     self.assertEqual("192.168.199.100", allocation_pools[0]["end"])
 def test_body_contains_allocation_pool_bigger_than_default(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     body = self.v6_has_alloc_bigger_than_default
     resp = result.__call__.request('/v2.0/subnets', method='POST',
                                    body=body)
     self.assertTrue(200, resp.status_code)
     self.assertNotEqual(result.body, body)
     allocation_pools = self._get_allocation_pools_from_body(result.body)
     self.assertEqual(1, len(allocation_pools))
     self.assertEqual("2607:f0d0:1002:51::a", allocation_pools[0]["start"])
     self.assertEqual("2607:f0d0:1002:51::ffff:fffe",
                      allocation_pools[0]["end"])
 def test_body_contains_multiple_allocation_pool_smaller_than_default(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     body = self.v6_has_alloc_smaller_than_default
     resp = result.__call__.request('/v2.0/subnets',
                                    method='POST',
                                    body=body)
     self.assertTrue(200, resp.status_code)
     self.assertNotEqual(result.body, body)
     allocation_pools = self._get_allocation_pools_from_body(result.body)
     self.assertEqual(1, len(allocation_pools))
     self.assertEqual("2607:f0d0:1002:51::55", allocation_pools[0]["start"])
     self.assertEqual("2607:f0d0:1002:51::64", allocation_pools[0]["end"])
 def test_body_contains_allocation_pool_bigger_than_default(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     body = self.v4_has_alloc_bigger_than_default
     resp = result.__call__.request('/v2.0/subnets',
                                    method='POST',
                                    body=body)
     self.assertTrue(200, resp.status_code)
     self.assertNotEqual(result.body, body)
     allocation_pools = self._get_allocation_pools_from_body(result.body)
     self.assertEqual(1, len(allocation_pools))
     self.assertEqual("192.168.199.5", allocation_pools[0]["start"])
     self.assertEqual("192.168.199.254", allocation_pools[0]["end"])
 def test_body_contains_multiple_allocation_pool_smaller_than_default(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     body = self.v4_has_alloc_multiple_smaller_than_default
     resp = result.__call__.request('/v2.0/subnets',
                                    method='POST',
                                    body=body)
     self.assertTrue(200, resp.status_code)
     self.assertNotEqual(result.body, body)
     allocation_pools = self._get_allocation_pools_from_body(result.body)
     self.assertEqual(2, len(allocation_pools))
     starting_ips = ["192.168.199.85", "192.168.199.185"]
     ending_ips = ["192.168.199.100", "192.168.199.200"]
     self.assertTrue(allocation_pools[0]["start"] in starting_ips)
     self.assertTrue(allocation_pools[0]["end"] in ending_ips)
     self.assertTrue(allocation_pools[1]["start"] in starting_ips)
     self.assertTrue(allocation_pools[1]["end"] in ending_ips)
    def test_runtime_override(self):
        self.set_reconfigure()
        result = create_default.filter_factory({'enabled': 'true'})(self.app)

        headers = {'X_WAFFLEHAUS_DEFAULTIPPOLICY_ENABLED': False}
        body = self.v4_has_alloc_multiple_smaller_than_default
        resp = result.__call__.request('/v2.0/subnets', method='POST',
                                       body=body, headers=headers)
        self.assertTrue(200, resp.status_code)
        self.assertFalse(hasattr(result, 'body'))

        headers = {'X_WAFFLEHAUS_DEFAULTIPPOLICY_ENABLED': True}
        body = self.v4_has_alloc_multiple_smaller_than_default
        resp = result.__call__.request('/v2.0/subnets', method='POST',
                                       body=body, headers=headers)
        self.assertTrue(200, resp.status_code)
        self.assertNotEqual(result.body, body)
    def test_runtime_override(self):
        self.set_reconfigure()
        result = create_default.filter_factory({'enabled': 'true'})(self.app)

        headers = {'X_WAFFLEHAUS_DEFAULTIPPOLICY_ENABLED': False}
        body = self.v4_has_alloc_multiple_smaller_than_default
        resp = result.__call__.request('/v2.0/subnets',
                                       method='POST',
                                       body=body,
                                       headers=headers)
        self.assertTrue(200, resp.status_code)
        self.assertFalse(hasattr(result, 'body'))

        headers = {'X_WAFFLEHAUS_DEFAULTIPPOLICY_ENABLED': True}
        body = self.v4_has_alloc_multiple_smaller_than_default
        resp = result.__call__.request('/v2.0/subnets',
                                       method='POST',
                                       body=body,
                                       headers=headers)
        self.assertTrue(200, resp.status_code)
        self.assertNotEqual(result.body, body)
 def test_not_matched(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     pkg = 'wafflehaus.neutron.ip_policy.create_default.DefaultIPPolicy'
     with patch(pkg + '._filter_policy', self.default_mock) as mock:
         result.__call__.request('/testing', method='POST')
         self.assertFalse(mock.called)
 def test_default_instance_create(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     self.assertIsNotNone(result)
     resp = result.__call__.request('/', method='GET')
     self.assertEqual(resp, self.app)
 def test_not_matched(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     pkg = 'wafflehaus.neutron.ip_policy.create_default.DefaultIPPolicy'
     with patch(pkg + '._filter_policy', self.default_mock) as mock:
         result.__call__.request('/testing', method='POST')
         self.assertFalse(mock.called)
 def test_default_instance_create(self):
     result = create_default.filter_factory({'enabled': 'true'})(self.app)
     self.assertIsNotNone(result)
     resp = result.__call__.request('/', method='GET')
     self.assertEqual(resp, self.app)