summaryrefslogtreecommitdiff
path: root/yaksh/test_views.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/test_views.py')
-rw-r--r--yaksh/test_views.py72
1 files changed, 44 insertions, 28 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 58b7506..925c3d1 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -23,7 +23,6 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.files import File
from django.contrib.messages import get_messages
from django.contrib.contenttypes.models import ContentType
-from celery.contrib.testing.worker import start_worker
from django.test import SimpleTestCase
@@ -41,6 +40,8 @@ from online_test.celery_settings import app
from notifications_plugin.models import Notification
+app.conf.update(CELERY_ALWAYS_EAGER=True)
+
class TestUserRegistration(TestCase):
def setUp(self):
@@ -938,36 +939,38 @@ class TestDownloadAssignment(TestCase):
)
self.question_paper.fixed_questions.add(self.question)
+ attempt = 1
+ ip = '127.0.0.1'
+ self.answerpaper1 = self.question_paper.make_answerpaper(
+ self.student1, ip, attempt, self.course.id
+ )
+
+ self.answerpaper2 = self.question_paper.make_answerpaper(
+ self.student2, ip, attempt, self.course.id
+ )
+
# create assignment file
assignment_file1 = SimpleUploadedFile("file1.txt", b"Test")
assignment_file2 = SimpleUploadedFile("file2.txt", b"Test")
+
self.assignment1 = AssignmentUpload.objects.create(
- user=self.student1, assignmentQuestion=self.question,
- course=self.course,
- assignmentFile=assignment_file1, question_paper=self.question_paper
+ assignmentQuestion=self.question,
+ assignmentFile=assignment_file1, answer_paper=self.answerpaper1
)
self.assignment2 = AssignmentUpload.objects.create(
- user=self.student2, assignmentQuestion=self.question,
- course=self.course,
- assignmentFile=assignment_file2, question_paper=self.question_paper
+ assignmentQuestion=self.question,
+ assignmentFile=assignment_file2, answer_paper=self.answerpaper1
+ )
+
+ self.assignment1 = AssignmentUpload.objects.create(
+ assignmentQuestion=self.question,
+ assignmentFile=assignment_file1, answer_paper=self.answerpaper2
+ )
+ self.assignment2 = AssignmentUpload.objects.create(
+ assignmentQuestion=self.question,
+ assignmentFile=assignment_file2, answer_paper=self.answerpaper2
)
- def tearDown(self):
- self.client.logout()
- self.user.delete()
- self.student1.delete()
- self.student2.delete()
- self.assignment1.delete()
- self.assignment2.delete()
- self.quiz.delete()
- self.course.delete()
- self.learning_module.delete()
- self.learning_unit.delete()
- self.mod_group.delete()
- dir_name = self.course.name.replace(" ", "_")
- file_path = os.sep.join((settings.MEDIA_ROOT, dir_name))
- if os.path.exists(file_path):
- shutil.rmtree(file_path)
def test_download_assignment_denies_student(self):
"""
@@ -1037,10 +1040,27 @@ class TestDownloadAssignment(TestCase):
zip_file = string_io(response.content)
zipped_file = zipfile.ZipFile(zip_file, 'r')
self.assertIsNone(zipped_file.testzip())
- self.assertIn('file2.txt', zipped_file.namelist()[0])
+ self.assertIn('file1.txt', zipped_file.namelist()[0])
zip_file.close()
zipped_file.close()
+ def tearDown(self):
+ self.client.logout()
+ self.user.delete()
+ self.student1.delete()
+ self.student2.delete()
+ self.assignment1.delete()
+ self.assignment2.delete()
+ self.quiz.delete()
+ self.learning_module.delete()
+ self.learning_unit.delete()
+ self.mod_group.delete()
+ dir_name = f'Course_{self.course.id}'
+ file_path = os.sep.join((settings.MEDIA_ROOT, dir_name))
+ if os.path.exists(file_path):
+ shutil.rmtree(file_path)
+ self.course.delete()
+
class TestAddQuiz(TestCase):
def setUp(self):
@@ -4418,9 +4438,6 @@ class TestGrader(SimpleTestCase):
end_time=timezone.now()+timezone.timedelta(minutes=20),
)
- self.celery_worker = start_worker(app)
- self.celery_worker.__enter__()
-
def tearDown(self):
User.objects.all().delete()
Course.objects.all().delete()
@@ -4429,7 +4446,6 @@ class TestGrader(SimpleTestCase):
QuestionPaper.objects.all().delete()
AnswerPaper.objects.all().delete()
self.mod_group.delete()
- self.celery_worker.__exit__(None, None, None)
def test_regrade_denies_anonymous(self):
# Given