Example #1
0
    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)

        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",
        "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)
    db_session.add(contest)
    db_session.commit()

    return CONTEST_ARGS, contest
Example #3
0
def setup_contest():
    roles = {x.name: 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)

    db_session.add_all([
        test_executioner, test_contestant, test_contest, test_problem, test_run
    ])
    db_session.commit()
Example #4
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": model.str_to_dt('2017-01-26T10:45Z'),
        }
        saved_code = model.SavedCode(**SAVED_CODE_ARGS)
        db_session.add(saved_code)
        db_session.commit()
Example #5
0
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)
    db_session.add(user)
    db_session.commit()

    return USER_ARGS, user
Example #6
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": 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)
        db_session.add(run)
        db_session.commit()
Example #7
0
    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)
        db_session.add(user)
        db_session.commit()

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

        self.assertEqual(len(results), 1)