diff options
author | adityacp | 2016-08-25 16:29:29 +0530 |
---|---|---|
committer | adityacp | 2016-08-25 16:29:29 +0530 |
commit | 40dc5e38c23d5c99475a6e9bbb811c5bb9b5d016 (patch) | |
tree | ff8ce2c4c4ebae943820411dbea773236fa948bf | |
parent | 074ca3fe68b790279c6ed8e0dda580b5ade8586e (diff) | |
download | online_test-40dc5e38c23d5c99475a6e9bbb811c5bb9b5d016.tar.gz online_test-40dc5e38c23d5c99475a6e9bbb811c5bb9b5d016.tar.bz2 online_test-40dc5e38c23d5c99475a6e9bbb811c5bb9b5d016.zip |
changed testcases to test questions dump
-rw-r--r-- | yaksh/test_models.py | 44 | ||||
-rw-r--r-- | yaksh/test_views.py | 6 |
2 files changed, 35 insertions, 15 deletions
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) ############################################################################### diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 6e59e26..3c08e48 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -640,8 +640,10 @@ class TestCourses(TestCase): def setUp(self): self.client = Client() - self.mod_group = Group.objects.create(name='moderator') - + self.mod_group = Group.objects.create(name='moderator') + User.objects.get_or_create(username='demo_user', + password='demo', + email='demo@test.com') # Create Moderator with profile self.user1_plaintext_pass = 'demo1' self.user1 = User.objects.create_user( |