def test_get_redirects_when_logged_in(self, pyramid_config, pyramid_request): pyramid_config.testing_securitypolicy("acct:[email protected]") controller = views.SignupController(pyramid_request) with pytest.raises(httpexceptions.HTTPRedirection): controller.get()
def test_post_does_not_create_user_when_validation_fails( self, invalid_form, pyramid_request, user_signup_service): controller = views.SignupController(pyramid_request) controller.form = invalid_form() controller.post() assert not user_signup_service.signup.called
def test_post_returns_errors_when_validation_fails(self, invalid_form, pyramid_request): controller = views.SignupController(pyramid_request) controller.form = invalid_form() result = controller.post() assert result == {"form": "invalid form"}
def test_post_redirects_on_success(self, form_validating_to, pyramid_request): controller = views.SignupController(pyramid_request) controller.form = form_validating_to({ "username": "******", "email": "*****@*****.**", "password": "******", }) result = controller.post() assert isinstance(result, httpexceptions.HTTPRedirection)
def test_post_creates_user_from_form_data(self, form_validating_to, pyramid_request, user_signup_service): controller = views.SignupController(pyramid_request) controller.form = form_validating_to({ "username": "******", "email": "*****@*****.**", "password": "******", "random_other_field": "something else", }) controller.post() user_signup_service.signup.assert_called_with(username="******", email="*****@*****.**", password="******")