def test_api_submission_patch_correct_scoreboard():
    "If we adjust a submission for someone the scoreboard should be correct accounting for the time of the adjusted submission"
    app = create_ctfd()
    with app.app_context():
        # Create 2 test users
        register_user(app, name="user1", email="user1@examplectf.com")
        register_user(app, name="user2", email="user2@examplectf.com")

        # Create 2 test challenges
        gen_challenge(app.db, name="chal1")
        gen_challenge(app.db, name="chal2")

        # Give the first test user only fails
        gen_fail(app.db, challenge_id=1, user_id=2)
        gen_fail(app.db, challenge_id=2, user_id=2)
        # Give the second test user only solves
        gen_solve(app.db, challenge_id=1, user_id=3)
        gen_solve(app.db, challenge_id=2, user_id=3)
        with login_as_user(app, "admin") as client:
            # user2 who has both solves should be considered on top
            scoreboard = client.get("/api/v1/scoreboard").get_json()["data"]
            assert len(scoreboard) == 1
            assert scoreboard[0]["name"] == "user2"

            # We mark user1's first solve as correct
            # This should give them 100 points
            # It should not place them above user2 who has 200 points
            client.patch("/api/v1/submissions/1", json={"type": "correct"})
            scoreboard = client.get("/api/v1/scoreboard").get_json()["data"]
            assert len(scoreboard) == 2
            assert scoreboard[0]["name"] == "user2"
            assert scoreboard[1]["name"] == "user1"
            assert scoreboard[1]["score"] == 100

            # We mark user1's second solve as correct
            # This should give them 200 points
            # It should place them above user2 who has 200 points but was not the first to solve the challenge
            # Based on time user1's attempts should be considered correct and first
            client.patch("/api/v1/submissions/2", json={"type": "correct"})
            scoreboard = client.get("/api/v1/scoreboard").get_json()["data"]
            assert len(scoreboard) == 2
            assert scoreboard[0]["name"] == "user1"
            assert scoreboard[0]["score"] == 200
            assert scoreboard[1]["name"] == "user2"
            assert scoreboard[1]["score"] == 200
    destroy_ctfd(app)
If we adjust a submission for someone the scoreboard should be correct accounting for the time of the adjusted submission
tests/api/v1/test_submissions.py