From aeccbc2074224c6688be6ef5aa8ba477c9631ba1 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Tue, 24 Nov 2015 14:47:30 +0000 Subject: [PATCH] Add more functional tests for reverse listings Also fix typo in the api doc. Follow-on to change I5eb655360ac95042877da26d18707aebc11c02f6 Change-Id: Ic1ea63c74a0a3b90a505865fba8fcfac584d0825 --- doc/source/api/object_api_v1_overview.rst | 4 +- test/functional/tests.py | 77 +++++++++++++++++++++-- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/doc/source/api/object_api_v1_overview.rst b/doc/source/api/object_api_v1_overview.rst index a0a472869c..99578904c0 100644 --- a/doc/source/api/object_api_v1_overview.rst +++ b/doc/source/api/object_api_v1_overview.rst @@ -129,8 +129,8 @@ parameters to page through large lists of containers or objects. Use the *``marker``*, *``limit``*, and *``end_marker``* query parameters to control how many items are returned in a list and where the list starts or ends. If you want to page through in reverse order, you can use the query -parameter *``reverse``*, noting that your marker and end_markers will be -applied to a reverse listing should be switched. I.e, for a list of objects +parameter *``reverse``*, noting that your marker and end_markers should be +switched when applied to a reverse listing. I.e, for a list of objects ``[a, b, c, d, e]`` the non-reversed could be: .. code:: diff --git a/test/functional/tests.py b/test/functional/tests.py index 911ef46d5d..cc0ecfe025 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -229,6 +229,45 @@ class TestAccount(Base): self.assertEqual(a, b) + def testListDelimiter(self): + delimiter = '-' + containers = ['test', delimiter.join(['test', 'bar']), + delimiter.join(['test', 'foo'])] + for c in containers: + cont = self.env.account.container(c) + self.assertTrue(cont.create()) + + results = self.env.account.containers(parms={'delimiter': delimiter}) + expected = ['test', 'test-'] + results = [r for r in results if r in expected] + self.assertEqual(expected, results) + + results = self.env.account.containers(parms={'delimiter': delimiter, + 'reverse': 'yes'}) + expected.reverse() + results = [r for r in results if r in expected] + self.assertEqual(expected, results) + + def testListDelimiterAndPrefix(self): + delimiter = 'a' + containers = ['bar', 'bazar'] + for c in containers: + cont = self.env.account.container(c) + self.assertTrue(cont.create()) + + results = self.env.account.containers(parms={'delimiter': delimiter, + 'prefix': 'ba'}) + expected = ['bar', 'baza'] + results = [r for r in results if r in expected] + self.assertEqual(expected, results) + + results = self.env.account.containers(parms={'delimiter': delimiter, + 'prefix': 'ba', + 'reverse': 'yes'}) + expected.reverse() + results = [r for r in results if r in expected] + self.assertEqual(expected, results) + def testInvalidAuthToken(self): hdrs = {'X-Auth-Token': 'bogus_auth_token'} self.assertRaises(ResponseError, self.env.account.info, hdrs=hdrs) @@ -351,12 +390,27 @@ class TestAccountSorting(Base): set_up = False def testAccountContainerListSorting(self): + # name (byte order) sorting. + cont_list = sorted(self.env.cont_items) + for reverse in ('false', 'no', 'off', '', 'garbage'): + cont_listing = self.env.account.containers( + parms={'reverse': reverse}) + self.assert_status(200) + self.assertEqual(cont_list, cont_listing, + 'Expected %s but got %s with reverse param %r' + % (cont_list, cont_listing, reverse)) + + def testAccountContainerListSortingReverse(self): # name (byte order) sorting. cont_list = sorted(self.env.cont_items) cont_list.reverse() - cont_listing = self.env.account.containers(parms={'reverse': 'on'}) - self.assert_status(200) - self.assertEqual(cont_list, cont_listing) + for reverse in ('true', '1', 'yes', 'on', 't', 'y'): + cont_listing = self.env.account.containers( + parms={'reverse': reverse}) + self.assert_status(200) + self.assertEqual(cont_list, cont_listing, + 'Expected %s but got %s with reverse param %r' + % (cont_list, cont_listing, reverse)) def testAccountContainerListSortingByPrefix(self): cont_list = sorted(c for c in self.env.cont_items if c.startswith('a')) @@ -526,6 +580,9 @@ class TestContainer(Base): results = cont.files(parms={'delimiter': delimiter}) self.assertEqual(results, ['test', 'test-']) + results = cont.files(parms={'delimiter': delimiter, 'reverse': 'yes'}) + self.assertEqual(results, ['test-', 'test']) + def testListDelimiterAndPrefix(self): cont = self.env.account.container(Utils.create_name()) self.assertTrue(cont.create()) @@ -539,6 +596,11 @@ class TestContainer(Base): results = cont.files(parms={'delimiter': delimiter, 'prefix': 'ba'}) self.assertEqual(results, ['bar', 'baza']) + results = cont.files(parms={'delimiter': delimiter, + 'prefix': 'ba', + 'reverse': 'yes'}) + self.assertEqual(results, ['baza', 'bar']) + def testCreate(self): cont = self.env.account.container(Utils.create_name()) self.assertTrue(cont.create()) @@ -747,9 +809,12 @@ class TestContainerSorting(Base): def testContainerFileListSortingReversed(self): file_list = list(sorted(self.env.file_items)) file_list.reverse() - cont_files = self.env.container.files(parms={'reverse': 'on'}) - self.assert_status(200) - self.assertEqual(file_list, cont_files) + for reverse in ('true', '1', 'yes', 'on', 't', 'y'): + cont_files = self.env.container.files(parms={'reverse': reverse}) + self.assert_status(200) + self.assertEqual(file_list, cont_files, + 'Expected %s but got %s with reverse param %r' + % (file_list, cont_files, reverse)) def testContainerFileSortingByPrefixReversed(self): cont_list = sorted(c for c in self.env.file_items if c.startswith('a'))