From 02441294ac0e44f31698876f8ebb54150c4aab52 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Fri, 28 Oct 2016 01:04:50 +0800 Subject: [PATCH] ci --- .travis.yml | 13 +++++++++++ client/__init__.py | 0 docker-compose.example.yml | 2 +- tests/tests.py | 47 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 client/__init__.py create mode 100644 tests/tests.py diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4524d75 --- /dev/null +++ b/.travis.yml @@ -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 \ No newline at end of file diff --git a/client/__init__.py b/client/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 619aff8..37a3502 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -1,7 +1,7 @@ version: "2" services: judge_server: - image: judge_server + image: qduoj/judge_server cpu_quota: 90000 read_only: true cap_drop: diff --git a/tests/tests.py b/tests/tests.py new file mode 100644 index 0000000..fc6f7c8 --- /dev/null +++ b/tests/tests.py @@ -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() \ No newline at end of file