def test_validate_username_with_user(self): user_service = pretend.stub(find_userid=pretend.call_recorder(lambda userid: 1)) form = forms.CreateRoleForm(user_service=user_service) field = pretend.stub(data="my_username") form.validate_username(field) assert user_service.find_userid.calls == [pretend.call("my_username")]
def test_validate_role_name_fails(self, value, expected): user_service = pretend.stub(find_userid=pretend.call_recorder(lambda userid: 1)) form = forms.CreateRoleForm( MultiDict({"role_name": value, "username": "******"}), user_service=user_service, ) assert not form.validate() assert form.role_name.errors == [expected]
def test_validate_username_with_no_user(self): user_service = pretend.stub( find_userid=pretend.call_recorder(lambda userid: None), ) form = forms.CreateRoleForm(user_service=user_service) field = pretend.stub(data="my_username") with pytest.raises(wtforms.validators.ValidationError): form.validate_username(field) assert user_service.find_userid.calls == [pretend.call("my_username")]
def test_creation(self): user_service = pretend.stub() form = forms.CreateRoleForm(user_service=user_service) assert form.user_service is user_service