Example #1
0
    def test_contest(self):
        """test the contest table"""
        CONTEST_ARGS = {
            "name": "1620 bracket",
            "activate_time": util.str_to_dt("2017-01-25T10:45:00Z"),
            "start_time": util.str_to_dt("2017-01-25T11:00:00Z"),
            "freeze_time": util.str_to_dt("2017-01-25T16:00:00Z"),
            "end_time": util.str_to_dt("2017-01-25T16:45:00Z"),
            "deactivate_time": util.str_to_dt("2017-01-26T10:45:00Z"),
            "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)

        db_session.add(contest)
        db_session.commit()

        # fetch contest
        results = model.Contest.query.filter_by(name=CONTEST_ARGS["name"]).all()

        self.assertEqual(len(results), 1)
Example #2
0
def get_contest():
    """returns a test contest"""
    CONTEST_ARGS = {
        "name": "1620 bracket",
        "start_time": util.str_to_dt("2017-01-25T11:00:00Z"),
        "end_time": util.str_to_dt("2017-01-25T16:45:00Z"),
        "is_public": True,
    }

    # create and add contest
    contest = model.Contest(**CONTEST_ARGS)
    db_session.add(contest)
    db_session.commit()

    return CONTEST_ARGS, contest
Example #3
0
    def test_str_to_dt(self):
        """test the str_to_dt function"""

        time = "2018-03-29T03:47:42Z"
        dt = util.str_to_dt(time)

        self.assertEqual(dt, datetime.datetime(2018, 3, 29, 3, 47, 42))
Example #4
0
def setup_contest():
    roles = {x.name: x for x in model.UserRole.query.all()}
    test_contestant = model.User(
        "testuser", "Test User", "pass", user_roles=[roles["defendant"]]
    )
    test_executioner = model.User(
        "testexec", "Test Executioner", "epass", user_roles=[roles["executioner"]]
    )
    test_contest = model.Contest(
        "test_contest",
        util.str_to_dt("2017-02-05T22:04:00Z"),
        util.str_to_dt("2030-01-01T11:11:00Z"),
        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,
        util.str_to_dt("2017-02-05T23:00: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,
    )

    db_session.add_all(
        [test_executioner, test_contestant, test_contest, test_problem, test_run]
    )
    db_session.commit()
Example #5
0
def get_user():
    """returns a test user"""
    USER_ARGS = {
        "username": "******",
        "name": "Test A. B. User",
        "password": "******",
        "creation_time": util.str_to_dt("2017-01-01T12:12:00Z"),
        "misc_data": '{"teacher": "Cavanaugh"}',
    }

    # create and add user
    user = model.User(**USER_ARGS)
    db_session.add(user)
    db_session.commit()

    return USER_ARGS, user
Example #6
0
    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": util.str_to_dt("2017-01-26T10:45:00Z"),
        }
        saved_code = model.SavedCode(**SAVED_CODE_ARGS)
        db_session.add(saved_code)
        db_session.commit()
Example #7
0
    def test_user(self):
        """test the user table"""
        USER_ARGS = {
            "username": "******",
            "name": "Test A. B. User",
            "password": "******",
            "creation_time": util.str_to_dt("2017-01-01T12:12:00Z"),
            "misc_data": '{"teacher": "Cavanaugh"}',
        }

        # create and add user
        user = model.User(**USER_ARGS)
        db_session.add(user)
        db_session.commit()

        # fetch user
        results = model.User.query.filter_by(username=USER_ARGS["username"]).all()

        self.assertEqual(len(results), 1)
Example #8
0
    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": util.str_to_dt("2017-01-26T10:45:00Z"),
            "source_code": "print('hello'*input())",
            "run_input": "5",
            "correct_output": "hellohellohellohellohello",
            "is_submission": True,
        }
        run = model.Run(**RUN_ARGS)
        db_session.add(run)
        db_session.commit()