summaryrefslogtreecommitdiff
path: root/yaksh/test_models.py
diff options
context:
space:
mode:
authorPalaparthy Adityachandra2021-03-15 19:02:27 +0530
committerGitHub2021-03-15 19:02:27 +0530
commit6fda19daaa06482b8eb52eeb62f9b0a15d0a3da6 (patch)
treea589f0dfae0cd118432f7e45899439cfc2a98a13 /yaksh/test_models.py
parent85a2b6b61c74e2ed42d6c78f6b502a3c72dcf9ca (diff)
parent1793f445ec0cbc67df4b4cd3151859e01ed4b2a0 (diff)
downloadonline_test-6fda19daaa06482b8eb52eeb62f9b0a15d0a3da6.tar.gz
online_test-6fda19daaa06482b8eb52eeb62f9b0a15d0a3da6.tar.bz2
online_test-6fda19daaa06482b8eb52eeb62f9b0a15d0a3da6.zip
Merge pull request #822 from CruiseDevice/fix_file_upload_assignments
Fix file upload assignments
Diffstat (limited to 'yaksh/test_models.py')
-rw-r--r--yaksh/test_models.py71
1 files changed, 53 insertions, 18 deletions
diff --git a/yaksh/test_models.py b/yaksh/test_models.py
index 9e0997d..2ee6e82 100644
--- a/yaksh/test_models.py
+++ b/yaksh/test_models.py
@@ -107,6 +107,7 @@ def setUpModule():
MicroManager.objects.create(manager=user, course=course, quiz=quiz,
student=course_user)
+
def tearDownModule():
User.objects.all().delete()
Question.objects.all().delete()
@@ -2202,17 +2203,37 @@ class TestCaseTestCases(unittest.TestCase):
class AssignmentUploadTestCases(unittest.TestCase):
+
def setUp(self):
- self.user1 = User.objects.get(username="creator")
- self.user1.first_name = "demo"
- self.user1.last_name = "user"
- self.user1.save()
- self.user2 = User.objects.get(username="demo_user3")
- self.user2.first_name = "demo"
- self.user2.last_name = "user3"
- self.user2.save()
- self.quiz = Quiz.objects.get(description="demo quiz 1")
- self.course = Course.objects.get(name="Python Course")
+ self.user1 = User.objects.create_user(
+ username='creator1',
+ password='demo',
+ email='demo@test1.com'
+ )
+ self.user2 = User.objects.create_user(
+ username='creator2',
+ password='demo',
+ email='demo@test2.com'
+ )
+ self.quiz = Quiz.objects.create(
+ start_date_time=datetime(
+ 2015, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc
+ ),
+ end_date_time=datetime(
+ 2199, 10, 9, 10, 8, 15, 0, tzinfo=pytz.utc
+ ),
+ duration=30, active=True,
+ attempts_allowed=1, time_between_attempts=0,
+ description='demo quiz 1', pass_criteria=0,
+ instructions="Demo Instructions"
+ )
+
+ self.course = Course.objects.create(
+ name="Python Course",
+ enrollment="Enroll Request",
+ creator=self.user1
+ )
+
self.questionpaper = QuestionPaper.objects.create(
quiz=self.quiz, total_marks=0.0, shuffle_questions=True
)
@@ -2224,17 +2245,22 @@ class AssignmentUploadTestCases(unittest.TestCase):
self.questionpaper.fixed_question_order = "{0}".format(
self.question.id)
self.questionpaper.fixed_questions.add(self.question)
+
+ attempt = 1
+ ip = '127.0.0.1'
+ self.answerpaper1 = self.questionpaper.make_answerpaper(
+ self.user1, ip, attempt, self.course.id
+ )
+
file_path1 = os.path.join(tempfile.gettempdir(), "upload1.txt")
file_path2 = os.path.join(tempfile.gettempdir(), "upload2.txt")
self.assignment1 = AssignmentUpload.objects.create(
- user=self.user1, assignmentQuestion=self.question,
- assignmentFile=file_path1, question_paper=self.questionpaper,
- course=self.course
+ assignmentQuestion=self.question,
+ assignmentFile=file_path1, answer_paper=self.answerpaper1,
)
self.assignment2 = AssignmentUpload.objects.create(
- user=self.user2, assignmentQuestion=self.question,
- assignmentFile=file_path2, question_paper=self.questionpaper,
- course=self.course
+ assignmentQuestion=self.question,
+ assignmentFile=file_path2, answer_paper=self.answerpaper1,
)
def test_get_assignments_for_user_files(self):
@@ -2243,7 +2269,7 @@ class AssignmentUploadTestCases(unittest.TestCase):
self.user1.id, self.course.id
)
self.assertIn("upload1.txt", assignment_files[0].assignmentFile.name)
- self.assertEqual(assignment_files[0].user, self.user1)
+ self.assertEqual(assignment_files[0].answer_paper.user, self.user1)
actual_file_name = self.user1.get_full_name().replace(" ", "_")
file_name = file_name.replace(" ", "_")
self.assertEqual(file_name, actual_file_name)
@@ -2254,7 +2280,8 @@ class AssignmentUploadTestCases(unittest.TestCase):
)
files = [os.path.basename(file.assignmentFile.name)
for file in assignment_files]
- question_papers = [file.question_paper for file in assignment_files]
+ question_papers = [
+ file.answer_paper.question_paper for file in assignment_files]
self.assertIn("upload1.txt", files)
self.assertIn("upload2.txt", files)
self.assertEqual(question_papers[0].quiz, self.questionpaper.quiz)
@@ -2262,6 +2289,14 @@ class AssignmentUploadTestCases(unittest.TestCase):
file_name = file_name.replace(" ", "_")
self.assertIn(actual_file_name, file_name)
+ def tearDown(self):
+ self.questionpaper.delete()
+ self.question.delete()
+ self.course.delete()
+ self.quiz.delete()
+ self.user2.delete()
+ self.user1.delete()
+
class CourseStatusTestCases(unittest.TestCase):
def setUp(self):