Пример #1
0
    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 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.
Пример #3
0
class TestWebServicePageIDs(TestCase):
    """Ensure that the web service enhances the page ID correctly."""
    def setUp(self):
        super(TestWebServicePageIDs, self).setUp()
        self.publication = WebServicePublication(db=None)
        self.view = FakeView()
        self.context = FakeContext()

    def makePageID(self):
        return self.publication.constructPageID(self.view, self.context)

    def test_pageid_without_op(self):
        # When the HTTP request does not have a named operation (ws.op) field
        # (either in the body or query string), the operation is included in
        # the page ID.
        self.assertEqual(self.makePageID(), 'FakeContext:FakeView')

    def test_pageid_without_op_in_form(self):
        # When the HTTP request does not have a named operation (ws.op) field
        # (either in the body or query string), the operation is included in
        # the page ID.
        self.view.request.form_values['ws.op'] = 'operation-name-1'
        self.assertEqual(self.makePageID(),
                         'FakeContext:FakeView:operation-name-1')

    def test_pageid_without_op_in_query_string(self):
        # When the HTTP request does not have a named operation (ws.op) field
        # (either in the body or query string), the operation is included in
        # the page ID.
        self.view.request.query_string_params['ws.op'] = 'operation-name-2'
        self.assertEqual(self.makePageID(),
                         'FakeContext:FakeView:operation-name-2')
Пример #4
0
class TestWebServicePageIDs(TestCase):
    """Ensure that the web service enhances the page ID correctly."""

    def setUp(self):
        super(TestWebServicePageIDs, self).setUp()
        self.publication = WebServicePublication(db=None)
        self.view = FakeView()
        self.context = FakeContext()

    def makePageID(self):
        return self.publication.constructPageID(self.view, self.context)

    def test_pageid_without_op(self):
        # When the HTTP request does not have a named operation (ws.op) field
        # (either in the body or query string), the operation is included in
        # the page ID.
        self.assertEqual(
            self.makePageID(), 'FakeContext:FakeView')

    def test_pageid_without_op_in_form(self):
        # When the HTTP request does not have a named operation (ws.op) field
        # (either in the body or query string), the operation is included in
        # the page ID.
        self.view.request.form_values['ws.op'] = 'operation-name-1'
        self.assertEqual(
            self.makePageID(), 'FakeContext:FakeView:operation-name-1')

    def test_pageid_without_op_in_query_string(self):
        # When the HTTP request does not have a named operation (ws.op) field
        # (either in the body or query string), the operation is included in
        # the page ID.
        self.view.request.query_string_params['ws.op'] = 'operation-name-2'
        self.assertEqual(
            self.makePageID(), 'FakeContext:FakeView:operation-name-2')
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
class TestCollectionResourcePageIDs(TestCase):
    """Ensure page ids for collections display the origin page resource."""
    def setUp(self):
        super(TestCollectionResourcePageIDs, self).setUp()
        self.publication = WebServicePublication(db=None)
        self.view = FakeCollectionResourceView()
        self.context = FakeContext()

    def makePageID(self):
        return self.publication.constructPageID(self.view, self.context)

    def test_origin_pageid_for_collection(self):
        # When the view provides a ICollectionResource, make sure the origin
        # page resource is included in the page ID.
        self.assertEqual(
            self.makePageID(),
            'FakeContext:FakeCollectionResourceView:#milestone-page-resource')
Пример #8
0
    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")
Пример #9
0
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)
Пример #10
0
class TestPageIdCorners(TestCase):
    """Ensure that the page ID generation handles corner cases well."""
    def setUp(self):
        super(TestPageIdCorners, self).setUp()
        self.publication = WebServicePublication(db=None)
        self.view = FakeView()
        self.context = FakeContext()

    def makePageID(self):
        return self.publication.constructPageID(self.view, self.context)

    def test_pageid_with_multiple_op_fields(self):
        # The publisher will combine multiple form values with the same name
        # into a list.  If those values are for "ws.op", the page ID mechanism
        # should just ignore the op altogether.  (It used to generate an
        # error, see bug 810113).
        self.view.request.form_values['ws.op'] = ['one', 'another']
        self.assertEqual(self.makePageID(), 'FakeContext:FakeView')
Пример #11
0
class TestCollectionResourcePageIDs(TestCase):
    """Ensure page ids for collections display the origin page resource."""

    def setUp(self):
        super(TestCollectionResourcePageIDs, self).setUp()
        self.publication = WebServicePublication(db=None)
        self.view = FakeCollectionResourceView()
        self.context = FakeContext()

    def makePageID(self):
        return self.publication.constructPageID(self.view, self.context)

    def test_origin_pageid_for_collection(self):
        # When the view provides a ICollectionResource, make sure the origin
        # page resource is included in the page ID.
        self.assertEqual(
            self.makePageID(),
            'FakeContext:FakeCollectionResourceView:#milestone-page-resource')
Пример #12
0
class TestPageIdCorners(TestCase):
    """Ensure that the page ID generation handles corner cases well."""

    def setUp(self):
        super(TestPageIdCorners, self).setUp()
        self.publication = WebServicePublication(db=None)
        self.view = FakeView()
        self.context = FakeContext()

    def makePageID(self):
        return self.publication.constructPageID(self.view, self.context)

    def test_pageid_with_multiple_op_fields(self):
        # The publisher will combine multiple form values with the same name
        # into a list.  If those values are for "ws.op", the page ID mechanism
        # should just ignore the op altogether.  (It used to generate an
        # error, see bug 810113).
        self.view.request.form_values['ws.op'] = ['one', 'another']
        self.assertEqual(self.makePageID(), 'FakeContext:FakeView')
Пример #13
0
 def test_WebServicePub_fires_FinishReadOnlyRequestEvent(self):
     # WebServicePublication.finishReadOnlyRequest() issues an
     # IFinishReadOnlyRequestEvent and commits the transaction.
     publication = WebServicePublication(None)
     self._test_publication(publication, ["COMMIT"])
Пример #14
0
 def setUp(self):
     super(TestWebServicePageIDs, self).setUp()
     self.publication = WebServicePublication(db=None)
     self.view = FakeView()
     self.context = FakeContext()
Пример #15
0
 def setUp(self):
     super(TestPageIdCorners, self).setUp()
     self.publication = WebServicePublication(db=None)
     self.view = FakeView()
     self.context = FakeContext()
Пример #16
0
 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)
Пример #17
0
 def setUp(self):
     super(TestCollectionResourcePageIDs, self).setUp()
     self.publication = WebServicePublication(db=None)
     self.view = FakeCollectionResourceView()
     self.context = FakeContext()