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,38 +221,33 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 | |
|
221 | if msg not in message_text: | |
|
222 | fail_msg = u'msg `%s` not found in session ' \ | |
|
223 | u'flash: got `%s` (type:%s) instead' % ( | |
|
224 | msg, message_text, type(message_text)) | |
|
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: | |
|
231 | if msg not in message_text: | |
|
232 | fail_msg = u'msg `%s` not found in session ' \ | |
|
233 | u'flash: got `%s` (type:%s) instead' % ( | |
|
234 | msg, message_text, type(message_text)) | |
|
225 | 235 | |
|
226 | pytest.fail(safe_str(fail_msg)) | |
|
227 | if category: | |
|
228 | assert category == message.category | |
|
236 | pytest.fail(safe_str(fail_msg)) | |
|
237 | if category: | |
|
238 | assert category == message.category | |
|
229 | 239 | |
|
230 | 240 | |
|
231 | 241 | def _eval_if_lazy(value): |
|
232 | 242 | return value.eval() if hasattr(value, 'eval') else value |
|
233 | 243 | |
|
234 | 244 | |
|
235 |
def assert_ |
|
|
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 | msg = 'flash messages are present in session:%s' % \ | |
|
249 | response.session['flash'][0] | |
|
250 | pytest.fail(safe_str(msg)) | |
|
248 | msg = 'flash messages are present in session:%s' % \ | |
|
249 | response.session['flash'][0] | |
|
250 | pytest.fail(safe_str(msg)) | |
|
251 | 251 | |
|
252 | 252 | |
|
253 | 253 | def no_newline_id_generator(test_name): |
General Comments 0
You need to be logged in to leave comments.
Login now