コード例 #1
0
    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()
コード例 #2
0
ファイル: account_signup_test.py プロジェクト: wwnorton/h
    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
        }
コード例 #3
0
ファイル: account_signup_test.py プロジェクト: wwnorton/h
    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
コード例 #4
0
ファイル: account_signup_test.py プロジェクト: wwnorton/h
    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"}
コード例 #5
0
    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)
コード例 #6
0
ファイル: account_signup_test.py プロジェクト: wwnorton/h
    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
コード例 #7
0
    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
コード例 #8
0
    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."
        )
コード例 #9
0
    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.")
コード例 #10
0
ファイル: account_signup_test.py プロジェクト: cuongdcdev/h
    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)