def test_api_submission_patch_correct_scoreboard_teams():
    "If we adjust a submission for a team the scoreboard should be correct after the adjustment"
    app = create_ctfd(user_mode="teams")
    with app.app_context():
        # Create 2 test teams each with only 1 user
        gen_team(app.db, name="team1", email="team1@examplectf.com", member_count=1)
        gen_team(app.db, name="team2", email="team2@examplectf.com", member_count=1)

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

        # Assign only fails to the user in team 1
        gen_fail(app.db, challenge_id=1, user_id=2, team_id=1)
        gen_fail(app.db, challenge_id=2, user_id=2, team_id=1)
        # Assign only solves to the user in team 2
        gen_solve(app.db, challenge_id=1, user_id=3, team_id=2)
        gen_solve(app.db, challenge_id=2, user_id=3, team_id=2)

        with login_as_user(app, "admin") as client:
            # team2 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"] == "team2"

            # We then convert the first submission which should give team1 100 points
            # team1 should also now appear on the scoreboard in 2nd place
            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"] == "team2"
            assert scoreboard[1]["name"] == "team1"
            assert scoreboard[1]["score"] == 100

            # We mark team1's second solve as correct
            # This should give them 200 points
            # It should place them above team2 who has 200 points but was not the first to solve the challenge
            # Based on time team1'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"] == "team1"
            assert scoreboard[0]["score"] == 200
            assert scoreboard[1]["name"] == "team2"
            assert scoreboard[1]["score"] == 200
    destroy_ctfd(app)
If we adjust a submission for a team the scoreboard should be correct after the adjustment
tests/api/v1/test_submissions.py