コード例 #1
0
ファイル: test_controllers.py プロジェクト: ppker/yata_app
    def test_update_user_settings_fail_with_not_valid(self, mock):
        form = self.produce_form(data={"language": "ruby", "theme": "solarized"})
        handler = mock.Mock(spec=ChangeSetHandler)
        view = UserSettings(form=form, settings_update_handler=handler)

        view.post()
        flashed = get_flashed_messages()

        assert not len(flashed)
        handler.apply_changeset.assert_not_called()
        assert form.errors
コード例 #2
0
ファイル: test_controllers.py プロジェクト: ppker/yata_app
    def test_update_user_settings_fails_with_persistence_error(self, mock):
        form = self.produce_form(data={"language": "python", "theme": "molokai"})
        handler = mock.Mock(spec=ChangeSetHandler)
        handler.apply_changeset.side_effect = PersistenceError("Nope")
        view = UserSettings(form=form, settings_update_handler=handler)

        result = view.post()
        flashed = get_flashed_messages(with_categories=True)

        assert len(flashed) == 1
        assert flashed[0] == ("danger", "Error while updating user settings")
        assert result.status_code == 302
        assert result.headers["Location"] == url_for("user.settings")
コード例 #3
0
ファイル: test_controllers.py プロジェクト: ppker/yata_app
    def test_update_user_settings_fail_with_stopvalidation_error(self, mock):
        form = self.produce_form(data={"language": "python", "theme": "molokai"})
        handler = mock.Mock(spec=ChangeSetHandler)
        handler.apply_changeset.side_effect = StopValidation(
            [("theme", "Solarized is better")]
        )
        view = UserSettings(form=form, settings_update_handler=handler)

        view.post()
        flashed = get_flashed_messages()

        assert not (len(flashed))
        assert form.errors["theme"] == ["Solarized is better"]
コード例 #4
0
ファイル: test_controllers.py プロジェクト: ppker/yata_app
    def test_update_user_settings_successfully(self, user, mock):
        form = self.produce_form(data={"language": "python", "theme": "solarized"})
        handler = mock.Mock(spec=ChangeSetHandler)
        view = UserSettings(form=form, settings_update_handler=handler)

        result = view.post()
        flashed = get_flashed_messages(with_categories=True)

        assert len(flashed) == 1
        assert flashed[0] == ("success", "Settings updated.")
        assert result.status_code == 302
        assert result.headers["Location"] == url_for("user.settings")
        handler.apply_changeset.assert_called_once_with(
            user, SettingsUpdate(language="python", theme="solarized")
        )
コード例 #5
0
ファイル: test_controllers.py プロジェクト: ppker/yata_app
    def test_renders_get_okay(self, mock):
        form = self.produce_form({})
        handler = mock.Mock(spec=ChangeSetHandler)
        handler = UserSettings(form=form, settings_update_handler=handler)

        handler.get()