Created
March 31, 2016 16:01
-
-
Save alistairncoles/8c7ed4ef1220f06b0591709c767a6346 to your computer and use it in GitHub Desktop.
Extra test for object versioning reverse listing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/swift/common/middleware/versioned_writes.py b/swift/common/middleware/versioned_writes.py | |
index 51497c7..a742587 100644 | |
--- a/swift/common/middleware/versioned_writes.py | |
+++ b/swift/common/middleware/versioned_writes.py | |
@@ -244,7 +244,7 @@ class VersionedWritesContext(WSGIContext): | |
first_item = sublisting[0]['name'].encode('utf-8') | |
last_item = sublisting[-1]['name'].encode('utf-8') | |
page_is_after_marker = marker and first_item > marker | |
- if reverse and (first_item < last_item or page_is_after_marker): | |
+ if reverse and (first_item <= last_item or page_is_after_marker): | |
# Apparently there's at least one pre-2.6.0 container server | |
yield self._in_proxy_reverse_listing( | |
account_name, lcontainer, lprefix, | |
diff --git a/test/unit/common/middleware/test_versioned_writes.py b/test/unit/common/middleware/test_versioned_writes.py | |
index b5ef198..e53ef58 100644 | |
--- a/test/unit/common/middleware/test_versioned_writes.py | |
+++ b/test/unit/common/middleware/test_versioned_writes.py | |
@@ -520,6 +520,44 @@ class VersionedWritesTestCase(VersionedWritesBaseTestCase): | |
('DELETE', '/v1/a/ver_cont/001o/2'), | |
]) | |
+ def test_delete_single_version_success(self): | |
+ # check that if the first listing page has just a single item then | |
+ # it is not erroneously inferred to be a non-reversed listing | |
+ self.app.register( | |
+ 'DELETE', '/v1/a/c/o', swob.HTTPOk, {}, 'passed') | |
+ self.app.register( | |
+ 'GET', | |
+ '/v1/a/ver_cont?format=json&prefix=001o/&marker=&reverse=on', | |
+ swob.HTTPOk, {}, | |
+ '[{"hash": "y", ' | |
+ '"last_modified": "2014-11-21T14:23:02.206740", ' | |
+ '"bytes": 3, ' | |
+ '"name": "001o/1", ' | |
+ '"content_type": "text/plain"}]') | |
+ self.app.register( | |
+ 'COPY', '/v1/a/ver_cont/001o/1', swob.HTTPCreated, | |
+ {}, None) | |
+ self.app.register( | |
+ 'DELETE', '/v1/a/ver_cont/001o/1', swob.HTTPOk, | |
+ {}, None) | |
+ | |
+ cache = FakeCache({'sysmeta': {'versions-location': 'ver_cont'}}) | |
+ req = Request.blank( | |
+ '/v1/a/c/o', | |
+ environ={'REQUEST_METHOD': 'DELETE', 'swift.cache': cache, | |
+ 'CONTENT_LENGTH': '0'}) | |
+ status, headers, body = self.call_vw(req) | |
+ self.assertEqual(status, '200 OK') | |
+ self.assertEqual(len(self.authorized), 1) | |
+ self.assertRequestEqual(req, self.authorized[0]) | |
+ | |
+ prefix_listing_prefix = '/v1/a/ver_cont?format=json&prefix=001o/&' | |
+ self.assertEqual(self.app.calls, [ | |
+ ('GET', prefix_listing_prefix + 'marker=&reverse=on'), | |
+ ('COPY', '/v1/a/ver_cont/001o/1'), | |
+ ('DELETE', '/v1/a/ver_cont/001o/1'), | |
+ ]) | |
+ | |
def test_DELETE_on_expired_versioned_object(self): | |
self.app.register( | |
'GET', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment