def test_store_disconnected_after_request_handled_logs_oops(self): # Bug #504291 was that a Store was being left in a disconnected # state after a request, causing subsequent requests handled by that # thread to fail. We detect this state in endRequest and log an # OOPS to help track down the trigger. request = LaunchpadTestRequest() publication = WebServicePublication(None) dbadapter.set_request_started() # Disconnect a store store = IMasterStore(EmailAddress) store._connection._state = STATE_DISCONNECTED # Invoke the endRequest hook. publication.endRequest(request, None) self.assertEqual(1, len(self.oopses)) oops = self.oopses[0] # Ensure the OOPS mentions the correct exception self.assertStartsWith(oops['value'], "Bug #504291") # Ensure the store has been rolled back and in a usable state. self.assertEqual(store._connection._state, STATE_RECONNECT) store.find(EmailAddress).first() # Confirms Store is working.
def createRequest(self, body_instream, environ): """See `IWebServiceConfiguration`.""" # The request is going to try to decode the 'PATH_INFO' using utf-8, # so if it is currently unicode, encode it. if 'PATH_INFO' in environ: environ['PATH_INFO'] = six.ensure_binary(environ['PATH_INFO']) request = WebServiceClientRequest(body_instream, environ) request.setPublication(WebServicePublication(None)) return request
def createRequest(self, body_instream, environ): """See `IWebServiceConfiguration`.""" # The request is going to try to decode the 'PATH_INFO' using utf-8, # so if it is currently unicode, encode it. if isinstance(environ.get('PATH_INFO'), unicode): environ['PATH_INFO'] = environ['PATH_INFO'].encode('utf-8') request = WebServiceClientRequest(body_instream, environ) request.setPublication(WebServicePublication(None)) return request
def test_disconnect_logs_oops(self): # Ensure that OOPS reports are generated for database # disconnections, as per Bug #373837. request = LaunchpadTestRequest() publication = WebServicePublication(None) dbadapter.set_request_started() try: raise DisconnectionError('Fake') except DisconnectionError: self.assertRaises(Retry, publication.handleException, None, request, sys.exc_info(), True) dbadapter.clear_request_started() self.assertEqual(1, len(self.oopses)) oops = self.oopses[0] # Ensure the OOPS mentions the correct exception self.assertEqual(oops['type'], "DisconnectionError")
def _generate_web_service_root(version, mimetype): """Generate the webservice description for the given version and mimetype. """ url = urlparse.urljoin(allvhosts.configs['api'].rooturl, version) # Since we want HTTPS URLs we have to munge the request URL. url = url.replace('http://', 'https://') request = WebServiceTestRequest(version=version, environ={ 'SERVER_URL': url, 'HTTP_HOST': allvhosts.configs['api'].hostname, 'HTTP_ACCEPT': mimetype, }) # We then bypass the usual publisher processing by associating # the request with the WebServicePublication (usually done by the # publisher) and then calling the root resource - retrieved # through getApplication(). request.setPublication(WebServicePublication(None)) setupInteractionByEmail(ANONYMOUS, request) return request.publication.getApplication(request)(request)
def test_WebServicePub_fires_FinishReadOnlyRequestEvent(self): # WebServicePublication.finishReadOnlyRequest() issues an # IFinishReadOnlyRequestEvent and commits the transaction. publication = WebServicePublication(None) self._test_publication(publication, ["COMMIT"])
def setUp(self): super(TestWebServicePageIDs, self).setUp() self.publication = WebServicePublication(db=None) self.view = FakeView() self.context = FakeContext()
def test_getPrincipal_for_person_and_account_with_different_ids(self): # WebServicePublication.getPrincipal() does not rely on accounts # having the same IDs as their associated person entries to work. request = self._getRequestForPersonAndAccountWithDifferentIDs() principal = WebServicePublication(None).getPrincipal(request) self.assertIsNotNone(principal)