Skip to content

Commit

Permalink
Test view permission
Browse files Browse the repository at this point in the history
  • Loading branch information
isuruf committed Oct 19, 2019
1 parent 84d29e5 commit 2e0c09c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/base_test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,19 @@ def get_edit_course_url(cls, course_identifier=None):
course_identifier or cls.get_default_course_identifier())
return cls.get_course_view_url("relate-edit_course", course_identifier)

@classmethod
def get_view_all_forms_url(cls, course_identifier=None):
course_identifier = (
course_identifier or cls.get_default_course_identifier())
return cls.get_course_view_url("relate-view_all_forms", course_identifier)

@classmethod
def get_view_form_url(cls, form_id, course_identifier=None):
course_identifier = (
course_identifier or cls.get_default_course_identifier())
return cls.get_course_view_url("relate-view_form", course_identifier,
form_id)

@classmethod
def post_edit_course(cls, data, course=None):
course = course or cls.get_default_course()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
from course.validation import ValidationError
from relate.utils import dict_to_struct

from tests.base_test_mixins import SingleCourseTestMixin, MockAddMessageMixing


class CreateFormTest(TestCase):

Expand Down Expand Up @@ -121,3 +123,17 @@ def test_create_form(self):
# Check that template_out has id appended
self.assertEqual(form.template_out, "out_{}.yml".format(form.id))
self.assertIn(form.id, form.get_jinja_text()[0])


class ViewAllFormsTest(SingleCourseTestMixin, MockAddMessageMixing, TestCase):

def test_student_no_form_access(self):
with self.temporarily_switch_to_user(self.student_participation.user):
print(self.get_course_page_url())
resp = self.c.get(self.get_view_all_forms_url())
self.assertEqual(resp.status_code, 403)

def test_instructor_forms_access(self):
with self.temporarily_switch_to_user(self.instructor_participation.user):
resp = self.c.get(self.get_view_all_forms_url())
self.assertEqual(resp.status_code, 200)

0 comments on commit 2e0c09c

Please sign in to comment.