def test_validate_json_content_dict_no_errors(self): content = self.to_bytes(_json.dumps({'foo': 'bar'})) response = self.get_response(content=content, status_code=400) try: utils.validate_response(response) except PlotlyRequestError as e: self.assertEqual(e.message, to_native_utf8_string(content)) self.assertEqual(e.status_code, 400) self.assertEqual(e.content, content) else: self.fail('Expected this to raise!')
def test_validate_json_content_array(self): content = self.to_bytes(_json.dumps([1, 2, 3])) response = self.get_response(content=content, status_code=400) try: utils.validate_response(response) except PlotlyRequestError as e: self.assertEqual(e.message, to_native_utf8_string(content)) self.assertEqual(e.status_code, 400) self.assertEqual(e.content, content) else: self.fail('Expected this to raise!')
def test_validate_json_content_dict_one_error_bad(self): content = self.to_bytes(_json.dumps({"errors": [{}]})) response = self.get_response(content=content, status_code=400) try: utils.validate_response(response) except PlotlyRequestError as e: self.assertEqual(e.message, to_native_utf8_string(content)) self.assertEqual(e.status_code, 400) self.assertEqual(e.content, content) else: self.fail("Expected this to raise!") content = self.to_bytes(_json.dumps({"errors": [{"message": ""}]})) response = self.get_response(content=content, status_code=400) try: utils.validate_response(response) except PlotlyRequestError as e: self.assertEqual(e.message, to_native_utf8_string(content)) self.assertEqual(e.status_code, 400) self.assertEqual(e.content, content) else: self.fail("Expected this to raise!")
def test_validate_json_content_dict_one_error_bad(self): content = self.to_bytes(_json.dumps({'errors': [{}]})) response = self.get_response(content=content, status_code=400) try: utils.validate_response(response) except PlotlyRequestError as e: self.assertEqual(e.message, to_native_utf8_string(content)) self.assertEqual(e.status_code, 400) self.assertEqual(e.content, content) else: self.fail('Expected this to raise!') content = self.to_bytes(_json.dumps({'errors': [{'message': ''}]})) response = self.get_response(content=content, status_code=400) try: utils.validate_response(response) except PlotlyRequestError as e: self.assertEqual(e.message, to_native_utf8_string(content)) self.assertEqual(e.status_code, 400) self.assertEqual(e.content, content) else: self.fail('Expected this to raise!')
def __init__(self, message, status_code, content): self.message = to_native_utf8_string(message) self.status_code = status_code self.content = content