summaryrefslogtreecommitdiff
path: root/yaksh/test_models.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r--yaksh/test_models.py18
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'])