Пример #1
0
class TestRetryAfterHeaders(unittest.TestCase, DSSAssertMixin):
    """Presence or absence of Retry-After headers is defined by dss.error.include_retry_after_header."""
    def test_502_get_bundle_HAS_retry_after_response(self):
        """Mock seems resistant to multiple calls, therefore this is only used for one endpoint."""
        with mock.patch('dss.api.bundles.get',
                        side_effect=DSSException(502, 'bad_gateway',
                                                 "Bad Gateway")):
            self.app = ThreadedLocalServer()
            self.app.start()
            uuid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
            version = datetime_to_version_format(datetime.datetime.utcnow())

            url = str(UrlBuilder().set(path=f"/v1/bundles/{uuid}").add_query(
                "version", version).add_query("replica", 'aws'))

            r = self.assertGetResponse(url, 502, headers=get_auth_header())
            self.assertEqual(int(r.response.headers['Retry-After']), 10)
            self.app.shutdown()

    def test_500_server_error(self):
        """Test that the dss_handler includes retry-after headers."""
        with app.test_request_context('/test'):
            r = mock_500_server_error()
            self.assertEqual(int(r.headers['Retry-After']), 10)

    def test_501_not_implemented(self):
        """501 should not be retried."""
        with app.test_request_context('/test'):
            r = mock_501_not_implemented()
            self.assertEqual(r.headers.get('Retry-After'), None)

    def test_502_bad_gateway(self):
        """Test that the dss_handler includes retry-after headers."""
        with app.test_request_context('/test'):
            r = mock_502_bad_gateway()
            self.assertEqual(int(r.headers['Retry-After']), 10)

    def test_503_service_unavailable(self):
        """Test that the dss_handler includes retry-after headers."""
        with app.test_request_context('/test'):
            r = mock_503_service_unavailable()
            self.assertEqual(int(r.headers['Retry-After']), 10)

    def test_504_504_gateway_timeout(self):
        """Test that the dss_handler includes retry-after headers."""
        with app.test_request_context('/test'):
            r = mock_504_gateway_timeout()
            self.assertEqual(int(r.headers['Retry-After']), 10)
Пример #2
0
 def test_build_bundle_metadata_document(self):
     dss.Config.set_config(dss.BucketConfig.TEST)
     app = ThreadedLocalServer()
     app.start()
     self.addCleanup(app.shutdown)
     for replica in Replica:
         uuid, version = _upload_bundle(app, replica)
         key = f"bundles/{uuid}.{version}"
         with self.subTest("Build normal bundle metadata document", replica=replica):
             md = events.build_bundle_metadata_document(replica, key)
             self.assertIn("manifest", md)
             self.assertIn("files", md)
             self.assertIn("version", md['manifest'])
             self.assertIn("files", md['manifest'])
             self.assertEqual(md['event_type'], "CREATE")
             self.assertEqual(md['bundle_info']['uuid'], uuid)
             self.assertEqual(md['bundle_info']['version'], version)
         _tombstone_bundle(app, replica, uuid, version)
         with self.subTest("Build tombstoned bundle metadata document", replica=replica):
             md = events.build_bundle_metadata_document(replica, f"{key}.{TOMBSTONE_SUFFIX}")
             self.assertNotIn("manifest", md)
             self.assertEqual(md['event_type'], "TOMBSTONE")
             self.assertEqual(md['bundle_info']['uuid'], uuid)
             self.assertEqual(md['bundle_info']['version'], version)