def test_get_redirects_when_logged_in(self, pyramid_config, pyramid_request): pyramid_config.testing_securitypolicy("acct:[email protected]") pyramid_request.user = mock.Mock(username="******") controller = views.SignupController(pyramid_request) with pytest.raises(httpexceptions.HTTPRedirection): controller.get()
def test_get_renders_form_when_not_logged_in(self, pyramid_request): controller = views.SignupController(pyramid_request) controller.form.render = mock.Mock() assert controller.get() == { "form": controller.form.render.return_value }
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() # invalid_form renders as "invalid form" 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 controller(self, form_validating_to, pyramid_request): controller = views.SignupController(pyramid_request) controller.form = form_validating_to({ "username": "******", "email": "*****@*****.**", "password": "******", "comms_opt_in": True, }) return controller
def test_post_displays_heading_and_message_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 result["heading"] == "Account registration successful" assert "message" not in result
def test_post_displays_heading_and_message_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 result["heading"] == "Account registration successful" assert result["message"] == ( "Please check your email and open the link to activate your account." )
def test_post_displays_heading_and_message_on_conflict_error( self, form_validating_to, pyramid_request, user_signup_service): user_signup_service.signup.side_effect = ConflictError( "The account [email protected] is already registered.") controller = views.SignupController(pyramid_request) controller.form = form_validating_to({ "username": "******", "email": "*****@*****.**", "password": "******" }) result = controller.post() assert result["heading"] == "Account already registered" assert result["message"] == ( "The account [email protected] is already registered.")
def test_post_creates_user_from_form_data(self, form_validating_to, pyramid_request, user_signup_service, datetime): 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="******", privacy_accepted=datetime.datetime.utcnow.return_value)