Ejemplo n.º 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")
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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"
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 10
0
 def test_bad_input(self):
     data = "this is a string"
     req = is_json(data)
     self.assertFalse(req)
Ejemplo n.º 11
0
def test_is_json_false():
    assert not is_json('{"test": "OK"')
Ejemplo n.º 12
0
def test_is_json():
    assert is_json('{"test": "OK"}')