diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/test_shell.py | 8 | ||||
-rw-r--r-- | test/unit/test_utils.py | 39 |
2 files changed, 47 insertions, 0 deletions
diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py index f6af6cb..98d73e9 100644 --- a/test/unit/test_shell.py +++ b/test/unit/test_shell.py @@ -2079,6 +2079,14 @@ class TestShell(unittest.TestCase): '/v1/AUTH_account/c/o', "60", 'secret_key', 'GET', absolute=False, iso8601=False, prefix=False, ip_range=None, digest='sha256') + # sanity check that suffixes will just pass through to utils.py + argv = ["", "tempurl", "GET", "2d", "/v1/AUTH_account/c/o", + "secret_key"] + swiftclient.shell.main(argv) + temp_url.assert_called_with( + '/v1/AUTH_account/c/o', "2d", 'secret_key', 'GET', absolute=False, + iso8601=False, prefix=False, ip_range=None, digest='sha256') + @mock.patch('swiftclient.shell.generate_temp_url', return_value='') def test_temp_url_prefix_based(self, temp_url): argv = ["", "tempurl", "GET", "60", "/v1/AUTH_account/c/", diff --git a/test/unit/test_utils.py b/test/unit/test_utils.py index 129208d..6d2f4a1 100644 --- a/test/unit/test_utils.py +++ b/test/unit/test_utils.py @@ -122,6 +122,43 @@ class TestPrtBytes(unittest.TestCase): self.assertEqual('1024Y', u.prt_bytes(bytes_, True).lstrip()) +class TestParseTimestamp(unittest.TestCase): + def test_int(self): + self.assertEqual((1234, False), u.parse_timestamp(1234, False)) + self.assertEqual((3600, False), u.parse_timestamp('3600', False)) + + def test_suffixed(self): + self.assertEqual((54, False), u.parse_timestamp('54.321s', False)) + self.assertEqual((int(54.321 * 60), False), + u.parse_timestamp('54.321m', False)) + self.assertEqual((900, False), + u.parse_timestamp('15min', False)) + self.assertEqual((int(54.321 * 60 * 60), False), + u.parse_timestamp('54.321h', False)) + self.assertEqual((7200, False), + u.parse_timestamp('2hr', False)) + self.assertEqual((60 * 60 * 24, False), u.parse_timestamp('1d', False)) + + def test_str(self): + self.assertEqual((1615852800, True), + u.parse_timestamp('2021-03-16T00:00:00Z', False)) + + def test_absolute(self): + self.assertEqual((1234, True), u.parse_timestamp(1234, True)) + self.assertEqual((1615852800, True), + u.parse_timestamp('2021-03-16T00:00:00Z', True)) + + def test_error(self): + with self.assertRaises(ValueError): + u.parse_timestamp('asdf', False) + with self.assertRaises(ValueError): + u.parse_timestamp(12.34, False) + with self.assertRaises(ValueError): + u.parse_timestamp('54.321', True) + with self.assertRaises(ValueError): + u.parse_timestamp(-1, False) + + class TestTempURL(unittest.TestCase): url = '/v1/AUTH_account/c/o' seconds = 3600 @@ -422,6 +459,7 @@ class TestTempURL(unittest.TestCase): class TestTempURLUnicodePathAndKey(TestTempURL): url = '/v1/\u00e4/c/\u00f3' key = 'k\u00e9y' + seconds = '1hr' expected_body = '\n'.join([ 'GET', '1400003600', @@ -432,6 +470,7 @@ class TestTempURLUnicodePathAndKey(TestTempURL): class TestTempURLUnicodePathBytesKey(TestTempURL): url = '/v1/\u00e4/c/\u00f3' key = 'k\u00e9y'.encode('utf-8') + seconds = '60m' expected_body = '\n'.join([ 'GET', '1400003600', |