mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-09-07 10:13:19 +00:00
Fix tests and missing returns on deferreds.
This commit is contained in:
parent
d33ae65efc
commit
b59aa74556
@ -95,7 +95,7 @@ class ApplicationService(object):
|
|||||||
# rooms: [ {regex: "[A-z]+.*", exclusive: true}, ...],
|
# rooms: [ {regex: "[A-z]+.*", exclusive: true}, ...],
|
||||||
# }
|
# }
|
||||||
if not namespaces:
|
if not namespaces:
|
||||||
return None
|
namespaces = {}
|
||||||
|
|
||||||
for ns in ApplicationService.NS_LIST:
|
for ns in ApplicationService.NS_LIST:
|
||||||
if ns not in namespaces:
|
if ns not in namespaces:
|
||||||
|
@ -37,7 +37,7 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def get_app_services(self):
|
def get_app_services(self):
|
||||||
defer.succeed(self.services_cache)
|
return defer.succeed(self.services_cache)
|
||||||
|
|
||||||
def get_app_service_by_user_id(self, user_id):
|
def get_app_service_by_user_id(self, user_id):
|
||||||
"""Retrieve an application service from their user ID.
|
"""Retrieve an application service from their user ID.
|
||||||
@ -54,9 +54,8 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||||||
"""
|
"""
|
||||||
for service in self.services_cache:
|
for service in self.services_cache:
|
||||||
if service.sender == user_id:
|
if service.sender == user_id:
|
||||||
defer.succeed(service)
|
return defer.succeed(service)
|
||||||
return
|
return defer.succeed(None)
|
||||||
defer.succeed(None)
|
|
||||||
|
|
||||||
def get_app_service_by_token(self, token):
|
def get_app_service_by_token(self, token):
|
||||||
"""Get the application service with the given appservice token.
|
"""Get the application service with the given appservice token.
|
||||||
@ -69,7 +68,7 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||||||
for service in self.services_cache:
|
for service in self.services_cache:
|
||||||
if service.token == token:
|
if service.token == token:
|
||||||
return defer.succeed(service)
|
return defer.succeed(service)
|
||||||
defer.succeed(None)
|
return defer.succeed(None)
|
||||||
|
|
||||||
def get_app_service_rooms(self, service):
|
def get_app_service_rooms(self, service):
|
||||||
"""Get a list of RoomsForUser for this application service.
|
"""Get a list of RoomsForUser for this application service.
|
||||||
@ -237,11 +236,16 @@ class ApplicationServiceStore(SQLBaseStore):
|
|||||||
|
|
||||||
def _populate_appservice_cache(self, config_files):
|
def _populate_appservice_cache(self, config_files):
|
||||||
"""Populates a cache of Application Services from the config files."""
|
"""Populates a cache of Application Services from the config files."""
|
||||||
|
if not isinstance(config_files, list):
|
||||||
|
logger.warning(
|
||||||
|
"Expected %s to be a list of AS config files.", config_files
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
for config_file in config_files:
|
for config_file in config_files:
|
||||||
try:
|
try:
|
||||||
with open(config_file, 'r') as f:
|
with open(config_file, 'r') as f:
|
||||||
as_info = yaml.load(f)
|
appservice = self._load_appservice(yaml.load(f))
|
||||||
appservice = self._load_appservice(as_info)
|
|
||||||
logger.info("Loaded application service: %s", appservice)
|
logger.info("Loaded application service: %s", appservice)
|
||||||
self.services_cache.append(appservice)
|
self.services_cache.append(appservice)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -22,6 +22,8 @@ from synapse.storage.appservice import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
import yaml
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
from tests.utils import SQLiteMemoryDbPool, MockClock
|
from tests.utils import SQLiteMemoryDbPool, MockClock
|
||||||
|
|
||||||
@ -30,25 +32,40 @@ class ApplicationServiceStoreTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
self.as_yaml_files = []
|
||||||
db_pool = SQLiteMemoryDbPool()
|
db_pool = SQLiteMemoryDbPool()
|
||||||
yield db_pool.prepare()
|
yield db_pool.prepare()
|
||||||
hs = HomeServer(
|
hs = HomeServer(
|
||||||
"test", db_pool=db_pool, clock=MockClock(), config=Mock()
|
"test", db_pool=db_pool, clock=MockClock(),
|
||||||
|
config=Mock(
|
||||||
|
app_service_config_files=self.as_yaml_files
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.as_token = "token1"
|
self.as_token = "token1"
|
||||||
db_pool.runQuery(
|
self.as_url = "some_url"
|
||||||
"INSERT INTO application_services(token) VALUES(?)",
|
self._add_appservice(self.as_token, self.as_url, "some_hs_token", "bob")
|
||||||
(self.as_token,)
|
self._add_appservice("token2", "some_url", "some_hs_token", "bob")
|
||||||
)
|
self._add_appservice("token3", "some_url", "some_hs_token", "bob")
|
||||||
db_pool.runQuery(
|
|
||||||
"INSERT INTO application_services(token) VALUES(?)", ("token2",)
|
|
||||||
)
|
|
||||||
db_pool.runQuery(
|
|
||||||
"INSERT INTO application_services(token) VALUES(?)", ("token3",)
|
|
||||||
)
|
|
||||||
# must be done after inserts
|
# must be done after inserts
|
||||||
self.store = ApplicationServiceStore(hs)
|
self.store = ApplicationServiceStore(hs)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
# TODO: suboptimal that we need to create files for tests!
|
||||||
|
for f in self.as_yaml_files:
|
||||||
|
try:
|
||||||
|
os.remove(f)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _add_appservice(self, as_token, url, hs_token, sender):
|
||||||
|
as_yaml = dict(url=url, as_token=as_token, hs_token=hs_token,
|
||||||
|
sender=sender, namespaces={})
|
||||||
|
# use the token as the filename
|
||||||
|
with open(as_token, 'w') as outfile:
|
||||||
|
outfile.write(yaml.dump(as_yaml))
|
||||||
|
self.as_yaml_files.append(as_token)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def test_retrieve_unknown_service_token(self):
|
def test_retrieve_unknown_service_token(self):
|
||||||
service = yield self.store.get_app_service_by_token("invalid_token")
|
service = yield self.store.get_app_service_by_token("invalid_token")
|
||||||
@ -60,7 +77,7 @@ class ApplicationServiceStoreTestCase(unittest.TestCase):
|
|||||||
self.as_token
|
self.as_token
|
||||||
)
|
)
|
||||||
self.assertEquals(stored_service.token, self.as_token)
|
self.assertEquals(stored_service.token, self.as_token)
|
||||||
self.assertEquals(stored_service.url, None)
|
self.assertEquals(stored_service.url, self.as_url)
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
stored_service.namespaces[ApplicationService.NS_ALIASES],
|
stored_service.namespaces[ApplicationService.NS_ALIASES],
|
||||||
[]
|
[]
|
||||||
|
Loading…
Reference in New Issue
Block a user