summaryrefslogtreecommitdiff
path: root/testapp/exam
diff options
context:
space:
mode:
authorankitjavalkar2015-02-04 20:03:13 +0530
committerankitjavalkar2015-04-26 19:28:18 +0530
commit28e2d32f9839b0e3cb3e99ce0113832627610bd7 (patch)
tree60f3943c8b6ae5696920e9fc79bf897efcf1a360 /testapp/exam
parentcd9f2542d09db0e4a352dd410f626f27e23c37e4 (diff)
downloadonline_test-28e2d32f9839b0e3cb3e99ce0113832627610bd7.tar.gz
online_test-28e2d32f9839b0e3cb3e99ce0113832627610bd7.tar.bz2
online_test-28e2d32f9839b0e3cb3e99ce0113832627610bd7.zip
Add test case model for testing redesign
Conflicts: testapp/exam/models.py testapp/exam/views.py
Diffstat (limited to 'testapp/exam')
-rwxr-xr-xtestapp/exam/code_server.py12
-rw-r--r--testapp/exam/models.py28
-rw-r--r--testapp/exam/templates/exam/add_question.html3
-rw-r--r--testapp/exam/views.py11
-rw-r--r--testapp/exam/xmlrpc_clients.py4
5 files changed, 49 insertions, 9 deletions
diff --git a/testapp/exam/code_server.py b/testapp/exam/code_server.py
index 792197d..64d6a47 100755
--- a/testapp/exam/code_server.py
+++ b/testapp/exam/code_server.py
@@ -68,7 +68,7 @@ class CodeServer(object):
'have an infinite loop in your code.' % SERVER_TIMEOUT
self.timeout_msg = msg
- def run_python_code(self, answer, test_code, in_dir=None):
+ def run_python_code(self, answer, test_code, test_obj, in_dir=None): ####
"""Tests given Python function (`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
@@ -123,7 +123,7 @@ class CodeServer(object):
return success, err
- def run_bash_code(self, answer, test_code, in_dir=None):
+ def run_bash_code(self, answer, test_code, test_obj, in_dir=None): ####
"""Tests given Bash code (`answer`) with the `test_code` supplied.
The testcode should typically contain two lines, the first is a path to
@@ -290,7 +290,7 @@ class CodeServer(object):
stdnt_stdout+stdnt_stderr)
return False, err
- def run_c_code(self, answer, test_code, in_dir=None):
+ def run_c_code(self, answer, test_code, test_obj, in_dir=None): ####
"""Tests given C code (`answer`) with the `test_code` supplied.
The testcode is a path to the reference code.
@@ -442,7 +442,7 @@ class CodeServer(object):
err = err + "\n" + stdnt_stderr
return success, err
- def run_cplus_code(self, answer, test_code, in_dir=None):
+ def run_cplus_code(self, answer, test_code, test_obj, in_dir=None): ####
"""Tests given C++ code (`answer`) with the `test_code` supplied.
The testcode is a path to the reference code.
@@ -504,7 +504,7 @@ class CodeServer(object):
return success, err
- def run_java_code(self, answer, test_code, in_dir=None):
+ def run_java_code(self, answer, test_code, test_obj, in_dir=None): ####
"""Tests given java code (`answer`) with the `test_code` supplied.
The testcode is a path to the reference code.
@@ -659,7 +659,7 @@ class CodeServer(object):
stripped = stripped + c
return ''.join(stripped)
- def run_scilab_code(self, answer, test_code, in_dir=None):
+ def run_scilab_code(self, answer, test_code, test_obj, in_dir=None): ####
"""Tests given Scilab function (`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
diff --git a/testapp/exam/models.py b/testapp/exam/models.py
index 72fb51b..df3b485 100644
--- a/testapp/exam/models.py
+++ b/testapp/exam/models.py
@@ -62,6 +62,15 @@ class Question(models.Model):
# Test cases for the question in the form of code that is run.
test = models.TextField(blank=True)
+ #Test case Keyword arguments in dict form
+ test_keyword_args = models.TextField(blank=True) ####
+
+ #Test case Positional arguments in list form
+ test_pos_args = models.TextField(blank=True) ####
+
+ #Test case Expected answer in list form
+ test_expected_answer = models.TextField(blank=True) ####
+
# Any multiple choice options. Place one option per line.
options = models.TextField(blank=True)
@@ -396,3 +405,22 @@ class AssignmentUpload(models.Model):
user = models.ForeignKey(Profile)
assignmentQuestion = models.ForeignKey(Question)
assignmentFile = models.FileField(upload_to=get_assignment_dir)
+
+
+################################################################################
+class TestCase(models.Model):
+ question = models.ForeignKey(Question)
+
+ # Test case Keyword arguments in dict form
+ test_keyword_args = models.TextField(blank=True)
+
+ # Test case Positional arguments in list form
+ test_pos_args = models.TextField(blank=True)
+
+ # Test case Expected answer in list form
+ test_expected_answer = models.TextField(blank=True)
+
+ # Is this Test Case public or not. If it is not
+ # public it will not be visible to the user
+ # public = models.BooleanField(default=False)
+
diff --git a/testapp/exam/templates/exam/add_question.html b/testapp/exam/templates/exam/add_question.html
index b0b22b1..b6ce908 100644
--- a/testapp/exam/templates/exam/add_question.html
+++ b/testapp/exam/templates/exam/add_question.html
@@ -28,6 +28,9 @@
<tr><td><strong>Rendered: </strong><td><p id='my'></p>
<tr><td>Description: <td>{{ form.description}} {{form.description.errors}}
<tr><td>Test: <td>{{ form.test }}{{form.test.errors}}
+ <tr><td>Test Keyword Arguments: <td>{{ form.test_keyword_args }}{{form.test.errors}} <!-- -->
+ <tr><td>Test Positional Arguments: <td>{{ form.test_pos_args }}{{form.test.errors}} <!-- -->
+ <tr><td>Test Expected Answer: <td>{{ form.test_expected_answer }}{{form.test.errors}} <!-- -->
<tr><td>Snippet: <td>{{ form.snippet }}{{ form.snippet.errors }}</td></tD></td></tr>
<tr><td>Tags: <td>{{ form.tags }}
<tr><td id='label_option'>Options: <td>{{ form.options }} {{form.options.errors}}
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 11aca06..9b6ce69 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -959,9 +959,18 @@ def validate_answer(user, user_answer, question):
elif question.type == 'code':
user_dir = get_user_dir(user)
success, message = code_server.run_code(user_answer, question.test,
- user_dir, question.language)
+ question.test_keyword_args, question.test_pos_args,
+ question.test_expected_answer, user_dir, question.language) ####
if success:
correct = True
+
+ ####
+ print "MESS>>>", question.test
+ print "POS>>>", question.test_pos_args
+ print "KEY>>>", question.test_keyword_args
+ print "EXP>>>", question.test_expected_answer
+ ####
+
return correct, success, message
diff --git a/testapp/exam/xmlrpc_clients.py b/testapp/exam/xmlrpc_clients.py
index 14ebf27..1aab8de 100644
--- a/testapp/exam/xmlrpc_clients.py
+++ b/testapp/exam/xmlrpc_clients.py
@@ -29,7 +29,7 @@ class CodeServerProxy(object):
"scilab": "run_scilab_code",
}
- def run_code(self, answer, test_code, user_dir, language):
+ def run_code(self, answer, test_code, test_obj, keyword_args, pos_args, expected_answer, user_dir, language): ####
"""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
@@ -55,7 +55,7 @@ class CodeServerProxy(object):
try:
server = self._get_server()
method = getattr(server, method_name)
- result = method(answer, test_code, user_dir)
+ result = method(answer, test_code, test_obj, user_dir) ####
except ConnectionError:
result = [False, 'Unable to connect to any code servers!']
return result