vishalbhat07/ctfd
0
1from CTFd.models import Teams, Users2from tests.helpers import (3 create_ctfd,4 destroy_ctfd,5 gen_bracket,6 login_as_user,7 register_team,8 register_user,9)10 11 12def test_require_bracket_on_register():13 """Require users to submit a bracket if there is a bracket configured"""14 app = create_ctfd()15 with app.app_context():16 gen_bracket(app.db)17 with app.test_client() as client:18 client.get("/register")19 with client.session_transaction() as sess:20 data = {21 "name": "user",22 "email": "user@examplectf.com",23 "password": "password",24 "nonce": sess.get("nonce"),25 }26 client.post("/register", data=data)27 login_as_user(app, raise_for_error=False)28 assert Users.query.filter_by(email="user@examplectf.com").count() == 029 data["bracket_id"] = 130 client.post("/register", data=data)31 login_as_user(app, raise_for_error=True)32 assert Users.query.filter_by(email="user@examplectf.com").count() == 133 destroy_ctfd(app)34 35 36def test_require_team_bracket_on_register():37 """Test that brackets are required on team mode"""38 app = create_ctfd(user_mode="teams")39 with app.app_context():40 gen_bracket(app.db, type="teams")41 register_user(app)42 with login_as_user(app) as client:43 register_team(app, raise_for_error=False)44 45 with client.session_transaction() as sess:46 data = {47 "name": "team",48 "password": "password",49 "nonce": sess.get("nonce"),50 }51 # Test that a team is not created52 client.post("/teams/new", data=data)53 assert Teams.query.count() == 054 55 # Test that the team is now created56 data["bracket_id"] = 157 client.post("/teams/new", data=data)58 assert Teams.query.filter_by(id=1).first().bracket_id == 159 destroy_ctfd(app)60 