summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/test_views.py98
-rw-r--r--yaksh/views.py12
2 files changed, 105 insertions, 5 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 45d3314..d65fe8e 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -1574,6 +1574,7 @@ class TestCourses(TestCase):
self.user2_course = Course.objects.create(name="Java Course",
enrollment="Enroll Request", creator=self.user2)
+ self.user2_course.learning_module.add(self.learning_module)
def tearDown(self):
self.client.logout()
@@ -1733,6 +1734,61 @@ class TestCourses(TestCase):
self.assertEqual(response.context['learning_modules'][0],
self.learning_module)
+ def test_duplicate_course(self):
+ """ Test To clone/duplicate course """
+
+ # Student Login
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+
+ response = self.client.get(
+ reverse('yaksh:duplicate_course',
+ kwargs={"course_id": self.user2_course.id}),
+ follow=True
+ )
+ self.assertEqual(response.status_code, 404)
+
+ # Teacher Login
+ self.client.login(
+ username=self.teacher.username,
+ password=self.teacher_plaintext_pass
+ )
+
+ # Denies teacher not added in the course
+ response = self.client.get(
+ reverse('yaksh:duplicate_course',
+ kwargs={"course_id": self.user2_course.id}),
+ follow=True
+ )
+ err_msg = "You do not have permissions"
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed(response, "yaksh/complete.html")
+ self.assertIn(err_msg, response.context['message'])
+
+ # Moderator/Course creator login
+ self.client.login(
+ username=self.user2.username,
+ password=self.user2_plaintext_pass
+ )
+
+ # Allows creator to duplicate the course
+ response = self.client.get(
+ reverse('yaksh:duplicate_course',
+ kwargs={"course_id": self.user2_course.id}),
+ follow=True
+ )
+
+ self.assertEqual(response.status_code, 200)
+ courses = Course.objects.filter(
+ creator=self.user2).order_by("id")
+ self.assertEqual(courses.count(), 2)
+ self.assertEqual(courses.last().creator, self.user2)
+ self.assertEqual(courses.last().name, "Copy Of Java Course")
+ self.assertEqual(courses.last().get_learning_modules()[0].id,
+ self.user2_course.get_learning_modules()[0].id)
+
class TestAddCourse(TestCase):
def setUp(self):
@@ -2298,6 +2354,27 @@ class TestCourseDetail(TestCase):
self.assertEqual(get_response.context['course'], self.user1_course)
self.assertEqual(get_response.context['state'], 'mail')
+ def test_download_users_template(self):
+ """ Test to check download users template """
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+
+ # Denies student to download users upload template
+ response = self.client.get(reverse('yaksh:download_sample_csv'))
+ self.assertEqual(response.status_code, 404)
+
+ # Moderator Login
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ response = self.client.get(reverse('yaksh:download_sample_csv'))
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.get('Content-Disposition'),
+ 'attachment; filename="sample_user_upload"')
+
class TestEnrollRequest(TestCase):
def setUp(self):
@@ -3583,6 +3660,27 @@ class TestShowQuestions(TestCase):
self.assertTemplateUsed(response, 'yaksh/ajax_question_filter.html')
self.assertEqual(response.context['questions'][0], self.question1)
+ def test_download_question_yaml_template(self):
+ """ Test to check download question yaml template """
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+
+ # Denies student to download question yaml template
+ response = self.client.get(reverse('yaksh:download_yaml_template'))
+ self.assertEqual(response.status_code, 404)
+
+ # Moderator Login
+ self.client.login(
+ username=self.user.username,
+ password=self.user_plaintext_pass
+ )
+ response = self.client.get(reverse('yaksh:download_yaml_template'))
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.get('Content-Disposition'),
+ 'attachment; filename="questions_dump.yaml"')
+
class TestShowStatistics(TestCase):
def setUp(self):
diff --git a/yaksh/views.py b/yaksh/views.py
index cfeb666..483b87c 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -2121,8 +2121,9 @@ def download_sample_csv(request):
"sample_user_upload.csv")
with open(csv_file_path, 'rb') as csv_file:
response = HttpResponse(csv_file.read(), content_type='text/csv')
- response['Content-Disposition'] = 'attachment;\
- filename="sample_user_upload"'
+ response['Content-Disposition'] = (
+ 'attachment; filename="sample_user_upload"'
+ )
return response
@@ -2142,6 +2143,7 @@ def duplicate_course(request, course_id):
return complete(request, msg, attempt_num=None, questionpaper_id=None)
return my_redirect('/exam/manage/courses/')
+
@login_required
@email_verified
def download_yaml_template(request):
@@ -2154,9 +2156,9 @@ def download_yaml_template(request):
yaml_file = zipfile.ZipFile(template_path, 'r')
template_yaml = yaml_file.open('questions_dump.yaml', 'r')
response = HttpResponse(template_yaml, content_type='text/yaml')
- response['Content-Disposition'] = 'attachment;\
- filename="questions_dump.yaml"'
-
+ response['Content-Disposition'] = (
+ 'attachment; filename="questions_dump.yaml"'
+ )
return response