mirror of
https://github.com/QingdaoU/JudgeServer.git
synced 2024-12-28 21:31:43 +00:00
ci
This commit is contained in:
parent
69bb2ae79b
commit
02441294ac
13
.travis.yml
Normal file
13
.travis.yml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
sudo: required
|
||||||
|
language: python
|
||||||
|
services:
|
||||||
|
- docker
|
||||||
|
before_install:
|
||||||
|
- sudo mkdir -p /data/log
|
||||||
|
- pip install requests
|
||||||
|
script:
|
||||||
|
- docker pull qduoj/judge_server
|
||||||
|
- cp docker-compose.example.yml docker-compose.yml
|
||||||
|
- docker-compose up -d
|
||||||
|
- docker ps -a
|
||||||
|
- python tests/tests.py
|
0
client/__init__.py
Normal file
0
client/__init__.py
Normal file
@ -1,7 +1,7 @@
|
|||||||
version: "2"
|
version: "2"
|
||||||
services:
|
services:
|
||||||
judge_server:
|
judge_server:
|
||||||
image: judge_server
|
image: qduoj/judge_server
|
||||||
cpu_quota: 90000
|
cpu_quota: 90000
|
||||||
read_only: true
|
read_only: true
|
||||||
cap_drop:
|
cap_drop:
|
||||||
|
47
tests/tests.py
Normal file
47
tests/tests.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from os import sys, path
|
||||||
|
sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
|
||||||
|
|
||||||
|
import json
|
||||||
|
import unittest
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
from client.Python.client import JudgeServerClient, JudgeServerClientError
|
||||||
|
|
||||||
|
|
||||||
|
class JudgeServerClientForTokenHeaderTest(JudgeServerClient):
|
||||||
|
def _request(self, url, data=None):
|
||||||
|
kwargs = {"headers": {"Content-Type": "application/json"}}
|
||||||
|
if data:
|
||||||
|
kwargs["data"] = json.dumps(data)
|
||||||
|
try:
|
||||||
|
return requests.post(url, **kwargs).json()
|
||||||
|
except Exception as e:
|
||||||
|
raise JudgeServerClientError(e.message)
|
||||||
|
|
||||||
|
|
||||||
|
class JudgeServerTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.token = "token"
|
||||||
|
self.server_base_url = "http://127.0.0.1:12358"
|
||||||
|
self.client = JudgeServerClient(token=self.token, server_base_url=self.server_base_url)
|
||||||
|
|
||||||
|
def test_success(self):
|
||||||
|
data = self.client.ping()
|
||||||
|
self.assertEqual(data["err"], None)
|
||||||
|
self.assertEqual(data["data"]["action"], "pong")
|
||||||
|
|
||||||
|
def test_invalid_token(self):
|
||||||
|
client = JudgeServerClient(token="wrong token", server_base_url=self.server_base_url)
|
||||||
|
data = client.ping()
|
||||||
|
self.assertEqual(data["err"], "TokenVerificationFailed")
|
||||||
|
|
||||||
|
def test_no_token_header(self):
|
||||||
|
client = JudgeServerClientForTokenHeaderTest(token="wrong token", server_base_url=self.server_base_url)
|
||||||
|
data = client.ping()
|
||||||
|
self.assertEqual(data["err"], "TokenVerificationFailed")
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user