diff --git a/swift/obj/mem_diskfile.py b/swift/obj/mem_diskfile.py index e86c321e2f..a3b37f4834 100644 --- a/swift/obj/mem_diskfile.py +++ b/swift/obj/mem_diskfile.py @@ -43,17 +43,37 @@ class InMemoryFileSystem(object): self._filesystem = {} def get_object(self, name): + """ + Return back an file-like object and its metadata + + :param name: standard object name + :return (fp, metadata): fp is `StringIO` in-memory representation + object (or None). metadata is a dictionary + of metadata (or None) + """ val = self._filesystem.get(name) if val is None: - data, metadata = None, None + fp, metadata = None, None else: - data, metadata = val - return data, metadata + fp, metadata = val + return fp, metadata - def put_object(self, name, data, metadata): - self._filesystem[name] = (data, metadata) + def put_object(self, name, fp, metadata): + """ + Store object into memory + + :param name: standard object name + :param fp: `StringIO` in-memory representation object + :param metadata: dictionary of metadata to be written + """ + self._filesystem[name] = (fp, metadata) def del_object(self, name): + """ + Delete object from memory + + :param name: standard object name + """ del self._filesystem[name] def get_diskfile(self, account, container, obj, **kwargs): diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 551b51af22..5f9d03094d 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -2970,6 +2970,10 @@ class TestObjectController(unittest.TestCase): # now POST to the object using default object_post_as_copy setting orig_post_as_copy = prosrv.object_post_as_copy + + # last-modified rounded in sec so sleep a sec to increment + sleep(1) + sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() fd.write('POST /v1/a/c/o.last_modified HTTP/1.1\r\n' @@ -2984,10 +2988,14 @@ class TestObjectController(unittest.TestCase): # last modified time will have changed due to POST last_modified_head = _do_HEAD() + self.assertNotEqual(last_modified_put, last_modified_head) _do_conditional_GET_checks(last_modified_head) # now POST using non-default object_post_as_copy setting try: + # last-modified rounded in sec so sleep a sec to increment + last_modified_post = last_modified_head + sleep(1) prosrv.object_post_as_copy = not orig_post_as_copy sock = connect_tcp(('localhost', prolis.getsockname()[1])) fd = sock.makefile() @@ -3005,6 +3013,7 @@ class TestObjectController(unittest.TestCase): # last modified time will have changed due to POST last_modified_head = _do_HEAD() + self.assertNotEqual(last_modified_post, last_modified_head) _do_conditional_GET_checks(last_modified_head) def test_PUT_auto_content_type(self):