This commit is contained in:
virusdefender 2016-10-28 01:04:50 +08:00
parent 69bb2ae79b
commit 02441294ac
4 changed files with 61 additions and 1 deletions

13
.travis.yml Normal file
View 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
View File

View File

@ -1,7 +1,7 @@
version: "2"
services:
judge_server:
image: judge_server
image: qduoj/judge_server
cpu_quota: 90000
read_only: true
cap_drop:

47
tests/tests.py Normal file
View 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()