def test_deleting_challenge_clears_cache_solves():
    """
    Test that deleting a challenge clears the cached solves for the challenge
    """
    app = create_ctfd()
    with app.app_context():
        register_user(app)
        user = Users.query.filter_by(id=2).first()
        simulate_user_activity(app.db, user)
        with login_as_user(app) as client, login_as_user(
            app, name="admin", password="password"
        ) as admin:
            req = client.get("/api/v1/challenges")
            data = req.get_json()["data"]
            challenge = data[0]
            assert challenge["solves"] == 1
            from CTFd.utils.challenges import (  # noqa: I001
                get_solve_counts_for_challenges,
                get_solves_for_challenge_id,
            )

            solves = get_solves_for_challenge_id(1)
            solve_counts = get_solve_counts_for_challenges()
            solves_req = client.get("/api/v1/challenges/1/solves").get_json()["data"]
            assert len(solves_req) == 1
            assert len(solves) == 1
            assert solve_counts[1] == 1

            r = admin.delete("/api/v1/challenges/1", json="")
            assert r.status_code == 200

            solve_counts = get_solve_counts_for_challenges()
            solves = get_solves_for_challenge_id(1)
            r = client.get("/api/v1/challenges/1/solves")
            assert r.status_code == 404
            assert len(solves) == 0
            assert solve_counts.get(1) is None
    destroy_ctfd(app)

    Test that deleting a challenge clears the cached solves for the challenge
    
tests/cache/test_challenges.py