diff options
author | Prabhu Ramachandran | 2015-05-12 20:20:43 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2015-05-12 20:20:43 +0530 |
commit | a022e0145ec8fb1622d58c2e2281c016b1d45b01 (patch) | |
tree | 1c0c3f2e8605d6f36405c57cbe5de9a895a47958 /testapp/exam/xmlrpc_clients.py | |
parent | cd9f2542d09db0e4a352dd410f626f27e23c37e4 (diff) | |
parent | 5b23647de575fd90552807260a4b8e0a96ab6afe (diff) | |
download | online_test-a022e0145ec8fb1622d58c2e2281c016b1d45b01.tar.gz online_test-a022e0145ec8fb1622d58c2e2281c016b1d45b01.tar.bz2 online_test-a022e0145ec8fb1622d58c2e2281c016b1d45b01.zip |
Merge pull request #41 from ankitjavalkar/code-server-redesign-mymaster2
Code server redesign
Diffstat (limited to 'testapp/exam/xmlrpc_clients.py')
-rw-r--r-- | testapp/exam/xmlrpc_clients.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/testapp/exam/xmlrpc_clients.py b/testapp/exam/xmlrpc_clients.py index 14ebf27..8f5642e 100644 --- a/testapp/exam/xmlrpc_clients.py +++ b/testapp/exam/xmlrpc_clients.py @@ -21,15 +21,8 @@ class CodeServerProxy(object): def __init__(self): pool_url = 'http://localhost:%d' % (SERVER_POOL_PORT) self.pool_server = ServerProxy(pool_url) - self.methods = {"python": 'run_python_code', - "bash": 'run_bash_code', - "C": "run_c_code", - "C++": "run_cplus_code", - "java": "run_java_code", - "scilab": "run_scilab_code", - } - def run_code(self, answer, test_code, user_dir, language): + def run_code(self, language, json_data, user_dir): """Tests given code (`answer`) with the `test_code` supplied. If the optional `in_dir` keyword argument is supplied it changes the directory to that directory (it does not change it back to the original when @@ -38,26 +31,28 @@ class CodeServerProxy(object): Parameters ---------- - answer : str - The user's answer for the question. + json_data contains; + user_answer : str + The user's answer for the question. test_code : str The test code to check the user code with. - user_dir : str (directory) - The directory to run the tests inside. language : str The programming language to use. + user_dir : str (directory) + The directory to run the tests inside. + + Returns ------- - A tuple: (success, error message). + A json string of a dict: {success: success, err: error message}. """ - method_name = self.methods[language] + try: server = self._get_server() - method = getattr(server, method_name) - result = method(answer, test_code, user_dir) + result = server.check_code(language, json_data, user_dir) except ConnectionError: - result = [False, 'Unable to connect to any code servers!'] + result = json.dumps({'success': False, 'error': 'Unable to connect to any code servers!'}) return result def _get_server(self): |