Show More
@@ -41,7 +41,7 b' def route_path(name, params=None, **kwar' | |||
|
41 | 41 | |
|
42 | 42 | |
|
43 | 43 | @pytest.mark.usefixtures("app") |
|
44 |
class TestDefaults |
|
|
44 | class TestDefaultsView(object): | |
|
45 | 45 | |
|
46 | 46 | def test_index(self, autologin_user): |
|
47 | 47 | response = self.app.get(route_path('admin_defaults_repositories')) |
@@ -608,10 +608,20 b' def add_events_routes(config):' | |||
|
608 | 608 | |
|
609 | 609 | def bootstrap_request(**kwargs): |
|
610 | 610 | import pyramid.testing |
|
611 | request = pyramid.testing.DummyRequest(**kwargs) | |
|
612 | request.application_url = kwargs.pop('application_url', 'http://example.com') | |
|
613 | request.host = kwargs.pop('host', 'example.com:80') | |
|
614 |
|
|
|
611 | ||
|
612 | class TestRequest(pyramid.testing.DummyRequest): | |
|
613 | application_url = kwargs.pop('application_url', 'http://example.com') | |
|
614 | host = kwargs.pop('host', 'example.com:80') | |
|
615 | domain = kwargs.pop('domain', 'example.com') | |
|
616 | ||
|
617 | class TestDummySession(pyramid.testing.DummySession): | |
|
618 | def save(*arg, **kw): | |
|
619 | pass | |
|
620 | ||
|
621 | request = TestRequest(**kwargs) | |
|
622 | request.session = TestDummySession() | |
|
615 | 623 | |
|
616 | 624 | config = pyramid.testing.setUp(request=request) |
|
617 | 625 | add_events_routes(config) |
|
626 | return request | |
|
627 |
@@ -60,7 +60,6 b' from webhelpers.html.tags import auto_di' | |||
|
60 | 60 | submit, text, password, textarea, title, ul, xml_declaration, radio |
|
61 | 61 | from webhelpers.html.tools import auto_link, button_to, highlight, \ |
|
62 | 62 | js_obfuscate, mail_to, strip_links, strip_tags, tag_re |
|
63 | from webhelpers.pylonslib import Flash as _Flash | |
|
64 | 63 | from webhelpers.text import chop_at, collapse, convert_accented_entities, \ |
|
65 | 64 | convert_misc_entities, lchop, plural, rchop, remove_formatting, \ |
|
66 | 65 | replace_whitespace, urlify, truncate, wrap_paragraphs |
@@ -661,19 +660,48 b' class _Message(object):' | |||
|
661 | 660 | return escape(safe_unicode(self.message)) |
|
662 | 661 | |
|
663 | 662 | |
|
664 |
class Flash( |
|
|
663 | class Flash(object): | |
|
664 | # List of allowed categories. If None, allow any category. | |
|
665 | categories = ["warning", "notice", "error", "success"] | |
|
666 | ||
|
667 | # Default category if none is specified. | |
|
668 | default_category = "notice" | |
|
669 | ||
|
670 | def __init__(self, session_key="flash", categories=None, | |
|
671 | default_category=None): | |
|
672 | """ | |
|
673 | Instantiate a ``Flash`` object. | |
|
674 | ||
|
675 | ``session_key`` is the key to save the messages under in the user's | |
|
676 | session. | |
|
665 | 677 |
|
|
666 | def pop_messages(self, request=None): | |
|
667 | """Return all accumulated messages and delete them from the session. | |
|
678 | ``categories`` is an optional list which overrides the default list | |
|
679 | of categories. | |
|
680 | ||
|
681 | ``default_category`` overrides the default category used for messages | |
|
682 | when none is specified. | |
|
683 | """ | |
|
684 | self.session_key = session_key | |
|
685 | if categories is not None: | |
|
686 | self.categories = categories | |
|
687 | if default_category is not None: | |
|
688 | self.default_category = default_category | |
|
689 | if self.categories and self.default_category not in self.categories: | |
|
690 | raise ValueError( | |
|
691 | "unrecognized default category %r" % (self.default_category,)) | |
|
692 | ||
|
693 | def pop_messages(self, session=None, request=None): | |
|
694 | """ | |
|
695 | Return all accumulated messages and delete them from the session. | |
|
668 | 696 | |
|
669 | 697 | The return value is a list of ``Message`` objects. |
|
670 | 698 | """ |
|
671 | 699 | messages = [] |
|
672 | 700 | |
|
673 |
if |
|
|
701 | if not session: | |
|
702 | if not request: | |
|
703 | request = get_current_request() | |
|
674 | 704 | session = request.session |
|
675 | else: | |
|
676 | from pylons import session | |
|
677 | 705 | |
|
678 | 706 | # Pop the 'old' pylons flash messages. They are tuples of the form |
|
679 | 707 | # (category, message) |
@@ -692,9 +720,9 b' class Flash(_Flash):' | |||
|
692 | 720 | session.save() |
|
693 | 721 | return messages |
|
694 | 722 | |
|
695 | def json_alerts(self, request=None): | |
|
723 | def json_alerts(self, session=None, request=None): | |
|
696 | 724 | payloads = [] |
|
697 | messages = flash.pop_messages(request=request) | |
|
725 | messages = flash.pop_messages(session=session, request=request) | |
|
698 | 726 | if messages: |
|
699 | 727 | for message in messages: |
|
700 | 728 | subdata = {} |
@@ -715,6 +743,18 b' class Flash(_Flash):' | |||
|
715 | 743 | }) |
|
716 | 744 | return json.dumps(payloads) |
|
717 | 745 | |
|
746 | def __call__(self, message, category=None, ignore_duplicate=False, | |
|
747 | session=None, request=None): | |
|
748 | ||
|
749 | if not session: | |
|
750 | if not request: | |
|
751 | request = get_current_request() | |
|
752 | session = request.session | |
|
753 | ||
|
754 | session.flash( | |
|
755 | message, queue=category, allow_duplicate=not ignore_duplicate) | |
|
756 | ||
|
757 | ||
|
718 | 758 | flash = Flash() |
|
719 | 759 | |
|
720 | 760 | #============================================================================== |
@@ -120,7 +120,7 b" c.template_context['default_user'] = {" | |||
|
120 | 120 | <script language="javascript" type="text/javascript" src="${h.asset('js/excanvas.min.js')}"></script> |
|
121 | 121 | <![endif]--> |
|
122 | 122 | <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode/routes.js', ver=c.rhodecode_version_hash)}"></script> |
|
123 | <script> var alertMessagePayloads = ${h.flash.json_alerts(request)|n}; </script> | |
|
123 | <script> var alertMessagePayloads = ${h.flash.json_alerts(request=request)|n}; </script> | |
|
124 | 124 | ## avoide escaping the %N |
|
125 | 125 | <script language="javascript" type="text/javascript" src="${h.asset('js/rhodecode-components.js', ver=c.rhodecode_version_hash)}"></script> |
|
126 | 126 | <script>CodeMirror.modeURL = "${h.asset('') + 'js/mode/%N/%N.js?ver='+c.rhodecode_version_hash}";</script> |
@@ -28,27 +28,16 b' from os.path import join as jn' | |||
|
28 | 28 | |
|
29 | 29 | from tempfile import _RandomNameSequence |
|
30 | 30 | |
|
31 |
from p |
|
|
32 | from paste.script.appinstall import SetupCommand | |
|
31 | from pylons import url | |
|
33 | 32 | |
|
34 | import pylons | |
|
35 | import pylons.test | |
|
36 | from pylons import config, url | |
|
37 | from pylons.i18n.translation import _get_translator | |
|
38 | from pylons.util import ContextObj | |
|
39 | ||
|
40 | from routes.util import URLGenerator | |
|
41 | 33 | from nose.plugins.skip import SkipTest |
|
42 | 34 | import pytest |
|
43 | 35 | |
|
44 | from rhodecode import is_windows | |
|
45 | from rhodecode.config.routing import ADMIN_PREFIX | |
|
46 | from rhodecode.model.meta import Session | |
|
47 | 36 | from rhodecode.model.db import User |
|
48 | 37 | from rhodecode.lib import auth |
|
49 | 38 | from rhodecode.lib import helpers as h |
|
50 | 39 | from rhodecode.lib.helpers import flash, link_to |
|
51 |
from rhodecode.lib.utils2 import |
|
|
40 | from rhodecode.lib.utils2 import safe_str | |
|
52 | 41 | |
|
53 | 42 | |
|
54 | 43 | log = logging.getLogger(__name__) |
@@ -117,6 +106,7 b' try:' | |||
|
117 | 106 | import ldap |
|
118 | 107 | ldap_lib_installed = True |
|
119 | 108 | except ImportError: |
|
109 | ldap = None | |
|
120 | 110 | # means that python-ldap is not installed |
|
121 | 111 | pass |
|
122 | 112 | |
@@ -196,18 +186,18 b' def login_user(app, username=TEST_USER_A' | |||
|
196 | 186 | return login_user_session(app, username, password)['rhodecode_user'] |
|
197 | 187 | |
|
198 | 188 | |
|
199 |
def assert_session_flash(response |
|
|
189 | def assert_session_flash(response, msg=None, category=None, no_=None): | |
|
200 | 190 | """ |
|
201 | 191 | Assert on a flash message in the current session. |
|
202 | 192 | |
|
203 | :param msg: Required. The expected message. Will be evaluated if a | |
|
193 | :param response: Response from give calll, it will contain flash | |
|
194 | messages or bound session with them. | |
|
195 | :param msg: The expected message. Will be evaluated if a | |
|
204 | 196 | :class:`LazyString` is passed in. |
|
205 | :param response: Optional. For functional testing, pass in the response | |
|
206 | object. Otherwise don't pass in any value. | |
|
207 | 197 | :param category: Optional. If passed, the message category will be |
|
208 | 198 | checked as well. |
|
209 |
:param no_: Optional. If passed, the message will be checked to NOT |
|
|
210 | flash session | |
|
199 | :param no_: Optional. If passed, the message will be checked to NOT | |
|
200 | be in the flash session | |
|
211 | 201 | """ |
|
212 | 202 | if msg is None and no_ is None: |
|
213 | 203 | raise ValueError("Parameter msg or no_ is required.") |
@@ -215,7 +205,8 b' def assert_session_flash(response=None, ' | |||
|
215 | 205 | if msg and no_: |
|
216 | 206 | raise ValueError("Please specify either msg or no_, but not both") |
|
217 | 207 | |
|
218 | messages = flash.pop_messages() | |
|
208 | session = response.get_session_from_response() | |
|
209 | messages = flash.pop_messages(session=session) | |
|
219 | 210 | msg = _eval_if_lazy(msg) |
|
220 | 211 | |
|
221 | 212 | assert messages, 'unable to find message `%s` in empty flash list' % msg |
@@ -242,14 +233,6 b' def _eval_if_lazy(value):' | |||
|
242 | 233 | return value.eval() if hasattr(value, 'eval') else value |
|
243 | 234 | |
|
244 | 235 | |
|
245 | def assert_session_flash_is_empty(response): | |
|
246 | assert 'flash' in response.session, 'Response session has no flash key' | |
|
247 | ||
|
248 | msg = 'flash messages are present in session:%s' % \ | |
|
249 | response.session['flash'][0] | |
|
250 | pytest.fail(safe_str(msg)) | |
|
251 | ||
|
252 | ||
|
253 | 236 | def no_newline_id_generator(test_name): |
|
254 | 237 | """ |
|
255 | 238 | Generates a test name without spaces or newlines characters. Used for |
@@ -1669,8 +1669,8 b' def request_stub():' | |||
|
1669 | 1669 | """ |
|
1670 | 1670 | Stub request object. |
|
1671 | 1671 | """ |
|
1672 | request = pyramid.testing.DummyRequest() | |
|
1673 |
request |
|
|
1672 | from rhodecode.lib.base import bootstrap_request | |
|
1673 | request = bootstrap_request(scheme='https') | |
|
1674 | 1674 | return request |
|
1675 | 1675 | |
|
1676 | 1676 |
General Comments 0
You need to be logged in to leave comments.
Login now