def test_teacher_required__with_teacher(rf, teacher):
    req = rf.get("/test")
    req.user = teacher.user

    fct = teacher_required(lambda req, teacher: teacher)
    resp = fct(req)
    assert resp == teacher
def test_teacher_required__with_anonymous_user(rf):
    req = rf.get("/test")
    req.user = AnonymousUser()

    fct = teacher_required(lambda req, teacher: teacher)
    resp = fct(req)
    assert resp.status_code == 403
    assert resp.template_name == "403.html"
def test_teacher_required__with_student(rf, student):
    req = rf.get("/test")
    req.user = student.student

    fct = teacher_required(lambda req, teacher: teacher)
    resp = fct(req)
    assert resp.status_code == 403
    assert resp.template_name == "403.html"
def test_teacher_required__with_regular_user(rf, user):
    req = rf.get("/test")
    req.user = user

    fct = teacher_required(lambda req, teacher: teacher)
    resp = fct(req)
    assert resp.status_code == 403
    assert resp.template_name == "403.html"
Exemple #5
0
 def setUp(self):
     self.req_factory = RequestFactory()
     self.teacher_required = teacher_required(lambda req: None)