Beispiel #1
0
 def POST(self, **kwargs): # pylint: disable=invalid-name
     """POST /user"""
     user = User(kwargs)
     errors = check_captcha(kwargs)
     if not errors: 
         errors = user.save()
     if not errors:
         # email the admin that the user has signed up
         SignUpMailer(user).mail()
         raise cherrypy.HTTPRedirect('/complete')
     return self._render_registration_form(user, errors)
Beispiel #2
0
 def POST(self, **kwargs):  # pylint: disable=invalid-name
     """POST /user"""
     user = User(kwargs)
     errors = check_captcha(kwargs)
     if not errors:
         errors = user.save()
     if not errors:
         # email the admin that the user has signed up
         SignUpMailer(user).mail()
         raise cherrypy.HTTPRedirect('/complete')
     return self._render_registration_form(user, errors)
Beispiel #3
0
def test_save_no_errors(monkeypatch):
    def mock_call_api(self):
        pass

    monkeypatch.setattr(User, '_call_api', mock_call_api)
    user = User()

    assert user.save() is None
Beispiel #4
0
    def _render_registration_form(self, user=User(), errors=None):  # pylint: disable=no-self-use
        """renders the registration form. private."""
        # pylint: disable=no-member
        captcha = CaptchaHelper()

        return render('new_user.html',
                      user=user,
                      errors=errors,
                      captcha=captcha)
Beispiel #5
0
def test_save_requirement_error(monkeypatch):
    def mock_call_api(self):
        raise mock_errors.DuplicateEntry

    monkeypatch.setattr(User, '_call_api', mock_call_api)
    monkeypatch.setattr(freeipa_community_portal.model.user, 'errors',
                        mock_errors)
    user = User()
    assert user.save() == 'test_dup'
Beispiel #6
0
def test_save_validation_error(monkeypatch):
    def mock_call_api(self):
        raise mock_errors.ValidationError

    monkeypatch.setattr(User, '_call_api', mock_call_api)
    monkeypatch.setattr(freeipa_community_portal.model.user, 'errors',
                        mock_errors)
    user = User()
    assert user.save() == 'test_valid'
Beispiel #7
0
def test_user_init_with_args_no_username():
    args = {
        "given_name": "test",
        "family_name": "user",
        "email": "*****@*****.**"
    }
    user = User(args)

    assert user.given_name == args["given_name"]
    assert user.family_name == args["family_name"]
    assert user.username == "tuser"
    assert user.email == args["email"]
Beispiel #8
0
def test_user_init():
    user = User()
    assert user.given_name == ""
    assert user.family_name == ""
    assert user.username == ""
    assert user.email == ""