diff options
Diffstat (limited to 'test/functional/tests.py')
-rw-r--r-- | test/functional/tests.py | 79 |
1 files changed, 52 insertions, 27 deletions
diff --git a/test/functional/tests.py b/test/functional/tests.py index 808208d..e4b778b 100644 --- a/test/functional/tests.py +++ b/test/functional/tests.py @@ -1704,8 +1704,14 @@ class TestFileComparisonEnv: file_item.write_random(cls.file_size) cls.files.append(file_item) - cls.time_old = time.asctime(time.localtime(time.time() - 86400)) - cls.time_new = time.asctime(time.localtime(time.time() + 86400)) + cls.time_old_f1 = time.strftime("%a, %d %b %Y %H:%M:%S GMT", + time.gmtime(time.time() - 86400)) + cls.time_old_f2 = time.strftime("%A, %d-%b-%y %H:%M:%S GMT", + time.gmtime(time.time() - 86400)) + cls.time_old_f3 = time.strftime("%a %b %d %H:%M:%S %Y", + time.gmtime(time.time() - 86400)) + cls.time_new = time.strftime("%a, %d %b %Y %H:%M:%S GMT", + time.gmtime(time.time() + 86400)) class TestFileComparison(Base): @@ -1732,7 +1738,7 @@ class TestFileComparison(Base): def testIfModifiedSince(self): for file_item in self.env.files: - hdrs = {'If-Modified-Since': self.env.time_old} + hdrs = {'If-Modified-Since': self.env.time_old_f1} self.assert_(file_item.read(hdrs=hdrs)) hdrs = {'If-Modified-Since': self.env.time_new} @@ -1744,7 +1750,7 @@ class TestFileComparison(Base): hdrs = {'If-Unmodified-Since': self.env.time_new} self.assert_(file_item.read(hdrs=hdrs)) - hdrs = {'If-Unmodified-Since': self.env.time_old} + hdrs = {'If-Unmodified-Since': self.env.time_old_f2} self.assertRaises(ResponseError, file_item.read, hdrs=hdrs) self.assert_status(412) @@ -1760,10 +1766,32 @@ class TestFileComparison(Base): self.assert_status(412) hdrs = {'If-Match': file_item.md5, - 'If-Unmodified-Since': self.env.time_old} + 'If-Unmodified-Since': self.env.time_old_f3} self.assertRaises(ResponseError, file_item.read, hdrs=hdrs) self.assert_status(412) + def testLastModified(self): + file_name = Utils.create_name() + content_type = Utils.create_name() + + file = self.env.container.file(file_name) + file.content_type = content_type + resp = file.write_random_return_resp(self.env.file_size) + put_last_modified = resp.getheader('last-modified') + + file = self.env.container.file(file_name) + info = file.info() + self.assert_('last_modified' in info) + last_modified = info['last_modified'] + self.assertEqual(put_last_modified, info['last_modified']) + + hdrs = {'If-Modified-Since': last_modified} + self.assertRaises(ResponseError, file.read, hdrs=hdrs) + self.assert_status(304) + + hdrs = {'If-Unmodified-Since': last_modified} + self.assert_(file.read(hdrs=hdrs)) + class TestFileComparisonUTF8(Base2, TestFileComparison): set_up = False @@ -1776,6 +1804,24 @@ class TestSloEnv(object): def setUp(cls): cls.conn = Connection(config) cls.conn.authenticate() + + if cls.slo_enabled is None: + status = cls.conn.make_request('GET', '/info', + cfg={'verbatim_path': True}) + if not (200 <= status <= 299): + # Can't tell if SLO is enabled or not since we're running + # against an old cluster, so let's skip the tests instead of + # possibly having spurious failures. + cls.slo_enabled = False + else: + # Don't bother looking for ValueError here. If something is + # responding to a GET /info request with invalid JSON, then + # the cluster is broken and a test failure will let us know. + cluster_info = json.loads(cls.conn.response.read()) + cls.slo_enabled = 'slo' in cluster_info + if not cls.slo_enabled: + return + cls.account = Account(cls.conn, config.get('account', config['username'])) cls.account.delete_containers() @@ -1785,28 +1831,6 @@ class TestSloEnv(object): if not cls.container.create(): raise ResponseError(cls.conn.response) - # TODO(seriously, anyone can do this): make this use the /info API once - # it lands, both for detection of SLO and for minimum segment size - if cls.slo_enabled is None: - test_file = cls.container.file(".test-slo") - try: - # If SLO is enabled, this'll raise an error since - # X-Static-Large-Object is a reserved header. - # - # If SLO is not enabled, then this will get the usual 2xx - # response. - test_file.write( - "some contents", - hdrs={'X-Static-Large-Object': 'true'}) - except ResponseError as err: - if err.status == 400: - cls.slo_enabled = True - else: - raise - else: - cls.slo_enabled = False - return - seg_info = {} for letter, size in (('a', 1024 * 1024), ('b', 1024 * 1024), @@ -1865,6 +1889,7 @@ class TestSlo(Base): set_up = False def setUp(self): + raise SkipTest("SLO not enabled yet in gluster-swift") super(TestSlo, self).setUp() if self.env.slo_enabled is False: raise SkipTest("SLO not enabled") |