def test_password_verify_password_not_matching():
    form = forms.UserAccount(data={
        'password': '******',
        'password_confirmed': 'drowssap'
    })

    assert form.is_valid() is False
    assert "Passwords don't match" in form.errors['password_confirmed']
def test_create_user_password_invalid_not_matching():
    form = forms.UserAccount(
        data={
            'email': '*****@*****.**',
            'password': '******',
            'password_confirmed': 'drowssap',
        })

    assert form.is_valid() is False
    assert "Passwords don't match" in form.errors['password_confirmed']
def test_create_user_password_invalid_not_matching(mock_create_user):
    mock_create_user.return_value = create_response(400)
    form = forms.UserAccount(
        data={
            'email': '*****@*****.**',
            'password': '******',
            'password_confirmed': 'drowssap',
        })

    assert form.is_valid() is False
    assert "Passwords don't match" in form.errors['password_confirmed']
def test_create_user_password_existing_user(mock_create_user):
    mock_create_user.return_value = create_response(400)

    form = forms.UserAccount(
        data={
            'email': '*****@*****.**',
            'password': '******',
            'password_confirmed': '12P',
            'terms_agreed': True,
        })
    assert form.is_valid() is True
    assert not form.cleaned_data['user_details']
def test_create_user_password_invalid(mock_create_user):
    data = {'password': '******'}
    mock_create_user.return_value = create_response(400, data)

    form = forms.UserAccount(data={
        'email': '*****@*****.**',
        'password': '******',
        'password_confirmed': '12P',
    })

    assert form.is_valid() is False
    assert "Invalid Password" in form.errors['password']
def test_create_user_error(mock_create_user):

    mock_create_user.return_value = create_response(401)
    form = forms.UserAccount(
        data={
            'email': '*****@*****.**',
            'password': '******',
            'password_confirmed': '12P',
            'terms_agreed': True,
        })

    with pytest.raises(HTTPError):
        form.is_valid()
def test_create_user(mock_create_user):
    data = {'email': '*****@*****.**', 'verification_code': '12345'}
    mock_create_user.return_value = create_response(201, data)

    form = forms.UserAccount(
        data={
            'email': '*****@*****.**',
            'password': '******',
            'password_confirmed': 'ABCdefg12345',
            'terms_agreed': True,
        })

    assert form.is_valid() is True
    assert form.cleaned_data["user_details"] == data