summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/forms.py1
-rw-r--r--yaksh/models.py28
-rw-r--r--yaksh/tests.py1
3 files changed, 18 insertions, 12 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index 26e0967..92b0ee0 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -227,4 +227,3 @@ class ProfileForm(forms.ModelForm):
class UploadFileForm(forms.Form):
file = forms.FileField()
-
diff --git a/yaksh/models.py b/yaksh/models.py
index 6ee02e1..c8d67ec 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -171,7 +171,7 @@ class Question(models.Model):
# The type of evaluator
test_case_type = models.CharField(max_length=24, choices=test_case_types)
-
+
# Is this question active or not. If it is inactive it will not be used
# when creating a QuestionPaper.
active = models.BooleanField(default=True)
@@ -201,17 +201,19 @@ class Question(models.Model):
return json.dumps(question_data)
def dump_into_json(self, question_ids, user):
- questions = Question.objects.filter(id__in = question_ids, user_id = user.id)
+ questions = Question.objects.filter(id__in=question_ids, user_id=user.id)
questions_dict = []
for question in questions:
- q_dict = {'summary': question.summary,
- 'description': question.description,
- 'points': question.points,
- 'language': question.language,
- 'type': question.type,
- 'active': question.active,
- 'test_case_type': question.test_case_type,
- 'snippet': question.snippet}
+ test_case = question.get_test_cases()
+ q_dict = {'summary': question.summary,
+ 'description': question.description,
+ 'points': question.points,
+ 'language': question.language,
+ 'type': question.type,
+ 'active': question.active,
+ 'test_case_type': question.test_case_type,
+ 'snippet': question.snippet,
+ 'testcase': [case.get_field_value() for case in test_case]}
questions_dict.append(q_dict)
return json.dumps(questions_dict, indent=2)
@@ -220,7 +222,11 @@ class Question(models.Model):
questions = json.loads(questions_list)
for question in questions:
question['user'] = user
- Question.objects.get_or_create(**question)
+ test_cases = question.pop('testcase')
+ que, result = Question.objects.get_or_create(**question)
+ model_class = get_model_class(que.test_case_type)
+ for test_case in test_cases:
+ model_class.objects.get_or_create(question=que, **test_case)
def get_test_cases(self, **kwargs):
test_case_ctype = ContentType.objects.get(app_label="yaksh",
diff --git a/yaksh/tests.py b/yaksh/tests.py
index f2083dd..88c2efc 100644
--- a/yaksh/tests.py
+++ b/yaksh/tests.py
@@ -136,6 +136,7 @@ class QuestionTestCases(unittest.TestCase):
self.assertEqual(self.question2.points, q['points'])
self.assertTrue(self.question2.active)
self.assertEqual(self.question2.snippet, q['snippet'])
+ self.assertEqual(self.question2.get_test_cases(), q['testcase'])
def test_load_questions_from_json(self):
""" Test load questions into database from json """