def test_contest(self): """test the contest table""" CONTEST_ARGS = { "name": "1620 bracket", "activate_time": model.str_to_dt('2017-01-25T10:45Z'), "start_time": model.str_to_dt('2017-01-25T11:00Z'), "freeze_time": model.str_to_dt('2017-01-25T16:00Z'), "end_time": model.str_to_dt('2017-01-25T16:45Z'), "deactivate_time": model.str_to_dt('2017-01-26T10:45Z'), "is_public": True, } user_args, user = get_user() problem_args, problem = get_problem() # create and add contest contest = model.Contest(**CONTEST_ARGS) contest.users.append(user) contest.problems.append(problem) model.db.session.add(contest) model.db.session.commit() # fetch contest results = model.Contest.query.filter_by( name=CONTEST_ARGS['name']).all() self.assertEqual(len(results), 1)
def setup_contest(): roles = {x.id: x for x in model.UserRole.query.all()} test_contestant = model.User("*****@*****.**", "Test User", "pass", user_roles=[roles['defendant']]) test_executioner = model.User("*****@*****.**", "Test Executioner", "epass", user_roles=[roles['executioner']]) test_contest = model.Contest("test_contest", model.str_to_dt("2017-02-05T22:04Z"), model.str_to_dt("2030-01-01T11:11Z"), True) io_problem_type = model.ProblemType.query.filter_by( name="input-output").one() test_problem = model.Problem( io_problem_type, "fizzbuzz", "FizzBuzz", "## FizzBuzz\nPerform fizzbuzz up to the given number", "3", "1\n2\nFizz", "15", "1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\n9\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n" ) test_contest.problems.append(test_problem) test_contest.users.append(test_contestant) python = model.Language.query.filter_by(name="python").one() test_run = model.Run( test_contestant, test_contest, python, test_problem, model.str_to_dt("2017-02-05T23:00Z"), 'import sys\nn=raw_input()\nfor i in range(1, n+1): print("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or i)', test_problem.secret_input, test_problem.secret_output, True) model.db.session.add_all([ test_executioner, test_contestant, test_contest, test_problem, test_run ]) model.db.session.commit()
def test_do_not_reset_not_overdue_run(self): """tests if an overdue run gets reset""" EXECUTOR_TIMEOUT_MINS = 5 contest_args, contest = get_contest() problem_args, problem = get_problem() user_args, user = get_user() language_args, language = get_language() RUN_ARGS = { "user": user, "contest": contest, "language": language, "problem": problem, "submit_time": model.str_to_dt('2017-01-26T10:45Z'), "source_code": "print('hello'*input())", "run_input": "5", "correct_output": "hellohellohellohellohello", "is_submission": True, } run = model.Run(**RUN_ARGS) run.started_execing_time = datetime.datetime.utcnow() - datetime.timedelta(minutes=EXECUTOR_TIMEOUT_MINS-1) run.finished_execing_time = None model.db.session.add(run) model.db.session.commit() reset_overdue_runs() queried_run = model.Run.query.scalar() self.assertEqual(queried_run.started_execing_time, run.started_execing_time)
def get_contest(): """returns a test contest""" CONTEST_ARGS = { "name": "1620 bracket", "activate_time": model.str_to_dt('2017-01-25T10:45Z'), "start_time": model.str_to_dt('2017-01-25T11:00Z'), "freeze_time": model.str_to_dt('2017-01-25T16:00Z'), "end_time": model.str_to_dt('2017-01-25T16:45Z'), "deactivate_time": model.str_to_dt('2017-01-26T10:45Z'), "is_public": True, } # create and add contest contest = model.Contest(**CONTEST_ARGS) model.db.session.add(contest) model.db.session.commit() return CONTEST_ARGS, contest
def get_user(): """returns a test user""" USER_ARGS = { "email": "*****@*****.**", "name": "Test A. B. User", "password": "******", "creation_time": model.str_to_dt("2017-01-01T12:12Z"), "misc_data": '{"teacher": "Cavanaugh"}', } # create and add user user = model.User(**USER_ARGS) model.db.session.add(user) model.db.session.commit() return USER_ARGS, user
def test_saved_code(self): """test the saved_code table""" contest_args, contest = get_contest() problem_args, problem = get_problem() user_args, user = get_user() language_args, language = get_language() SAVED_CODE_ARGS = { "contest": contest, "problem": problem, "user": user, "language": language, "source_code": "print('hello')", "last_updated_time": model.str_to_dt('2017-01-26T10:45Z'), } saved_code = model.SavedCode(**SAVED_CODE_ARGS) model.db.session.add(saved_code) model.db.session.commit()
def test_user(self): """test the user table""" USER_ARGS = { "email": "*****@*****.**", "name": "Test A. B. User", "password": "******", "creation_time": model.str_to_dt("2017-01-01T12:12Z"), "misc_data": '{"teacher": "Cavanaugh"}', } # create and add user user = model.User(**USER_ARGS) model.db.session.add(user) model.db.session.commit() # fetch user results = model.User.query.filter_by(email=USER_ARGS['email']).all() self.assertEqual(len(results), 1)
def test_run(self): """test the run table""" contest_args, contest = get_contest() problem_args, problem = get_problem() user_args, user = get_user() language_args, language = get_language() RUN_ARGS = { "user": user, "contest": contest, "language": language, "problem": problem, "submit_time": model.str_to_dt('2017-01-26T10:45Z'), "source_code": "print('hello'*input())", "run_input": "5", "correct_output": "hellohellohellohellohello", "is_submission": True, } run = model.Run(**RUN_ARGS) model.db.session.add(run) model.db.session.commit()