def test_get_document(self): """ Test and assert that connection.get_object is called with the correct arguments """ connection = Mock() container_name = 'container_name_mock' object_name = 'object_name_mock' objstore = ObjectStore(config='this is the config') objstore.get_document(connection, container_name, object_name) connection.get_object.assert_called_with(container_name, object_name)
def get_file(self, request, pk=None): document_model = self.get_object() container_path = ObjectStore.get_container_path(document_model.type) filename = document_model.filename objstore = ObjectStore(settings.OBJECTSTORE_CONNECTION_CONFIG) connection = objstore.get_connection() try: store_object = objstore.get_document(connection, container_path, filename) except ClientException as e: return handle_swift_exception(container_path, filename, e) content_type = store_object[0].get('content-type') obj_data = store_object[1] response = HttpResponse(content_type=content_type) response['Content-Disposition'] = f'attachment; filename="{filename}"' response.write(obj_data) return response