From 83b4826a242a6825197e42eb233f9301f99f3716 Mon Sep 17 00:00:00 2001
From: adityacp
Date: Mon, 25 Apr 2016 14:34:54 +0530
Subject: added test cases for loading and dumping questions
---
yaksh/models.py | 21 +++++++++++
yaksh/templates/yaksh/showquestions.html | 2 +-
yaksh/tests.py | 38 +++++++++++++++++++
yaksh/views.py | 64 ++++++++------------------------
4 files changed, 76 insertions(+), 49 deletions(-)
(limited to 'yaksh')
diff --git a/yaksh/models.py b/yaksh/models.py
index c76d655..b7df67c 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -211,6 +211,27 @@ class Question(models.Model):
return json.dumps(question_info_dict)
+ def dump_questions_into_json(self, user):
+ questions = Question.objects.filter(user_id = user.id)
+ questions_dict = [{'summary': question.summary,
+ 'description': question.description,
+ 'points': question.points, 'test': question.test,
+ 'ref_code_path': question.ref_code_path,
+ 'options': question.options, 'language': question.language,
+ 'type': question.type, 'active': question.active,
+ 'snippet': question.snippet} for question in questions]
+ return json.dumps(questions_dict, indent=2)
+
+ def load_questions_from_json(self, questions_list, user):
+ questions = json.loads(questions_list)
+ for question in questions:
+ Question.objects.get_or_create(summary=question['summary'],
+ description=question['description'], points=question['points'],
+ test=question['test'], ref_code_path=question['ref_code_path'],
+ options=question['options'], language=question['language'],
+ type=question['type'], active=question['active'],
+ snippet=question['snippet'], user=user)
+
def __unicode__(self):
return self.summary
diff --git a/yaksh/templates/yaksh/showquestions.html b/yaksh/templates/yaksh/showquestions.html
index ba96728..19fc06e 100644
--- a/yaksh/templates/yaksh/showquestions.html
+++ b/yaksh/templates/yaksh/showquestions.html
@@ -15,7 +15,7 @@
Download Questions
{% endif %}
-