def test_token_api_file_upload():
    """Test that tokens can upload files with multipart/form-data content type"""
    app = create_ctfd()
    with app.app_context():
        admin = Users.query.filter_by(id=1).first()
        token = generate_user_token(admin, expiration=None)
        with app.test_client() as client:
            headers = {"Authorization": "token " + token.value}
            r = client.post(
                "/api/v1/files",
                headers=headers,
                content_type="multipart/form-data",
                data={
                    "file": (BytesIO(b"test file content"), "test.txt"),
                },
            )
            assert r.status_code == 200
            f = Files.query.filter_by(id=1).first()
            filepath = os.path.join(app.config["UPLOAD_FOLDER"] + "/" + f.location)
            with open(filepath) as f:
                assert f.read() == "test file content"
            os.remove(filepath)
    destroy_ctfd(app)
Test that tokens can upload files with multipart/form-data content type
tests/api/test_tokens.py