From 66e8f39bb390b3ec2547d82512349fabf67e3d7c Mon Sep 17 00:00:00 2001 From: mahesh Date: Mon, 31 Jul 2017 17:22:54 +0530 Subject: Adds yaml serialization to download and upload questions --- yaksh/test_models.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'yaksh/test_models.py') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index c86d9a3..8dc3244 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -3,6 +3,7 @@ from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload import json +import yaml from datetime import datetime, timedelta from django.utils import timezone import pytz @@ -111,7 +112,7 @@ class QuestionTestCases(unittest.TestCase): user=self.user1 ) - self.question2 = Question.objects.create(summary='Demo Json', + self.question2 = Question.objects.create(summary='Yaml Json', language='python', type='code', active=True, @@ -159,8 +160,8 @@ class QuestionTestCases(unittest.TestCase): "language": "Python", "type": "Code", "testcase": self.test_case_upload_data, "files": [[file1, 0]], - "summary": "Json Demo"}] - self.json_questions_data = json.dumps(questions_data) + "summary": "Yaml Demo"}] + self.yaml_questions_data = yaml.safe_dump_all(questions_data) def tearDown(self): shutil.rmtree(self.load_tmp_path) @@ -191,7 +192,7 @@ class QuestionTestCases(unittest.TestCase): self.assertIn(tag, ['python', 'function']) def test_dump_questions(self): - """ Test dump questions into json """ + """ Test dump questions into Yaml """ question = Question() question_id = [self.question2.id] questions_zip = question.dump_questions(question_id, self.user2) @@ -200,8 +201,8 @@ class QuestionTestCases(unittest.TestCase): tmp_path = tempfile.mkdtemp() zip_file.extractall(tmp_path) test_case = self.question2.get_test_cases() - with open("{0}/questions_dump.json".format(tmp_path), "r") as f: - questions = json.loads(f.read()) + with open("{0}/questions_dump.yaml".format(tmp_path), "r") as f: + questions = yaml.safe_load_all(f.read()) for q in questions: self.assertEqual(self.question2.summary, q['summary']) self.assertEqual(self.question2.language, q['language']) @@ -216,13 +217,13 @@ class QuestionTestCases(unittest.TestCase): os.remove(os.path.join(tmp_path, file)) def test_load_questions(self): - """ Test load questions into database from json """ + """ Test load questions into database from Yaml """ question = Question() - result = question.load_questions(self.json_questions_data, self.user1) - question_data = Question.objects.get(summary="Json Demo") + result = question.load_questions(self.yaml_questions_data, self.user1) + question_data = Question.objects.get(summary="Yaml Demo") file = FileUpload.objects.get(question=question_data) test_case = question_data.get_test_cases() - self.assertEqual(question_data.summary, 'Json Demo') + self.assertEqual(question_data.summary, 'Yaml Demo') self.assertEqual(question_data.language, 'Python') self.assertEqual(question_data.type, 'Code') self.assertEqual(question_data.description, 'factorial of a no') -- cgit From 67f3119a2e27673694db907d21f501bc8247fce1 Mon Sep 17 00:00:00 2001 From: mahesh Date: Wed, 16 Aug 2017 18:28:26 +0530 Subject: Adds ruamel.yaml instead of pyyaml - Preserves escape characters - Adds ruamel.yaml in requirements --- yaksh/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/test_models.py') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 8dc3244..d5ac394 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -3,7 +3,7 @@ from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload import json -import yaml +import ruamel.yaml as yaml from datetime import datetime, timedelta from django.utils import timezone import pytz -- cgit From 0ffc49f91dd9e21a6b9917b7841999bf853c3c9f Mon Sep 17 00:00:00 2001 From: mahesh Date: Fri, 18 Aug 2017 02:13:10 +0530 Subject: Adds test cases for yaml - Fixes selenium test cases, test_models, test_views - Fixes create demo question paper --- yaksh/test_models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'yaksh/test_models.py') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index d5ac394..a940c0f 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1,7 +1,7 @@ import unittest from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ - StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload + StdIOBasedTestCase, FileUpload, McqTestCase, AssignmentUpload import json import ruamel.yaml as yaml from datetime import datetime, timedelta @@ -160,7 +160,9 @@ class QuestionTestCases(unittest.TestCase): "language": "Python", "type": "Code", "testcase": self.test_case_upload_data, "files": [[file1, 0]], - "summary": "Yaml Demo"}] + "summary": "Yaml Demo", + "tags": ['yaml_demo'] + }] self.yaml_questions_data = yaml.safe_dump_all(questions_data) def tearDown(self): -- cgit