def test_response_strings_fail_big_payload(self): string_handler = core.StringResponseHandler() # Register the JSON handler so response_data is set. json_handler = jsonhandler.JSONHandler() self.test.response_handlers = [string_handler, json_handler] self.test.content_handlers = [json_handler] self.test.content_type = "application/json" self.test.test_data = {'response_strings': ['foobar']} self.test.response_data = { 'objects': [{ 'name': 'cw', 'location': 'barn' }, { 'name': 'chris', 'location': 'house' }] * 100 } self.test.output = json.dumps(self.test.response_data) with self.assertRaises(AssertionError) as cm: self._assert_handler(string_handler) msg = str(cm.exception) self.assertEqual(2038, len(msg)) # Check the pprint of the json self.assertIn(' "location": "house"', msg)
def test_response_strings(self): handler = core.StringResponseHandler() self.test.content_type = "text/plain" self.test.response_data = None self.test.test_data = {'response_strings': ['alpha', 'beta']} self.test.output = 'alpha\nbeta\n' self._assert_handler(handler)
def test_response_strings_fail(self): handler = core.StringResponseHandler() self.test.content_type = "text/plain" self.test.response_data = None self.test.test_data = {'response_strings': ['alpha', 'beta']} self.test.output = 'alpha\nbta\n' with self.assertRaises(AssertionError): self._assert_handler(handler)
def test_response_strings_fail_big_output(self): handler = core.StringResponseHandler() self.test.content_type = "text/plain" self.test.response_data = None self.test.test_data = {'response_strings': ['alpha', 'beta']} self.test.output = 'alpha\nbta\n' * 1000 with self.assertRaises(AssertionError) as cm: self._assert_handler(handler) msg = str(cm.exception) self.assertEqual(2036, len(msg))
def test_response_string_list_type(self): handler = core.StringResponseHandler() self.test.test_data = { 'name': 'omega test', 'response_strings': 'omega' } self.test.output = 'omega\n' with self.assertRaises(GabbiFormatError) as exc: self._assert_handler(handler) self.assertIn('has incorrect type', str(exc)) self.assertIn("response_strings in 'omega test'", str(exc))