def test_get_password_valid(fake_error): with mock.patch.object(vhost_mail, 'validate_password') as m, \ mock.patch.object(vhost_mail, 'crypt_password') as c: assert _get_password(fake_request(password='******'), 'ckuehl') == c.return_value m.assert_called_once_with('ckuehl', 'password', strength_check=True) c.assert_called_once_with('password')
def test_get_password_fails_strength_check(fake_error): def fake_validate(addr_name, password, strength_check=False): raise ValueError('bad password yo') with pytest.raises(fake_error) as ex, \ mock.patch.object(vhost_mail, 'validate_password', side_effect=fake_validate) as m: assert _get_password(fake_request(password='******'), 'ckuehl') is None assert ex.value.args[0] == 'bad password yo' m.assert_called_once_with('ckuehl', 'password', strength_check=True)
def test_get_password_empty(): """If password is present and an empty string, remove it.""" assert _get_password(fake_request(password=''), 'ckuehl') is REMOVE_PASSWORD
def test_get_password_not_present(): """If "password" is not present, just do nothing.""" assert _get_password(fake_request(), 'ckuehl') is None
def test_get_password_no_name(): assert _get_password(fake_request(password='******'), None) is REMOVE_PASSWORD