def register_environment() -> Response: _, body = _validate_request() with transaction() as s: _ = _validate_token(s, admin_required=True) e = Environment(name=body.name, active=getattr(body, 'active', True), published=getattr(body, 'published', False), compile_image_name=getattr(body, 'compile_image_name', ''), test_image_name=body.test_image_name) s.add(e) s.flush() return jsonify(e.to_dict())
def test_submission(self, mock_conn, mock_get_params): # TODO(kazuki): API経由に書き換える env = dict(name='Python 3.7', test_image_name='docker-image') with transaction() as s: env = Environment(**env) s.add(env) s.flush() env = env.to_dict() start_time = datetime.now(tz=timezone.utc) contest_id = app.post_json('/contests', { 'id': 'abc000', 'title': 'ABC000', 'description': '# ABC000\n\nほげほげ\n', 'start_time': start_time.isoformat(), 'end_time': (start_time + timedelta(hours=1)).isoformat(), 'published': True, }, headers=self.admin_headers).json['id'] prefix = '/contests/{}'.format(contest_id) app.post_json( '{}/problems'.format(prefix), dict( id='A', title='A Problem', description='# A', time_limit=2, score=100 ), headers=self.admin_headers) # TODO(kazuki): API経由に書き換える ctx = ZstdCompressor() with transaction() as s: s.add(TestCase( contest_id=contest_id, problem_id='A', id='1', input=ctx.compress(b'1'), output=ctx.compress(b'2'))) app.get('{}/submissions'.format(prefix), status=403) self.assertEqual([], app.get( '{}/submissions'.format(prefix), headers=self.admin_headers).json) app.get('/contests/invalid/submissions', status=404) code = 'print("Hello World")' resp = app.post_json('{}/submissions'.format(prefix), { 'problem_id': 'A', 'environment_id': env['id'], 'code': code, }, headers=self.admin_headers).json self.assertEqual([resp], app.get( '{}/submissions'.format(prefix), headers=self.admin_headers).json) app.get('{}/submissions/{}'.format(prefix, resp['id']), status=404) resp2 = app.get('{}/submissions/{}'.format(prefix, resp['id']), headers=self.admin_headers).json self.assertEqual(resp2.pop('code'), code) resp['tests'] = [] self.assertEqual(resp, resp2) app.post_json('{}/submissions'.format(prefix), { 'problem_id': 'invalid', 'environment_id': env['id'], 'code': code, }, headers=self.admin_headers, status=400) app.post_json('{}/submissions'.format(prefix), { 'problem_id': 'A', 'environment_id': 99999, 'code': code, }, headers=self.admin_headers, status=400) app.get('{}/submissions/99999'.format(prefix), status=404) contest_id2 = app.post_json('/contests', { 'id': 'abc001', 'title': 'ABC001', 'description': '# ABC001', 'start_time': start_time.isoformat(), 'end_time': (start_time + timedelta(hours=1)).isoformat(), }, headers=self.admin_headers).json['id'] app.get( '/contests/{}/submissions/{}'.format(contest_id2, resp['id']), status=404) with transaction() as s: s.query(Contest).update({'end_time': start_time}) app.get('{}/submissions'.format(prefix))