def test_xml_error_without_format(client): with client as c: response = c.post("/", data={}) assert response.status_code == 400 assert is_json(response.data) assert (json.loads(response.data)["error"] == "You must add `format=[html,json,pdf]` to formData")
def put(self, user_id, id): json_data = request.get_json() artifact = Artifact.query.filter_by(user_id=user_id, id=id).first() if not is_json(json_data): return {"message": "Bad request", "data": json_data}, 400 result = update_object(Artifact.Schema, artifact, json_data) return result
def test_xml_to_json(client): with client as c: file = io.BytesIO(open(os.path.join(PATH, "sii.xml"), "rb").read()) response = c.post("/", data={ "format": "json", "xml": (file, "sii.xml") }) assert response.status_code == 200 assert is_json(response.data)
def put(self: None, id: int) -> str: json_data = request.get_json() user_settings = User.query.get(id).settings[0] if user is None: return "Not found", 404 if not is_json(json_data): return {"message": "Bad request.", "data": json_data}, 400 return update_object(UserSettings.Schema, user_settings, json_data)
def test_xml_error_not_xml(client): with client as c: file = io.BytesIO(b"") response = c.post("/", data={ "format": "json", "xml": (file, "sii.xml") }) assert response.status_code == 400 assert is_json(response.data) assert json.loads(response.data)["error"] == "File xml it's invalid"
def put(self: None, id: int) -> UserProfile: try: json_data = request.get_json() user_profile = User.query.get(id).profile[0] if user_profile is None: return "Not found", 404 if not is_json(json_data): return {"message": "Bad request.", "data": json_data}, 400 result = update_object(UserProfile.Schema, user_profile, json_data) return result except ValidationError as err: print(request.get_json()) return err.messages, 422
def test_xml_error_without_file(client): with client as c: response = c.post("/", data={"format": "json", "xml": ""}) assert response.status_code == 400 assert is_json(response.data) assert json.loads(response.data)["error"] == "You must send a file"
def test_good_input(self): data = '{"foo": "bar"}' req = is_json(data) self.assertTrue(req)
def test_submit_object(self): data = {"public": "true"} req = is_json(data) self.assertTrue(req)
def test_bad_input(self): data = "this is a string" req = is_json(data) self.assertFalse(req)
def test_is_json_false(): assert not is_json('{"test": "OK"')
def test_is_json(): assert is_json('{"test": "OK"}')