'Asserts that the logger was called with the given
log_level and with a regex of the given string.'

@contextmanager
def assert_logged(self, log_string, log_level='error'):

    with patch(('openedx.core.djangoapps.safe_sessions.middleware.log.' + log_level)) as mock_log:
        (yield)
        self.assertTrue(mock_log.called)
        self.assertRegexpMatches(mock_log.call_args_list[0][0][0], log_string)
