summaryrefslogtreecommitdiff
path: root/tests/unit/test_utils.py
diff options
context:
space:
mode:
authorZack M. Davis <zdavis@swiftstack.com>2015-09-04 14:57:30 -0700
committerZack M. Davis <zdavis@swiftstack.com>2015-09-04 14:57:30 -0700
commit52d39bebc11979fa1be5090ff75466710638e561 (patch)
treef700b14751375eadd84f2688a73f1e930a24930d /tests/unit/test_utils.py
parent93666bb84abc1edc36fbb3ef5ec194cf774e4826 (diff)
downloadpython-swiftclient-52d39bebc11979fa1be5090ff75466710638e561.tar.gz
absolute expiry option for tempURL generation
The `tempurl` subcommand's second positional argument is called `seconds` and has heretofore interpreted as the number of seconds for which the tempURL should be valid, counting from the moment of running the command. This is indeed a common, if not the most common, use-case. But some users, occasionally, might want to generate a tempURL that expires at some particular ("absolute") time, rather than a particular amount of time relative to the moment of happening to run the command. (One might make an analogy to the way in which Swift's expiring object support supports an `X-Delete-At` header in addition to `X-Delete-After`—and it's the former that must be regarded as ontologically prior.) Thus, this commit adds an `--absolute` optional argument to the `tempurl` subcommand; if present, the `seconds` argument will be interpreted as a Unix timestamp of when the tempURL should be expire, rather than a duration for which the tempURL should be valid starting from "now". Change-Id: If9ded96f2799800958d5063127f3de812f50ef06
Diffstat (limited to 'tests/unit/test_utils.py')
-rw-r--r--tests/unit/test_utils.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index ca3531e..7d7f6b6 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -132,11 +132,9 @@ class TestTempURL(testtools.TestCase):
self.key = 'correcthorsebatterystaple'
self.method = 'GET'
- @mock.patch('hmac.HMAC.hexdigest')
- @mock.patch('time.time')
+ @mock.patch('hmac.HMAC.hexdigest', return_value='temp_url_signature')
+ @mock.patch('time.time', return_value=1400000000)
def test_generate_temp_url(self, time_mock, hmac_mock):
- time_mock.return_value = 1400000000
- hmac_mock.return_value = 'temp_url_signature'
expected_url = (
'/v1/AUTH_account/c/o?'
'temp_url_sig=temp_url_signature&'
@@ -145,6 +143,15 @@ class TestTempURL(testtools.TestCase):
self.method)
self.assertEqual(url, expected_url)
+ @mock.patch('hmac.HMAC.hexdigest', return_value="temp_url_signature")
+ def test_generate_absolute_expiry_temp_url(self, hmac_mock):
+ expected_url = ('/v1/AUTH_account/c/o?'
+ 'temp_url_sig=temp_url_signature&'
+ 'temp_url_expires=2146636800')
+ url = u.generate_temp_url(self.url, 2146636800, self.key, self.method,
+ absolute=True)
+ self.assertEqual(url, expected_url)
+
def test_generate_temp_url_bad_seconds(self):
self.assertRaises(TypeError,
u.generate_temp_url,