def test_authenticated_user(self): url = reverse(self.URL_NAME) request = RequestFactory().get(url) request.user = mixer.blend("auth.User", is_superuser=False, is_staff=False) response = views.custom_password_change_done(request) assert response.status_code == 200, "Should be callable"
def test_anonymous_default(self): url = reverse(self.URL_NAME) request = RequestFactory().get(url) request.user = AnonymousUser() response = views.custom_password_change_done(request) assert response.status_code == 302, "Should redirect to login page" assert response.url == reverse("login") + "?next=" + url, \ "Should contain a next parameter for redirect"
def test_authenticated_ldap_user(self, monkeypatch, settings): """LDAP users are not allowed to change there passwords, this must happen in the LDAP directory itself""" # when using the LDAP integration, a custom LDAP backend exists for the user # if they are readable, the account is an LDAP account settings.LDAP_ENABLE = True url = reverse(self.URL_NAME) request = RequestFactory().get(url) request.user = User.objects.create(username="******", is_superuser=False, is_staff=False) request.user.ldap_user = True response = views.custom_password_change_done(request) assert response.status_code == 403
def test_authenticated_ldap_user(self, monkeypatch, settings): """LDAP users are not allowed to change there passwords, this must happen in the directory itself""" # mock the custom LDAP backend monkeypatch.setattr(context_processors, "LDAPBackend", LDAPBackendMock) # when using the LDAP integration, a custom LDAP backend exists for the user # if they are readable, the account is an LDAP account settings.LDAP_ENABLE = True url = reverse(self.URL_NAME) request = RequestFactory().get(url) request.user = mixer.blend("auth.User", is_superuser=False, is_staff=False) response = views.custom_password_change_done(request) assert response.status_code == 403