def test_default_instance_create_simple(self):
     result = unset_key.filter_factory(self.simple_conf1)(self.app)
     self.assertIsNotNone(result)
     self.assertTrue(hasattr(result, 'resources'))
     self.assertTrue(isinstance(result.resources, dict))
     self.assertEqual(1, len(result.resources))
     resources = result.resources
     self.assertTrue('/widget' in resources)
     self.assertEqual(1, len(resources['/widget']))
Exemplo n.º 2
0
 def test_default_instance_create_simple(self):
     result = unset_key.filter_factory(self.simple_conf1)(self.app)
     self.assertIsNotNone(result)
     self.assertTrue(hasattr(result, 'resources'))
     self.assertTrue(isinstance(result.resources, dict))
     self.assertEqual(1, len(result.resources))
     resources = result.resources
     self.assertTrue('/widget' in resources)
     self.assertEqual(1, len(resources['/widget']))
 def test_override_runtime(self):
     self.set_reconfigure()
     result = unset_key.filter_factory(self.plural_conf2)(self.app)
     headers = {'X_WAFFLEHAUS_DEFAULTPAYLOAD_ENABLED': False}
     resp = result.__call__.request('/widget', method='POST',
                                    body=self.body5, headers=headers)
     self.assertEqual(self.app, resp)
     self.assertFalse(hasattr(result, 'body'))
     headers = {'X_WAFFLEHAUS_DEFAULTPAYLOAD_ENABLED': True}
     resp = result.__call__.request('/widget', method='POST',
                                    body=self.body5, headers=headers)
     self.assertEqual(self.app, resp)
     self.assertTrue(hasattr(result, 'body'))
 def test_request_plural_request(self):
     result = unset_key.filter_factory(self.plural_conf)(self.app)
     resp = result.__call__.request('/widget', method='POST',
                                    body=self.body4)
     self.assertEqual(self.app, resp)
     body = result.body
     self.assertIsNotNone(body)
     json_body = json.loads(body)
     self.assertTrue('widgets' in json_body)
     self.assertTrue('thing' not in json_body)
     widgets = json_body['widgets']
     for widget in widgets:
         self.assertTrue('name' in widget)
         self.assertTrue('thing' in widget)
         self.assertEqual('thingie', widget['thing'])
 def test_request_multi_path_with_part_missing_reversed(self):
     result = unset_key.filter_factory(self.multi_confr)(self.app)
     resp = result.__call__.request('/widget', method='POST',
                                    body=self.body1)
     self.assertEqual(self.app, resp)
     body = result.body
     self.assertIsNotNone(body)
     json_body = json.loads(body)
     self.assertTrue('widget' in json_body)
     widget = json_body['widget']
     self.assertTrue('name' in widget)
     self.assertEqual('foo', widget['name'])
     self.assertTrue('thing' in widget)
     self.assertEqual('thingie', widget['thing'])
     self.assertFalse('sub' in widget)
 def test_request_body_not_overridden(self):
     """Payload filter will not change values that are set."""
     result = unset_key.filter_factory(self.simple_conf1)(self.app)
     resp = result.__call__.request('/widget', method='POST',
                                    body=self.body2)
     self.assertEqual(self.app, resp)
     body = result.body
     self.assertIsNotNone(body)
     json_body = json.loads(body)
     self.assertTrue('widget' in json_body)
     self.assertTrue('thing' not in json_body)
     widget = json_body['widget']
     self.assertTrue('name' in widget)
     self.assertEqual('foo', widget['name'])
     self.assertTrue('thing' in widget)
     self.assertEqual('derp', widget['thing'])
Exemplo n.º 7
0
 def test_request_plural_request(self):
     result = unset_key.filter_factory(self.plural_conf)(self.app)
     resp = result.__call__.request('/widget',
                                    method='POST',
                                    body=self.body4)
     self.assertEqual(self.app, resp)
     body = result.body
     self.assertIsNotNone(body)
     json_body = json.loads(body)
     self.assertTrue('widgets' in json_body)
     self.assertTrue('thing' not in json_body)
     widgets = json_body['widgets']
     for widget in widgets:
         self.assertTrue('name' in widget)
         self.assertTrue('thing' in widget)
         self.assertEqual('thingie', widget['thing'])
