Beispiel #1
0
 def get_task(**kwargs):
     """Create a task"""
     args = {
         "name": unique_unicode_id(),
         "title": unique_unicode_id(),
     }
     args.update(kwargs)
     task = Task(**args)
     return task
Beispiel #2
0
 def get_task(cls, **kwargs):
     """Create a task"""
     args = {
         "name": unique_unicode_id(),
         "title": unique_unicode_id(),
     }
     args.update(kwargs)
     task = Task(**args)
     return task
Beispiel #3
0
 def get_contest(cls, **kwargs):
     """Create a contest"""
     args = {
         "name": unique_unicode_id(),
         "description": unique_unicode_id(),
     }
     args.update(kwargs)
     contest = Contest(**args)
     return contest
Beispiel #4
0
 def get_team(**kwargs):
     """Create a team"""
     args = {
         "code": unique_unicode_id(),
         "name": unique_unicode_id(),
     }
     args.update(kwargs)
     team = Team(**args)
     return team
Beispiel #5
0
 def get_team(cls, **kwargs):
     """Create a team"""
     args = {
         "code": unique_unicode_id(),
         "name": unique_unicode_id(),
     }
     args.update(kwargs)
     team = Team(**args)
     return team
Beispiel #6
0
 def get_contest(**kwargs):
     """Create a contest"""
     args = {
         "name": unique_unicode_id(),
         "description": unique_unicode_id(),
     }
     args.update(kwargs)
     contest = Contest(**args)
     return contest
Beispiel #7
0
 def add_contest(self, **kwargs):
     """Add a contest."""
     args = {
         "name": unique_unicode_id(),
         "description": unique_unicode_id(),
     }
     args.update(kwargs)
     contest = Contest(**args)
     self.session.add(contest)
     return contest
Beispiel #8
0
 def get_user(cls, **kwargs):
     """Create a user"""
     args = {
         "username": unique_unicode_id(),
         "password": "",
         "first_name": unique_unicode_id(),
         "last_name": unique_unicode_id(),
     }
     args.update(kwargs)
     user = User(**args)
     return user
Beispiel #9
0
 def get_user(**kwargs):
     """Create a user"""
     args = {
         "username": unique_unicode_id(),
         "password": "",
         "first_name": unique_unicode_id(),
         "last_name": unique_unicode_id(),
     }
     args.update(kwargs)
     user = User(**args)
     return user
