Пример #1
0
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")
Пример #2
0
    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
Пример #3
0
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)
Пример #4
0
    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)
Пример #5
0
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"
Пример #6
0
    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
Пример #7
0
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)
Пример #11
0
def test_is_json_false():
    assert not is_json('{"test": "OK"')
Пример #12
0
def test_is_json():
    assert is_json('{"test": "OK"}')