Exemplo n.º 8
0
 def test_request_multi_path_with_part_missing_reversed(self):
     result = unset_key.filter_factory(self.multi_confr)(self.app)
     resp = result.__call__.request('/widget',
                                    method='POST',
                                    body=self.body1)
     self.assertEqual(self.app, resp)
     body = result.body
     self.assertIsNotNone(body)
     json_body = json.loads(body)
     self.assertTrue('widget' in json_body)
     widget = json_body['widget']
     self.assertTrue('name' in widget)
     self.assertEqual('foo', widget['name'])
     self.assertTrue('thing' in widget)
     self.assertEqual('thingie', widget['thing'])
     self.assertFalse('sub' in widget)
 def test_request_complex_path(self):
     result = unset_key.filter_factory(self.simple_conf2)(self.app)
     resp = result.__call__.request('/widget', method='POST',
                                    body=self.body3)
     self.assertEqual(self.app, resp)
     body = result.body
     self.assertIsNotNone(body)
     json_body = json.loads(body)
     self.assertTrue('widget' in json_body)
     self.assertTrue('thing' not in json_body)
     widget = json_body['widget']
     self.assertTrue('thing' not in widget)
     self.assertTrue('name' in widget)
     self.assertEqual('foo', widget['name'])
     self.assertTrue('sub' in widget)
     sub = widget['sub']
     self.assertEqual('thingie', sub['thing'])
Exemplo n.º 10
0
 def test_request_body_not_overridden(self):
     """Payload filter will not change values that are set."""
     result = unset_key.filter_factory(self.simple_conf1)(self.app)
     resp = result.__call__.request('/widget',
                                    method='POST',
                                    body=self.body2)
     self.assertEqual(self.app, resp)
     body = result.body
     self.assertIsNotNone(body)
     json_body = json.loads(body)
     self.assertTrue('widget' in json_body)
     self.assertTrue('thing' not in json_body)
     widget = json_body['widget']
     self.assertTrue('name' in widget)
     self.assertEqual('foo', widget['name'])
     self.assertTrue('thing' in widget)
     self.assertEqual('derp', widget['thing'])
Exemplo n.º 11
0
 def test_override_runtime(self):
     self.set_reconfigure()
     result = unset_key.filter_factory(self.plural_conf2)(self.app)
     headers = {'X_WAFFLEHAUS_DEFAULTPAYLOAD_ENABLED': False}
     resp = result.__call__.request('/widget',
                                    method='POST',
                                    body=self.body5,
                                    headers=headers)
     self.assertEqual(self.app, resp)
     self.assertFalse(hasattr(result, 'body'))
     headers = {'X_WAFFLEHAUS_DEFAULTPAYLOAD_ENABLED': True}
     resp = result.__call__.request('/widget',
                                    method='POST',
                                    body=self.body5,
                                    headers=headers)
     self.assertEqual(self.app, resp)
     self.assertTrue(hasattr(result, 'body'))
Exemplo n.º 12
0
 def test_request_complex_path(self):
     result = unset_key.filter_factory(self.simple_conf2)(self.app)
     resp = result.__call__.request('/widget',
                                    method='POST',
                                    body=self.body3)
     self.assertEqual(self.app, resp)
     body = result.body
     self.assertIsNotNone(body)
     json_body = json.loads(body)
     self.assertTrue('widget' in json_body)
     self.assertTrue('thing' not in json_body)
     widget = json_body['widget']
     self.assertTrue('thing' not in widget)
     self.assertTrue('name' in widget)
     self.assertEqual('foo', widget['name'])
     self.assertTrue('sub' in widget)
     sub = widget['sub']
     self.assertEqual('thingie', sub['thing'])