Beispiel #10
0
 def get_announcement(cls, contest=None, **kwargs):
     """Create an announcement"""
     contest = contest if contest is not None else cls.get_contest()
     args = {
         "contest": contest,
         "subject": unique_unicode_id(),
         "text": unique_unicode_id(),
         "timestamp": (contest.start + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     announcement = Announcement(**args)
     return announcement
Beispiel #11
0
 def get_announcement(cls, contest=None, **kwargs):
     """Create an announcement"""
     contest = contest if contest is not None else cls.get_contest()
     args = {
         "contest": contest,
         "subject": unique_unicode_id(),
         "text": unique_unicode_id(),
         "timestamp": (contest.start + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     announcement = Announcement(**args)
     return announcement
Beispiel #12
0
 def add_task(self, contest=None, **kwargs):
     """Add a task."""
     contest = contest if contest is not None else self.add_contest()
     args = {
         "contest": contest,
         "name": unique_unicode_id(),
         "title": unique_unicode_id(),
     }
     args.update(kwargs)
     task = Task(**args)
     self.session.add(task)
     return task
Beispiel #13
0
 def add_user(self, **kwargs):
     """Add a user."""
     args = {
         "username": unique_unicode_id(),
         "password": "",
         "first_name": unique_unicode_id(),
         "last_name": unique_unicode_id(),
     }
     args.update(kwargs)
     user = User(**args)
     self.session.add(user)
     return user
Beispiel #14
0
 def add_testcase(self, dataset=None, **kwargs):
     """Add a testcase."""
     dataset = dataset if dataset is not None else self.add_dataset()
     args = {
         "dataset": dataset,
         "codename": unique_unicode_id(),
         "input": unique_unicode_id(),
         "output": unique_unicode_id(),
     }
     args.update(kwargs)
     testcase = Testcase(**args)
     self.session.add(testcase)
     return testcase
Beispiel #15
0
 def add_testcase(self, dataset=None, **kwargs):
     """Add a testcase."""
     dataset = dataset if dataset is not None else self.add_dataset()
     args = {
         "dataset": dataset,
         "codename": unique_unicode_id(),
         "input": unique_unicode_id(),
         "output": unique_unicode_id(),
     }
     args.update(kwargs)
     testcase = Testcase(**args)
     self.session.add(testcase)
     return testcase
Beispiel #16
0
 def get_question(cls, participation=None, **kwargs):
     """Create a question."""
     participation = participation if participation is not None \
         else cls.get_participation()
     args = {
         "participation": participation,
         "subject": unique_unicode_id(),
         "text": unique_unicode_id(),
         "question_timestamp": (participation.contest.start
                                + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     question = Question(**args)
     return question
Beispiel #17
0
 def get_message(cls, participation=None, **kwargs):
     """Create a message."""
     participation = participation if participation is not None \
         else cls.get_participation()
     args = {
         "participation": participation,
         "subject": unique_unicode_id(),
         "text": unique_unicode_id(),
         "timestamp": (participation.group.start
                       + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     message = Message(**args)
     return message
Beispiel #18
0
 def get_question(cls, participation=None, **kwargs):
     """Create a question."""
     participation = participation if participation is not None \
         else cls.get_participation()
     args = {
         "participation": participation,
         "subject": unique_unicode_id(),
         "text": unique_unicode_id(),
         "question_timestamp": (participation.contest.start
                                + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     question = Question(**args)
     return question
Beispiel #19
0
    def setUp(self):
        super().setUp()

        self.score_info = (unique_long_id(), unique_long_id(),
                           unique_long_id(), unique_long_id(),
                           [unique_unicode_id(), unique_unicode_id()])

        patcher = patch("cms.db.Dataset.score_type_object",
                        new_callable=PropertyMock)
        self.score_type = patcher.start().return_value
        self.addCleanup(patcher.stop)
        self.call_args = list()
        self.score_type.compute_score.side_effect = self.compute_score

        self.contest = self.add_contest()
Beispiel #20
0
    def setUp(self):
        super().setUp()

        self.score_info = (unique_long_id(), unique_long_id(),
                           unique_long_id(), unique_long_id(),
                           [unique_unicode_id(), unique_unicode_id()])

        patcher = patch("cms.db.Dataset.score_type_object",
                        new_callable=PropertyMock)
        self.score_type = patcher.start().return_value
        self.addCleanup(patcher.stop)
        self.call_args = list()
        self.score_type.compute_score.side_effect = self.compute_score

        self.contest = self.add_contest()
Beispiel #21
0
 def get_contest(cls, **kwargs):
     """Create a contest"""
     grpargs = {}
     for a in ["start", "stop", "per_user_time"]:
         if a in kwargs:
             grpargs[a] = kwargs[a]
             del kwargs[a]
     args = {
         "name": unique_unicode_id(),
         "description": unique_unicode_id(),
         "main_group": cls.get_group(**grpargs),
     }
     args["groups"] = [args["main_group"]]
     args.update(kwargs)
     contest = Contest(**args)
     return contest
Beispiel #22
0
 def get_contest(cls, **kwargs):
     """Create a contest"""
     grpargs = {}
     for a in ["start", "stop", "per_user_time"]:
         if a in kwargs:
             grpargs[a] = kwargs[a]
             del kwargs[a]
     args = {
         "name": unique_unicode_id(),
         "description": unique_unicode_id(),
         "main_group": cls.get_group(**grpargs),
     }
     args["groups"] = [args["main_group"]]
     args.update(kwargs)
     contest = Contest(**args)
     return contest
Beispiel #23
0
 def get_message(participation=None, **kwargs):
     """Create a message."""
     participation = participation \
         if participation is not None else DatabaseMixin.get_participation()
     args = {
         "participation":
         participation,
         "subject":
         unique_unicode_id(),
         "text":
         unique_unicode_id(),
         "timestamp":
         (participation.contest.start + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     message = Message(**args)
     return message
Beispiel #24
0
 def get_message(cls, participation=None, **kwargs):
     """Create a message."""
     participation = participation if participation is not None \
         else cls.get_participation()
     args = {
         "participation":
         participation,
         "subject":
         unique_unicode_id(),
         "text":
         unique_unicode_id(),
         "timestamp":
         (participation.group.start + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     message = Message(**args)
     return message
Beispiel #25
0
 def get_manager(cls, dataset=None, **kwargs):
     """Create a manager."""
     dataset = dataset if dataset is not None else cls.get_dataset()
     args = {
         "dataset": dataset,
         "filename": unique_unicode_id(),
         "digest": unique_digest(),
     }
     args.update(kwargs)
     manager = Manager(**args)
     return manager
Beispiel #26
0
 def get_manager(cls, dataset=None, **kwargs):
     """Create a manager."""
     dataset = dataset if dataset is not None else cls.get_dataset()
     args = {
         "dataset": dataset,
         "filename": unique_unicode_id(),
         "digest": unique_digest(),
     }
     args.update(kwargs)
     manager = Manager(**args)
     return manager
Beispiel #27
0
 def add_submission_format_element(self, task=None, **kwargs):
     """Create a submission format element and add it to the session"""
     task = task if task is not None else self.add_task()
     args = {
         "task": task,
         "filename": unique_unicode_id(),
     }
     args.update(kwargs)
     sfe = SubmissionFormatElement(**args)
     self.session.add(sfe)
     return sfe
Beispiel #28
0
 def add_statement(self, task=None, **kwargs):
     """Create a statement and add it to the session"""
     task = task if task is not None else self.add_task()
     args = {
         "task": task,
         "digest": unique_digest(),
         "language": unique_unicode_id(),
     }
     args.update(kwargs)
     statement = Statement(**args)
     self.session.add(statement)
     return statement
Beispiel #29
0
 def add_statement(self, task=None, **kwargs):
     """Create a statement and add it to the session"""
     task = task if task is not None else self.add_task()
     args = {
         "task": task,
         "digest": unique_digest(),
         "language": unique_unicode_id(),
     }
     args.update(kwargs)
     statement = Statement(**args)
     self.session.add(statement)
     return statement
Beispiel #30
0
 def get_manager(dataset=None, **kwargs):
     """Create a manager."""
     if dataset is None:
         dataset = DatabaseMixin.get_dataset()
     args = {
         "dataset": dataset,
         "filename": unique_unicode_id(),
         "digest": unique_digest(),
     }
     args.update(kwargs)
     manager = Manager(**args)
     return manager
Beispiel #31
0
 def add_user_test_manager(self, user_test=None, **kwargs):
     """Create a user test manager and add it to the session"""
     if user_test is None:
         user_test = self.add_user_test()
     args = {
         "user_test": user_test,
         "filename": unique_unicode_id(),
         "digest": unique_digest(),
     }
     args.update(kwargs)
     user_test_manager = UserTestManager(**args)
     self.session.add(user_test_manager)
     return user_test_manager
Beispiel #32
0
 def add_user_test_manager(self, user_test=None, **kwargs):
     """Create a user test manager and add it to the session"""
     if user_test is None:
         user_test = self.add_user_test()
     args = {
         "user_test": user_test,
         "filename": unique_unicode_id(),
         "digest": unique_digest(),
     }
     args.update(kwargs)
     user_test_manager = UserTestManager(**args)
     self.session.add(user_test_manager)
     return user_test_manager
Beispiel #33
0
 def add_file(self, submission=None, **kwargs):
     """Create a file and add it to the session"""
     if submission is None:
         submission = self.add_submission()
     args = {
         "submission": submission,
         "filename": unique_unicode_id(),
         "digest": unique_digest(),
     }
     args.update(kwargs)
     file_ = File(**args)
     self.session.add(file_)
     return file_
Beispiel #34
0
 def add_file(self, submission=None, **kwargs):
     """Create a file and add it to the session"""
     if submission is None:
         submission = self.add_sbubmission()
     args = {
         "submission": submission,
         "filename": unique_unicode_id(),
         "digest": unique_digest(),
     }
     args.update(kwargs)
     file = File(**args)
     self.session.add(file)
     return file
Beispiel #35
0
 def get_dataset(cls, task=None, **kwargs):
     """Create a dataset"""
     task = task if task is not None else cls.get_task()
     args = {
         "task": task,
         "description": unique_unicode_id(),
         "task_type": "Batch",
         "task_type_parameters": ["alone", ["", ""], "diff"],
         "score_type": "Sum",
         "score_type_parameters": 100,
     }
     args.update(kwargs)
     dataset = Dataset(**args)
     return dataset
Beispiel #36
0
 def add_executable(self, submission_result=None, **kwargs):
     """Create an executable and add it to the session"""
     submission_result = submission_result \
         if submission_result is not None \
         else self.add_submission_result()
     args = {
         "submission_result": submission_result,
         "digest": unique_digest(),
         "filename": unique_unicode_id(),
     }
     args.update(kwargs)
     executable = Executable(**args)
     self.session.add(executable)
     return executable
Beispiel #37
0
 def add_executable(self, submission_result=None, **kwargs):
     """Create an executable and add it to the session"""
     submission_result = submission_result \
         if submission_result is not None \
         else self.add_submission_result()
     args = {
         "submission_result": submission_result,
         "digest": unique_digest(),
         "filename": unique_unicode_id(),
     }
     args.update(kwargs)
     executable = Executable(**args)
     self.session.add(executable)
     return executable
Beispiel #38
0
 def add_dataset(self, task=None, **kwargs):
     """Add a dataset."""
     task = task if task is not None else self.add_task()
     args = {
         "task": task,
         "description": unique_unicode_id(),
         "task_type": "",
         "task_type_parameters": "",
         "score_type": "",
         "score_type_parameters": "",
     }
     args.update(kwargs)
     dataset = Dataset(**args)
     self.session.add(dataset)
     return dataset
Beispiel #39
0
 def add_user_test(self, task=None, participation=None, **kwargs):
     """Add a user test."""
     task = task if task is not None else self.add_task()
     participation = participation \
         if participation is not None \
         else self.add_participation(contest=task.contest)
     assert task.contest == participation.contest
     args = {
         "task": task,
         "participation": participation,
         "input": unique_unicode_id(),
         "timestamp": (task.contest.start + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     user_test = UserTest(**args)
     self.session.add(user_test)
     return user_test
Beispiel #40
0
 def new_jobs(number_of_jobs, prefix=None):
     prefix = prefix if prefix is not None else ""
     jobs = []
     calls = []
     for i in range(number_of_jobs):
         job_params = [
             ESOperation(ESOperation.EVALUATION, unique_long_id(),
                         unique_long_id(), unique_unicode_id()).to_dict(),
             "fake_task_type",
             "fake_parameters_%s%d" % (prefix, i)
         ]
         job = EvaluationJob(*job_params, info="%s%d" % (prefix, i))
         jobs.append(job)
         # Arguments to get_task_type are the same as for the job,
         # but omitting the operation.
         calls.append(call(*job_params[1:]))
     return jobs, calls
Beispiel #41
0
 def add_user_test(self, task=None, participation=None, **kwargs):
     """Add a user test."""
     task = task if task is not None else self.add_task()
     participation = participation \
         if participation is not None \
         else self.add_participation(contest=task.contest)
     assert task.contest == participation.contest
     args = {
         "task": task,
         "participation": participation,
         "input": unique_unicode_id(),
         "timestamp": (task.contest.start + timedelta(0, unique_long_id())),
     }
     args.update(kwargs)
     user_test = UserTest(**args)
     self.session.add(user_test)
     return user_test
Beispiel #42
0
 def new_jobs(number_of_jobs, prefix=None):
     prefix = prefix if prefix is not None else ""
     jobs = []
     calls = []
     for i in xrange(number_of_jobs):
         job_params = [
             ESOperation(ESOperation.EVALUATION,
                         unique_long_id(), unique_long_id(),
                         unique_unicode_id()).to_dict(),
             "fake_task_type",
             "fake_parameters_%s%d" % (prefix, i)
         ]
         job = EvaluationJob(*job_params, info="%s%d" % (prefix, i))
         jobs.append(job)
         # Arguments to get_task_type are the same as for the job,
         # but omitting the operation.
         calls.append(call(*job_params[1:]))
     return jobs, calls
Beispiel #43
0
 def get_dataset(cls, task=None, **kwargs):
     """Create a dataset"""
     task = task if task is not None else cls.get_task()
     args = {
         "task": task,
         "description": unique_unicode_id(),
         "task_type": "",
         # "None" won't work here as the column is defined as non
         # nullable. As soon as we'll depend on SQLAlchemy 1.1 we
         # will be able to put JSON.NULL here instead.
         "task_type_parameters": {},
         "score_type": "",
         # Same here.
         "score_type_parameters": {},
     }
     args.update(kwargs)
     dataset = Dataset(**args)
     return dataset
Beispiel #44
0
 def get_dataset(task=None, **kwargs):
     """Create a dataset"""
     task = task if task is not None else TestCaseWithDatabase.get_task()
     args = {
         "task": task,
         "description": unique_unicode_id(),
         "task_type": "",
         # "None" won't work here as the column is defined as non
         # nullable. As soon as we'll depend on SQLAlchemy 1.1 we
         # will be able to put JSON.NULL here instead.
         "task_type_parameters": {},
         "score_type": "",
         # Same here.
         "score_type_parameters": {},
     }
     args.update(kwargs)
     dataset = Dataset(**args)
     return dataset
Beispiel #45
0
    def setUp(self):
        super().setUp()

        # Set up patches and mocks for a successful run. These are all
        # controlled by the following values, which can be changed to
        # make some steps fail. The task will require a language-aware
        # submission with three files: foo.%l, bar.%l and baz.%l; the
        # first will be provided by the contestant, the second will be
        # fetched from the previous submission (as partial submissions
        # will be allowed), the third will be missing.

        self.contest = self.add_contest(
            languages=["MockLanguage", "AnotherMockLanguage"])
        self.participation = self.add_participation(
            contest=self.contest)
        self.task = self.add_task(
            submission_format=["foo.%l", "bar.%l", "baz.%l"],
            contest=self.contest)
        self.dataset = self.add_dataset(
            task=self.task)
        self.task.active_dataset = self.dataset

        self.timestamp = make_datetime()
        self.tornado_files = sentinel.tornado_files
        self.language_name = sentinel.language_name
        self.official = True
        self.received_files = sentinel.received_files
        self.files = {"foo.%l": FOO_CONTENT}
        # Multiple extensions, primary one doesn't start with a period.
        self.language = make_language("MockLanguage", ["mock.1", ".mock2"])
        self.digests = {"bar.%l": bytes_digest(BAR_CONTENT)}
        self.submit_local_copy_path = unique_unicode_id()

        patcher = patch('cms.db.Dataset.task_type_object',
                        new_callable=PropertyMock)
        self.task_type = patcher.start().return_value
        self.addCleanup(patcher.stop)
        self.task_type.ALLOW_PARTIAL_SUBMISSION = True

        patcher = patch(
            "cms.server.contest.submission.workflow.check_max_number")
        self.check_max_number = patcher.start()
        self.addCleanup(patcher.stop)
        self.check_max_number.return_value = True

        patcher = patch(
            "cms.server.contest.submission.workflow.check_min_interval")
        self.check_min_interval = patcher.start()
        self.addCleanup(patcher.stop)
        self.check_min_interval.return_value = True

        patcher = patch(
            "cms.server.contest.submission.workflow.extract_files_from_tornado")
        self.extract_files_from_tornado = patcher.start()
        self.addCleanup(patcher.stop)
        self.extract_files_from_tornado.return_value = self.received_files

        patcher = patch(
            "cms.server.contest.submission.workflow.match_files_and_language")
        self.match_files_and_language = patcher.start()
        self.addCleanup(patcher.stop)
        # Use side_effect to keep it working if we reassign the values.
        self.match_files_and_language.side_effect = \
            lambda *args, **kwargs: (self.files, self.language)

        patcher = patch(
            "cms.server.contest.submission.workflow"
            ".fetch_file_digests_from_previous_submission")
        self.fetch_file_digests_from_previous_submission = patcher.start()
        self.addCleanup(patcher.stop)
        # Use side_effect to keep it working if we reassign the value.
        self.fetch_file_digests_from_previous_submission.side_effect = \
            lambda *args, **kwargs: self.digests

        patcher = patch.object(config, "submit_local_copy", True)
        patcher.start()
        self.addCleanup(patcher.stop)

        patcher = patch.object(
            config, "submit_local_copy_path", self.submit_local_copy_path)
        patcher.start()
        self.addCleanup(patcher.stop)

        patcher = patch(
            "cms.server.contest.submission.workflow.store_local_copy")
        self.store_local_copy = patcher.start()
        self.addCleanup(patcher.stop)

        self.file_cacher = MagicMock()
        self.file_cacher.put_file_content.side_effect = \
            lambda content, _: bytes_digest(content)
Beispiel #46
0
 def generate_content():
     return unique_unicode_id().encode('utf-8')