def test_create_user_duplicate(mock_create_user):

    mock_create_user.return_value = create_response(400)
    result = helpers.create_user(
        email='*****@*****.**',
        password='******',
    )
    assert mock_create_user.call_count == 1
    assert result is None
Ejemplo n.º 2
0
 def clean(self):
     cleaned_data = super().clean()
     try:
         cleaned_data['user_details'] = helpers.create_user(
             email=cleaned_data['email'],
             password=cleaned_data['password'],
         )
     except HTTPError as error:
         if error.response.status_code == 400:
             self.add_error('password', self.MESSAGE_PASSWORD_INVALID)
         else:
             raise
     return None
def test_create_user(mock_create_user):

    data = {
        'email': '*****@*****.**',
        'verification_code': '12345',
        'cookies': RequestsCookieJar(),
    }
    mock_create_user.return_value = create_response(200, data)
    result = helpers.create_user(
        email='*****@*****.**',
        password='******',
    )
    assert mock_create_user.call_count == 1
    assert mock_create_user.call_args == mock.call('*****@*****.**', '1234')
    assert result == data
Ejemplo n.º 4
0
 def render_next_step(self, form, **kwargs):
     response = super().render_next_step(form, **kwargs)
     if form.prefix == USER_ACCOUNT:
         user_details = helpers.create_user(
             email=form.cleaned_data['email'],
             password=form.cleaned_data['password'],
         )
         # Check if we have a user, else the user is already registered
         if user_details:
             helpers.send_verification_code_email(
                 email=form.cleaned_data['email'],
                 verification_code=user_details['verification_code'],
                 form_url=self.request.path,
             )
         else:
             helpers.notify_already_registered(
                 email=form.cleaned_data['email'],
                 form_url=self.request.path
             )
     elif form.prefix == VERIFICATION:
         response.cookies.update(form.cleaned_data['cookies'])
     return response