Begin to add unit tests for appservice glue and regex testing.

This commit is contained in:
Kegan Dougal 2015-02-04 12:24:20 +00:00
parent 17753f0c20
commit 525a218b2b
5 changed files with 158 additions and 4 deletions

View file

@ -14,8 +14,11 @@
# limitations under the License.
from synapse.api.constants import EventTypes
import logging
import re
logger = logging.getLogger(__name__)
class ApplicationService(object):
"""Defines an application service. This definition is mostly what is
@ -56,15 +59,22 @@ class ApplicationService(object):
return namespaces
def _matches_regex(self, test_string, namespace_key):
if not isinstance(test_string, basestring):
logger.warning(
"Expected a string to test regex against, but got %s",
test_string
)
return False
for regex in self.namespaces[namespace_key]:
if re.match(regex, test_string):
return True
return False
def _matches_user(self, event):
if (hasattr(event, "user_id") and
if (hasattr(event, "sender") and
self._matches_regex(
event.user_id, ApplicationService.NS_USERS)):
event.sender, ApplicationService.NS_USERS)):
return True
# also check m.room.member state key
if (hasattr(event, "type") and event.type == EventTypes.Member