def test_ctftime_prevents_accessing_challenges_before_ctf():
    """Test that the ctftime function prevents users from accessing challenges before the ctf"""
    app = create_ctfd()
    with app.app_context():
        with ctftime.init():
            register_user(app)
            chal = gen_challenge(app.db)
            chal_id = chal.id
            gen_flag(app.db, challenge_id=chal.id, content="flag")

            with ctftime.not_started():
                client = login_as_user(app)
                r = client.get("/challenges")
                assert r.status_code == 403

                with client.session_transaction() as sess:
                    data = {"key": "flag", "nonce": sess.get("nonce")}
                r = client.get("/api/v1/challenges/{}".format(chal_id), data=data)
                data = r.get_data(as_text=True)
                assert r.status_code == 403
            solve_count = app.db.session.query(app.db.func.count(Solves.id)).first()[0]
            assert solve_count == 0
    destroy_ctfd(app)
Test that the ctftime function prevents users from accessing challenges before the ctf
tests/utils/test_ctftime.py