changeset 5409:5bfeada59776

tests: add regex version of checkSessionFlash This is needed to match more complex messages.
author Søren Løvborg <sorenl@unity3d.com>
date Wed, 19 Aug 2015 17:19:02 +0200
parents f6fcfc84f30c
children 97a20b808e5b
files kallithea/tests/__init__.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/__init__.py	Tue Aug 18 11:47:18 2015 +0200
+++ b/kallithea/tests/__init__.py	Wed Aug 19 17:19:02 2015 +0200
@@ -33,6 +33,7 @@
 
 """
 import os
+import re
 import time
 import logging
 import datetime
@@ -238,15 +239,18 @@
     def authentication_token(self):
         return self.app.get(url('authentication_token')).body
 
-    def checkSessionFlash(self, response, msg, skip=0):
+    def checkSessionFlash(self, response, msg=None, skip=0, _matcher=lambda msg, m: msg in m):
         if 'flash' not in response.session:
             self.fail(safe_str(u'msg `%s` not found - session has no flash:\n%s' % (msg, response)))
         try:
             level, m = response.session['flash'][-1 - skip]
-            if msg in m:
+            if _matcher(msg, m):
                 return
         except IndexError:
             pass
         self.fail(safe_str(u'msg `%s` not found in session flash (skipping %s): %s' %
                            (msg, skip,
                             ', '.join('`%s`' % m for level, m in response.session['flash']))))
+
+    def checkSessionFlashRegex(self, response, regex, skip=0):
+        self.checkSessionFlash(response, regex, skip=skip, _matcher=re.search)