diff options
author | Prabhu Ramachandran | 2016-10-04 15:44:05 +0530 |
---|---|---|
committer | GitHub | 2016-10-04 15:44:05 +0530 |
commit | 91dd42214ba5ad88c5158b50a7746caa3841a883 (patch) | |
tree | 188f8aa284783e844eccffe350839d6a18f4da8b /yaksh/test_models.py | |
parent | 6b08e56fe3cf70ffbcbd1ed432dde25babe48148 (diff) | |
parent | 59fa975a9fd0f6728cf62b1069abecac95a77b68 (diff) | |
download | online_test-91dd42214ba5ad88c5158b50a7746caa3841a883.tar.gz online_test-91dd42214ba5ad88c5158b50a7746caa3841a883.tar.bz2 online_test-91dd42214ba5ad88c5158b50a7746caa3841a883.zip |
Merge pull request #143 from adityacp/python2to3-migrate
Migration Python 2 to 3
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r-- | yaksh/test_models.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 50ead1d..019a339 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -58,6 +58,9 @@ def setUpModule(): language='Python', prerequisite=quiz, course=course) + with open('/tmp/test.txt', 'wb') as f: + f.write('2'.encode('ascii')) + def tearDownModule(): User.objects.all().delete() Question.objects.all().delete() @@ -66,7 +69,8 @@ def tearDownModule(): que_id_list = ["25", "22", "24", "27"] for que_id in que_id_list: dir_path = os.path.join(os.getcwd(), "yaksh", "data","question_{0}".format(que_id)) - shutil.rmtree(dir_path) + if os.path.exists(dir_path): + shutil.rmtree(dir_path) ############################################################################### class ProfileTestCases(unittest.TestCase): @@ -115,7 +119,7 @@ class QuestionTestCases(unittest.TestCase): self.question2.save() # create a temp directory and add files for loading questions test - file_path = os.path.join(os.getcwd(), "yaksh", "test.txt") + file_path = "/tmp/test.txt" self.load_tmp_path = tempfile.mkdtemp() shutil.copy(file_path, self.load_tmp_path) file1 = os.path.join(self.load_tmp_path, "test.txt") @@ -164,7 +168,8 @@ class QuestionTestCases(unittest.TestCase): tag_list = [] for tag in self.question1.tags.all(): tag_list.append(tag.name) - self.assertEqual(tag_list, ['python', 'function']) + for tag in tag_list: + self.assertIn(tag, ['python', 'function']) def test_dump_questions(self): """ Test dump questions into json """ @@ -714,7 +719,7 @@ class AnswerPaperTestCases(unittest.TestCase): def test_get_question_answer(self): """ Test get_question_answer() method of Answer Paper""" answered = self.answerpaper.get_question_answers() - first_answer = answered.values()[0][0] + first_answer = list(answered.values())[0][0] self.assertEqual(first_answer.answer, 'Demo answer') self.assertTrue(first_answer.correct) self.assertEqual(len(answered), 2) @@ -895,4 +900,7 @@ class TestCaseTestCases(unittest.TestCase): result = self.question1.consolidate_answer_data( user_answer="demo_answer" ) - self.assertEqual(result, self.answer_data_json) + actual_data = json.loads(result) + exp_data = json.loads(self.answer_data_json) + self.assertEqual(actual_data['user_answer'], exp_data['user_answer']) + self.assertEqual(actual_data['test_case_data'], exp_data['test_case_data']) |