def test_make_websocket_url_without_base_url(self): wcommon = WebServiceCommon(reactor=the_reactor, title='', ws_endpoint_string='tcp:1234') request = FakeRequest() self.assertEqual('ws://fake-request-hostname:1234/testpath', wcommon.make_websocket_url(request, '/testpath'))
def test_make_websocket_url_with_base_url_with_path(self): wcommon = WebServiceCommon(reactor=the_reactor, title='', ws_endpoint_string='tcp:1234', ws_base_url='wss://wshost:5678/ws/') request = FakeRequest() self.assertEqual('wss://wshost:5678/ws/testpath', wcommon.make_websocket_url(request, '/testpath'))
def setUp(self): wcommon = WebServiceCommon.stub(reactor=the_reactor) self.obj = StateSpecimen() r = BlockResource(self.obj, wcommon, None) self.port = the_reactor.listenTCP(0, SiteWithDefaultHeaders(r), interface="127.0.0.1") # pylint: disable=no-member
def __init__(self, reactor, cap_table, http_endpoint, ws_endpoint, root_cap, title): # Constants self.__http_endpoint_string = str(http_endpoint) self.__http_endpoint = endpoints.serverFromString(reactor, self.__http_endpoint_string) self.__ws_endpoint = endpoints.serverFromString(reactor, str(ws_endpoint)) self.__visit_path = _make_cap_url(root_cap) wcommon = WebServiceCommon( reactor=reactor, title=title, ws_endpoint_string=ws_endpoint) # TODO: Create poller actually for the given reactor w/o redundancy -- perhaps there should be a one-poller-per-reactor map subscription_context = SubscriptionContext(reactor=reactor, poller=the_poller) def resource_factory(entry_point): # TODO: If not an IWebEntryPoint, return a generic result return IWebEntryPoint(entry_point).get_entry_point_resource(wcommon=wcommon) # pylint: disable=redundant-keyword-arg server_root = CapAccessResource(cap_table=cap_table, resource_factory=resource_factory) _put_root_static(wcommon, server_root) if UNIQUE_PUBLIC_CAP in cap_table: # TODO: consider factoring out "generate URL for cap" server_root.putChild('', Redirect(_make_cap_url(UNIQUE_PUBLIC_CAP))) self.__ws_protocol = txws.WebSocketFactory( FactoryWithArgs.forProtocol(WebSocketDispatcherProtocol, cap_table, subscription_context)) self.__site = SiteWithDefaultHeaders(server_root) self.__ws_port_obj = None self.__http_port_obj = None
def test_resource_smoke(self): IResource(self.session.get_entry_point_resource( wcommon=WebServiceCommon.stub(reactor=the_reactor)))
def test_make_websocket_url_relative(self): wcommon = WebServiceCommon.stub(the_reactor) request = FakeRequest() self.assertRaises( AssertionError, lambda: wcommon.make_websocket_url(request, 'boguspath'))