##// END OF EJS Templates
tests: re-use assert_session_flash to also test for negative cases....
marcink -
r1925:2c37cda7 default
parent child Browse files
Show More
@@ -196,7 +196,7 b' def login_user(app, username=TEST_USER_A'
196 196 return login_user_session(app, username, password)['rhodecode_user']
197 197
198 198
199 def assert_session_flash(response=None, msg=None, category=None):
199 def assert_session_flash(response=None, msg=None, category=None, no_=None):
200 200 """
201 201 Assert on a flash message in the current session.
202 202
@@ -206,9 +206,14 b' def assert_session_flash(response=None, '
206 206 object. Otherwise don't pass in any value.
207 207 :param category: Optional. If passed, the message category will be
208 208 checked as well.
209 :param no_: Optional. If passed, the message will be checked to NOT be in the
210 flash session
209 211 """
210 if msg is None:
211 raise ValueError("Parameter msg is required.")
212 if msg is None and no_ is None:
213 raise ValueError("Parameter msg or no_ is required.")
214
215 if msg and no_:
216 raise ValueError("Please specify either msg or no_, but not both")
212 217
213 218 messages = flash.pop_messages()
214 219 msg = _eval_if_lazy(msg)
@@ -216,8 +221,13 b' def assert_session_flash(response=None, '
216 221 assert messages, 'unable to find message `%s` in empty flash list' % msg
217 222 message = messages[0]
218 223
219 message_text = _eval_if_lazy(message.message)
224 message_text = _eval_if_lazy(message.message) or ''
220 225
226 if no_:
227 if no_ in message_text:
228 msg = u'msg `%s` found in session flash.' % (no_,)
229 pytest.fail(safe_str(msg))
230 else:
221 231 if msg not in message_text:
222 232 fail_msg = u'msg `%s` not found in session ' \
223 233 u'flash: got `%s` (type:%s) instead' % (
@@ -232,19 +242,9 b' def _eval_if_lazy(value):'
232 242 return value.eval() if hasattr(value, 'eval') else value
233 243
234 244
235 def assert_not_in_session_flash(response, msg, category=None):
245 def assert_session_flash_is_empty(response):
236 246 assert 'flash' in response.session, 'Response session has no flash key'
237 message_category, message_text = response.session['flash'][0]
238 if msg in message_text:
239 msg = u'msg `%s` found in session flash: got `%s` instead' % (
240 msg, message_text)
241 pytest.fail(safe_str(msg))
242 if category:
243 assert category == message_category
244 247
245
246 def assert_session_flash_is_empty(response):
247 if 'flash' in response.session:
248 248 msg = 'flash messages are present in session:%s' % \
249 249 response.session['flash'][0]
250 250 pytest.fail(safe_str(msg))
General Comments 0
You need to be logged in to leave comments. Login now