def create_runs(self): self.runs = [ Run(problem_id=self.problems[0].id, user_id=self.users[0].id), Run(problem_id=self.problems[0].id, user_id=self.users[1].id), Run(problem_id=self.problems[0].id, user_id=self.users[2].id), ] db.session.add_all(self.runs)
def test_rejudge_failed_run(self, queue_submit_mock): run = Run(user_id=self.users[0].id, problem_id=self.problems[1].id, ejudge_status=1, ejudge_language_id=1, ejudge_contest_id=1, ejudge_url=None) db.session.add(run) db.session.commit() protocol = {'my_protocol': 'data', 'run_id': run.id} mongo.db.protocol.insert_one(protocol) del protocol['_id'] resp = self.send_request(run.id) self.assert200(resp) queue_submit_mock.assert_called_once() rejudge = db.session.query(Rejudge) \ .filter(Rejudge.run_id == run.id) \ .filter(Rejudge.ejudge_contest_id == run.ejudge_contest_id) \ .one_or_none() self.assertIsNone(rejudge)
def test_simple(self, queue_submit_mock): run = Run(user_id=self.users[0].id, problem_id=self.problems[1].id, ejudge_status=1, ejudge_language_id=1, ejudge_contest_id=1, ejudge_url='ej_url') db.session.add(run) db.session.commit() protocol = {'my_protocol': 'data', 'run_id': run.id} mongo.db.protocol.insert_one(protocol) del protocol['_id'] resp = self.send_request(run.id) self.assert200(resp) queue_submit_mock.assert_called_once() rejudge = db.session.query(Rejudge) \ .filter(Rejudge.run_id == run.id) \ .filter(Rejudge.ejudge_contest_id == run.ejudge_contest_id) \ .one() old_protocol = mongo.db.rejudge.find_one({'rejudge_id': rejudge.id}) del old_protocol['_id'] del old_protocol['rejudge_id'] self.assertEqual(old_protocol, protocol)
def create_runs(self, creation_time=None): if not hasattr(self, 'runs'): self.runs = [] runs = [ Run(problem_id=self.problems[0].id, user_id=self.users[0].id), Run(problem_id=self.problems[0].id, user_id=self.users[1].id), Run(problem_id=self.problems[0].id, user_id=self.users[2].id), ] if creation_time is not None: for run in runs: run.create_time = creation_time self.runs += runs db.session.add_all(runs) db.session.commit()
def setUp(self): super().setUp() self.create_ejudge_problems() self.create_problems() self.create_users() self.run = Run(user_id=self.users[0].id, problem_id=self.problems[1].id, ejudge_status=1, ejudge_language_id=1) db.session.add(self.run) db.session.commit()