summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/test_views.py240
-rw-r--r--yaksh/views.py1
2 files changed, 240 insertions, 1 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index af0193e..5b873b5 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -2636,6 +2636,12 @@ class TestCourseDetail(TestCase):
name="Python Course II",
enrollment="Enroll Request", creator=self.user1
)
+ self.user1_deactive_course = Course.objects.create(
+ name="Python Course II",
+ enrollment="Enroll Request",
+ creator=self.user1,
+ active=False
+ )
self.learning_module = LearningModule.objects.create(
name="test module", description="test description module",
html_data="test html description module", creator=self.user1,
@@ -2986,6 +2992,64 @@ class TestCourseDetail(TestCase):
self.assertEqual(response.status_code, 302)
self.assertSequenceEqual([self.student1], enrolled_student)
+ def test_student_course_enroll_post_without_enroll_in_request(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:enroll_reject_user', kwargs={
+ 'course_id': self.user1_course.id
+ })
+ data = {
+ 'check': self.student1.id,
+ 'enroll': ''
+ }
+ response = self.client.post(url, data)
+ self.assertEqual(response.status_code, 302)
+
+ def test_student_course_enroll_post_without_enroll_ids(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:enroll_reject_user', kwargs={
+ 'course_id': self.user1_course.id
+ })
+ data = {
+ 'enroll': 'enroll'
+ }
+ response = self.client.post(url, data)
+ self.assertEqual(response.status_code, 302)
+
+ def test_student_course_reject_post_without_reject_in_request(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:enroll_reject_user', kwargs={
+ 'course_id': self.user1_course.id
+ })
+ data = {
+ 'check': self.student1.id,
+ 'reject': ''
+ }
+ response = self.client.post(url, data)
+ self.assertEqual(response.status_code, 302)
+
+ def test_student_course_reject_post_without_reject_ids(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:enroll_reject_user', kwargs={
+ 'course_id': self.user1_course.id
+ })
+ data = {
+ 'reject': 'reject'
+ }
+ response = self.client.post(url, data)
+ self.assertEqual(response.status_code, 302)
+
def test_student_course_reject_get(self):
"""
Reject student in a course using get request
@@ -3023,6 +3087,64 @@ class TestCourseDetail(TestCase):
self.assertEqual(response.status_code, 302)
self.assertSequenceEqual([self.student1], enrolled_student)
+ def test_enroll_user_not_moderator(self):
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ url = reverse('yaksh:enroll_user', kwargs={
+ 'course_id': self.user1_course.id,
+ 'user_id': self.user1.id
+ })
+ response = self.client.post(url)
+ self.assertEqual(response.status_code, 404)
+
+ def test_enroll_user_in_deactivated_course(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:enroll_user', kwargs={
+ 'course_id': self.user1_deactive_course.id,
+ 'user_id': self.student.id
+ })
+ response = self.client.post(url)
+ self.assertEqual(response.status_code, 302)
+
+ def test_reject_user_not_moderator(self):
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ url = reverse('yaksh:reject_user', kwargs={
+ 'course_id': self.user1_course.id,
+ 'user_id': self.user1.id
+ })
+ response = self.client.post(url)
+ self.assertEqual(response.status_code, 404)
+
+ def test_enroll_reject_user_not_moderator(self):
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ url = reverse('yaksh:enroll_reject_user', kwargs={
+ 'course_id': self.user1_course.id,
+ })
+ response = self.client.post(url)
+ self.assertEqual(response.status_code, 404)
+
+ def test_enroll_reject_user_in_deactivated_course(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:enroll_reject_user', kwargs={
+ 'course_id': self.user1_deactive_course.id,
+ })
+ response = self.client.post(url)
+ self.assertEqual(response.status_code, 302)
+
def test_toggle_course_status_get(self):
self.client.login(
username=self.user1.username,
@@ -3216,6 +3338,124 @@ class TestCourseDetail(TestCase):
self.assertIn("Per Module Progress", data)
+class TestCourseStudents(TestCase):
+ def setUp(self):
+ self.client = Client()
+ self.mod_group = Group.objects.create(name='moderator')
+
+ # Create Moderator with profile
+ self.user1_plaintext_pass = 'demo1'
+ self.user1 = User.objects.create_user(
+ username='demo_user1',
+ password=self.user1_plaintext_pass,
+ first_name='user1_first_name',
+ last_name='user1_last_name',
+ email='demo@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.user1,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='Moderator',
+ timezone='UTC',
+ is_moderator=True
+ )
+
+ self.student_plaintext_pass = 'demo_student'
+ self.student = User.objects.create_user(
+ username='demo_student',
+ password=self.student_plaintext_pass,
+ first_name='student_first_name',
+ last_name='student_last_name',
+ email='demo_student@test.com'
+ )
+ self.student1_plaintext_pass = 'demo_student'
+ self.student1 = User.objects.create_user(
+ username='demo_student1',
+ password=self.student1_plaintext_pass,
+ first_name='student1_first_name',
+ last_name='student1_last_name',
+ email='demo_student1@test.com'
+ )
+
+ self.student2_plaintext_pass = 'demo_student'
+ self.student2 = User.objects.create_user(
+ username='demo_student2',
+ password=self.student2_plaintext_pass,
+ first_name='student2_first_name',
+ last_name='student2_last_name',
+ email='demo_student2@test.com'
+ )
+
+ # Add to moderator group
+ self.mod_group.user_set.add(self.user1)
+
+ self.user1_course = Course.objects.create(
+ name="Python Course",
+ enrollment="Enroll Request", creator=self.user1
+ )
+
+ # self.course.students.add(self.student)
+ self.user1_course.enroll(False, self.student)
+ self.user1_course.reject(False, self.student1)
+ self.user1_course.request(self.student2)
+
+ def test_enrolled_users(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:course_students', kwargs={
+ 'course_id': self.user1_course.id
+ })
+ response = self.client.get(url)
+ enrolled_users = self.user1_course.get_enrolled()
+ self.assertTrue(enrolled_users.exists())
+
+ def test_requested_users(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:course_students', kwargs={
+ 'course_id': self.user1_course.id
+ })
+ response = self.client.get(url)
+ requested_users = self.user1_course.get_requests()
+ self.assertTrue(requested_users.exists())
+
+ def test_rejected_users(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:course_students', kwargs={
+ 'course_id': self.user1_course.id
+ })
+ response = self.client.get(url)
+ rejected_users = self.user1_course.get_rejected()
+ self.assertTrue(rejected_users.exists())
+
+ def test_course_students_context(self):
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ url = reverse('yaksh:course_students', kwargs={
+ 'course_id': self.user1_course.id
+ })
+ response = self.client.get(url)
+ self.assertTrue('enrolled_users' in response.context)
+ self.assertTrue('requested_users' in response.context)
+ self.assertTrue('rejected_users' in response.context)
+
+
+ def tearDown(self):
+ pass
+
+
class TestEnrollRequest(TestCase):
def setUp(self):
self.client = Client()
diff --git a/yaksh/views.py b/yaksh/views.py
index c716be4..91ddbae 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1141,7 +1141,6 @@ def enroll_user(request, course_id, user_id=None, was_rejected=False):
@email_verified
def reject_user(request, course_id, user_id=None, was_enrolled=False):
user = request.user
- print(was_enrolled)
if not is_moderator(user):
raise Http404('You are not allowed to view this page')
course = get_object_or_404(Course, id=course_id)