summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authorPrabhu Ramachandran2016-11-01 10:58:27 +0530
committerGitHub2016-11-01 10:58:27 +0530
commit710d620834a424cc8aa2a4db099437b160f86b92 (patch)
tree7e2a2a242aa77e6b88c3a9702f235f359bd71dcb /yaksh
parentf563640af941a50642dc5eb6e63b1d63a1685046 (diff)
parentd60b49896d46853b5d36f4affd6a68f5ecfd8771 (diff)
downloadonline_test-710d620834a424cc8aa2a4db099437b160f86b92.tar.gz
online_test-710d620834a424cc8aa2a4db099437b160f86b92.tar.bz2
online_test-710d620834a424cc8aa2a4db099437b160f86b92.zip
Merge pull request #150 from ankitjavalkar/view-test-update1
Add views test for add_course view
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/test_views.py154
-rw-r--r--yaksh/views.py4
2 files changed, 150 insertions, 8 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 1d1c3f3..2b7ad9b 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -139,6 +139,7 @@ class TestProfile(TestCase):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'yaksh/editprofile.html')
+
class TestAddQuiz(TestCase):
def setUp(self):
self.client = Client()
@@ -209,7 +210,7 @@ class TestAddQuiz(TestCase):
self.pre_req_quiz.delete()
self.course.delete()
- def test_view_profile_denies_anonymous(self):
+ def test_add_quiz_denies_anonymous(self):
"""
If not logged in redirect to login page
"""
@@ -220,7 +221,7 @@ class TestAddQuiz(TestCase):
redirect_destination = '/exam/login/?next=/exam/manage/addquiz/{0}/'.format(self.course.id)
self.assertRedirects(response, redirect_destination)
- def test_view_profile_denies_non_moderator(self):
+ def test_add_quiz_denies_non_moderator(self):
"""
If not moderator in redirect to login page
"""
@@ -342,6 +343,7 @@ class TestAddQuiz(TestCase):
self.assertEqual(response.status_code, 302)
self.assertRedirects(response, '/exam/manage/courses/')
+
class TestAddTeacher(TestCase):
def setUp(self):
self.client = Client()
@@ -500,6 +502,7 @@ class TestAddTeacher(TestCase):
self.assertIn(teacher_object, response.context['teachers_added'])
self.assertIn(teacher_object, self.course.teachers.all())
+
class TestRemoveTeacher(TestCase):
def setUp(self):
self.client = Client()
@@ -758,6 +761,139 @@ class TestCourses(TestCase):
self.assertNotIn(self.user2_course, response.context['courses'])
+class TestAddCourse(TestCase):
+ def setUp(self):
+ self.client = Client()
+
+ self.mod_group = Group.objects.create(name='moderator')
+ tzone = pytz.timezone('UTC')
+
+ # Create Moderator with profile
+ self.user_plaintext_pass = 'demo'
+ self.user = User.objects.create_user(
+ username='demo_user',
+ password=self.user_plaintext_pass,
+ first_name='first_name',
+ last_name='last_name',
+ email='demo@test.com'
+ )
+
+ Profile.objects.create(
+ user=self.user,
+ roll_number=10,
+ institute='IIT',
+ department='Chemical',
+ position='Moderator',
+ timezone='UTC'
+ )
+
+ # Create Student
+ 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'
+ )
+
+ # Add to moderator group
+ self.mod_group.user_set.add(self.user)
+
+ self.course = Course.objects.create(name="Python Course",
+ enrollment="Enroll Request", creator=self.user)
+
+ self.pre_req_quiz = Quiz.objects.create(
+ start_date_time=datetime(2014, 2, 1, 5, 8, 15, 0, tzone),
+ end_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzone),
+ duration=30, active=True,
+ attempts_allowed=-1, time_between_attempts=0,
+ description='pre requisite quiz', pass_criteria=40,
+ language='Python', prerequisite=None,
+ course=self.course
+ )
+
+ self.quiz = Quiz.objects.create(
+ start_date_time=datetime(2014, 10, 9, 10, 8, 15, 0, tzone),
+ end_date_time=datetime(2015, 10, 9, 10, 8, 15, 0, tzone),
+ duration=30, active=True,
+ attempts_allowed=-1, time_between_attempts=0,
+ description='demo quiz', pass_criteria=40,
+ language='Python', prerequisite=self.pre_req_quiz,
+ course=self.course
+ )
+
+ def tearDown(self):
+ self.client.logout()
+ self.user.delete()
+ self.student.delete()
+ self.quiz.delete()
+ self.pre_req_quiz.delete()
+ self.course.delete()
+
+ def test_add_course_denies_anonymous(self):
+ """
+ If not logged in redirect to login page
+ """
+ response = self.client.get(reverse('yaksh:add_course'),
+ follow=True
+ )
+ redirect_destination = ('/exam/login/?next=/'
+ 'exam/manage/add_course/')
+ self.assertRedirects(response, redirect_destination)
+
+ def test_add_course_denies_non_moderator(self):
+ """
+ If not moderator in redirect to login page
+ """
+ self.client.login(
+ username=self.student.username,
+ password=self.student_plaintext_pass
+ )
+ course_id = self.course.id
+ response = self.client.get(reverse('yaksh:add_course'),
+ follow=True
+ )
+ self.assertEqual(response.status_code, 404)
+
+ def test_add_course_get(self):
+ """
+ GET request to add course should display add course form
+ """
+ self.client.login(
+ username=self.user.username,
+ password=self.user_plaintext_pass
+ )
+ response = self.client.get(reverse('yaksh:add_course'))
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed(response, 'yaksh/add_course.html')
+ self.assertIsNotNone(response.context['form'])
+
+ def test_add_course_post_new_course(self):
+ """
+ POST request to add course should add new courses if no course exists
+ """
+ self.client.login(
+ username=self.user.username,
+ password=self.user_plaintext_pass
+ )
+
+ response = self.client.post(reverse('yaksh:add_course'),
+ data={'name': 'new_demo_course_1',
+ 'active': True,
+ 'enrollment': 'open'
+ }
+ )
+ course_list = Course.objects.all().order_by('-id')
+ new_course = course_list[0]
+ self.assertEqual(new_course.name, 'new_demo_course_1')
+ self.assertEqual(new_course.enrollment, 'open')
+ self.assertEqual(new_course.active, True)
+
+ self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, '/exam/manage/')
+
+
class TestCourseDetail(TestCase):
def setUp(self):
self.client = Client()
@@ -829,11 +965,13 @@ class TestCourseDetail(TestCase):
"""
If not logged in redirect to login page
"""
- response = self.client.get(reverse('yaksh:add_course'),
+ response = self.client.get(reverse('yaksh:course_detail',
+ kwargs={'course_id': self.user1_course.id}
+ ),
follow=True
)
- redirect_destination = ('/exam/login/?next=/exam'
- '/manage/add_course/')
+ redirect_destination = ('/exam/login/?next=/exam/'
+ 'manage/course_detail/1/')
self.assertRedirects(response, redirect_destination)
def test_course_detail_denies_non_moderator(self):
@@ -845,7 +983,9 @@ class TestCourseDetail(TestCase):
password=self.student_plaintext_pass
)
- response = self.client.get(reverse('yaksh:add_course'),
+ response = self.client.get(reverse('yaksh:course_detail',
+ kwargs={'course_id': self.user1_course.id}
+ ),
follow=True
)
self.assertEqual(response.status_code, 404)
@@ -882,6 +1022,7 @@ class TestCourseDetail(TestCase):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'yaksh/course_detail.html')
+
class TestEnrollRequest(TestCase):
def setUp(self):
self.client = Client()
@@ -988,6 +1129,7 @@ class TestEnrollRequest(TestCase):
)
self.assertRedirects(response, '/exam/manage/')
+
class TestViewAnswerPaper(TestCase):
def setUp(self):
self.client = Client()
diff --git a/yaksh/views.py b/yaksh/views.py
index 4706222..f91342d 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -299,7 +299,7 @@ def show_all_questionpapers(request, questionpaper_id=None):
@login_required
def prof_manage(request):
"""Take credentials of the user with professor/moderator
-rights/permissions and log in."""
+ rights/permissions and log in."""
user = request.user
ci = RequestContext(request)
if user.is_authenticated() and is_moderator(user):
@@ -584,7 +584,7 @@ def add_course(request):
new_course = form.save(commit=False)
new_course.creator = user
new_course.save()
- return my_render_to_response('manage.html', {'course': new_course})
+ return my_redirect('/exam/manage/')
else:
return my_render_to_response('yaksh/add_course.html',
{'form': form},