From 40dc5e38c23d5c99475a6e9bbb811c5bb9b5d016 Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 25 Aug 2016 16:29:29 +0530 Subject: changed testcases to test questions dump --- yaksh/test_models.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'yaksh/test_models.py') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 8bd2dda..efd7b55 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -1,12 +1,16 @@ import unittest from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\ - StdoutBasedTestCase + StdoutBasedTestCase, FileUpload import json from datetime import datetime, timedelta from django.utils import timezone import pytz from django.contrib.auth.models import Group +from django.core.files import File +import zipfile +import os +import shutil def setUpModule(): @@ -105,7 +109,8 @@ class QuestionTestCases(unittest.TestCase): user=self.user2 ) self.question2.save() - + file_path = os.path.join(os.getcwd(), "yaksh", "test.txt") + shutil.copy(file_path, "/tmp/") self.question1.tags.add('python', 'function') self.assertion_testcase = StandardTestCase(question=self.question1, test_case='assert myfunc(12, 13) == 15' @@ -122,6 +127,7 @@ class QuestionTestCases(unittest.TestCase): "language": "Python", "type": "Code", "test_case_type": "standardtestcase", "testcase": self.test_case_upload_data, + "files": ['/tmp/test.txt'], "summary": "Json Demo"}] self.json_questions_data = json.dumps(questions_data) @@ -143,24 +149,33 @@ class QuestionTestCases(unittest.TestCase): """ Test dump questions into json """ question = Question() question_id = [self.question2.id] - questions = json.loads(question.dump_into_json(question_id, self.user2)) + questions_zip = question.dump_into_json(question_id, self.user2) + zip_file = zipfile.ZipFile(questions_zip, "r") + zip_file.extractall("/tmp/") test_case = self.question2.get_test_cases() - for q in questions: - self.assertEqual(self.question2.summary, q['summary']) - self.assertEqual(self.question2.language, q['language']) - self.assertEqual(self.question2.type, q['type']) - self.assertEqual(self.question2.description, q['description']) - self.assertEqual(self.question2.points, q['points']) - self.assertTrue(self.question2.active) - self.assertEqual(self.question2.snippet, q['snippet']) - self.assertEqual(self.question2.test_case_type, q['test_case_type']) - self.assertEqual([case.get_field_value() for case in test_case], q['testcase']) + with open("/tmp/questions_dump.json", "r") as f: + questions = json.loads(f.read()) + for q in questions: + self.assertEqual(self.question2.summary, q['summary']) + self.assertEqual(self.question2.language, q['language']) + self.assertEqual(self.question2.type, q['type']) + self.assertEqual(self.question2.description, q['description']) + self.assertEqual(self.question2.points, q['points']) + self.assertTrue(self.question2.active) + self.assertEqual(self.question2.snippet, q['snippet']) + self.assertEqual(self.question2.test_case_type, q['test_case_type']) + self.assertEqual([case.get_field_value() for case in test_case], q['testcase']) + for file in zip_file.namelist(): + os.remove(os.path.join("/tmp/", file)) def test_load_questions_from_json(self): """ Test load questions into database from json """ + f_path = os.path.join(os.getcwd(), "yaksh", "data", + "question_25", "tmp", "test.txt") question = Question() result = question.load_from_json(self.json_questions_data, self.user1) question_data = Question.objects.get(pk=25) + file = FileUpload.objects.get(question=25) test_case = question_data.get_test_cases() self.assertEqual(question_data.summary, 'Json Demo') self.assertEqual(question_data.language, 'Python') @@ -170,7 +185,10 @@ class QuestionTestCases(unittest.TestCase): self.assertTrue(question_data.active) self.assertEqual(question_data.snippet, 'def fact()') self.assertEqual(question_data.test_case_type, 'standardtestcase') + self.assertEqual(os.path.basename(file.file.path), "test.txt") self.assertEqual([case.get_field_value() for case in test_case], self.test_case_upload_data) + rm_dir = os.path.dirname(os.path.dirname(f_path)) + shutil.rmtree(rm_dir) ############################################################################### -- cgit From 0f42918020b5eb436e73e564ca8b519e84aecfa2 Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 26 Aug 2016 11:33:10 +0530 Subject: changed function calls in tests --- yaksh/test_models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/test_models.py') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index efd7b55..1716c73 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -149,7 +149,7 @@ class QuestionTestCases(unittest.TestCase): """ Test dump questions into json """ question = Question() question_id = [self.question2.id] - questions_zip = question.dump_into_json(question_id, self.user2) + questions_zip = question.dump_questions(question_id, self.user2) zip_file = zipfile.ZipFile(questions_zip, "r") zip_file.extractall("/tmp/") test_case = self.question2.get_test_cases() @@ -173,7 +173,7 @@ class QuestionTestCases(unittest.TestCase): f_path = os.path.join(os.getcwd(), "yaksh", "data", "question_25", "tmp", "test.txt") question = Question() - result = question.load_from_json(self.json_questions_data, self.user1) + result = question.load_questions(self.json_questions_data, self.user1) question_data = Question.objects.get(pk=25) file = FileUpload.objects.get(question=25) test_case = question_data.get_test_cases() -- cgit From 83fe192987c239287bf816a31f4da31910eb7087 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 30 Aug 2016 22:44:46 +0530 Subject: changed load and dump test cases --- yaksh/test_models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'yaksh/test_models.py') diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 5c34e8e..7b5dd5b 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -69,7 +69,7 @@ def tearDownModule(): shutil.rmtree(dir_path1) shutil.rmtree(dir_path2) shutil.rmtree(dir_path3) - #shutil.rmtree(dir_path4) + shutil.rmtree(dir_path4) ############################################################################### @@ -148,7 +148,7 @@ class QuestionTestCases(unittest.TestCase): "language": "Python", "type": "Code", "test_case_type": "standardtestcase", "testcase": self.test_case_upload_data, - "files": [file1], + "files": [[file1, 0]], "summary": "Json Demo"}] self.json_questions_data = json.dumps(questions_data) @@ -191,7 +191,7 @@ class QuestionTestCases(unittest.TestCase): self.assertTrue(self.question2.active) self.assertEqual(self.question2.snippet, q['snippet']) self.assertEqual(self.question2.test_case_type, q['test_case_type']) - self.assertEqual(os.path.basename(que_file.file.path), q['files'][0]) + self.assertEqual(os.path.basename(que_file.file.path), q['files'][0][0]) self.assertEqual([case.get_field_value() for case in test_case], q['testcase']) for file in zip_file.namelist(): os.remove(os.path.join(tmp_path, file)) -- cgit