import re class SubstringMatcher: """Class which allows to check for SQL calls by the list of substrings.""" def __init__(self, containing): """Initialise object. Args: containing (list): A list of substrings to check. """ self.containing = [el.lower() for el in containing] def __eq__(self, sql): """Equal magic method. Check if all the substrings from the passed list are present in SQL. Args: sql (str): SQL statement from a call. """ sql = re.sub('\\s+', ' ', sql.lower()).strip() return all(el in sql for el in self.containing) def __repr__(self): """Represent string magic method to play nice with py.test messages.""" return 'SQL containing: {}'.format(', '.join(self.containing))