Dependency inject ApplicationServiceApi when creating ApplicationServicesHandler.

This commit is contained in:
Kegan Dougal 2015-02-05 17:04:59 +00:00
parent a3c6010718
commit 11e6b3d18b
3 changed files with 9 additions and 11 deletions

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from synapse.appservice.api import ApplicationServiceApi
from .register import RegistrationHandler from .register import RegistrationHandler
from .room import ( from .room import (
RoomCreationHandler, RoomMemberHandler, RoomListHandler RoomCreationHandler, RoomMemberHandler, RoomListHandler
@ -53,5 +54,7 @@ class Handlers(object):
self.directory_handler = DirectoryHandler(hs) self.directory_handler = DirectoryHandler(hs)
self.typing_notification_handler = TypingNotificationHandler(hs) self.typing_notification_handler = TypingNotificationHandler(hs)
self.admin_handler = AdminHandler(hs) self.admin_handler = AdminHandler(hs)
self.appservice_handler = ApplicationServicesHandler(hs) self.appservice_handler = ApplicationServicesHandler(
hs, ApplicationServiceApi(hs)
)
self.sync_handler = SyncHandler(hs) self.sync_handler = SyncHandler(hs)

View File

@ -18,7 +18,6 @@ from twisted.internet import defer
from synapse.api.constants import EventTypes from synapse.api.constants import EventTypes
from synapse.api.errors import Codes, StoreError, SynapseError from synapse.api.errors import Codes, StoreError, SynapseError
from synapse.appservice import ApplicationService from synapse.appservice import ApplicationService
from synapse.appservice.api import ApplicationServiceApi
from synapse.types import UserID from synapse.types import UserID
import synapse.util.stringutils as stringutils import synapse.util.stringutils as stringutils
@ -32,10 +31,10 @@ logger = logging.getLogger(__name__)
# easier. # easier.
class ApplicationServicesHandler(object): class ApplicationServicesHandler(object):
def __init__(self, hs): def __init__(self, hs, appservice_api):
self.store = hs.get_datastore() self.store = hs.get_datastore()
self.hs = hs self.hs = hs
self.appservice_api = ApplicationServiceApi(hs) self.appservice_api = appservice_api
@defer.inlineCallbacks @defer.inlineCallbacks
def register(self, app_service): def register(self, app_service):

View File

@ -29,13 +29,9 @@ class AppServiceHandlerTestCase(unittest.TestCase):
self.mock_as_api = Mock() self.mock_as_api = Mock()
hs = Mock() hs = Mock()
hs.get_datastore = Mock(return_value=self.mock_store) hs.get_datastore = Mock(return_value=self.mock_store)
self.handler = ApplicationServicesHandler(hs) # thing being tested self.handler = ApplicationServicesHandler(
hs, self.mock_as_api
# FIXME Would be nice to DI this rather than monkey patch:( )
if not hasattr(self.handler, "appservice_api"):
# someone probably updated the handler but not the tests. Fail fast.
raise Exception("Test expected handler.appservice_api to exist.")
self.handler.appservice_api = self.mock_as_api
@defer.inlineCallbacks @defer.inlineCallbacks
def test_notify_interested_services(self): def test_notify_interested_services(self):