Skip to content

Commit

Permalink
Merge branch 'feature/async-bulk-move' into 'develop'
Browse files Browse the repository at this point in the history
Merge feature/async-bulk-move into develop

See merge request core/sevenbridges-python!52
  • Loading branch information
Stevan Pejak committed Dec 13, 2019
2 parents 5538268 + d5379b7 commit 54fdca0
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
#html_static_path = ['_static']
# html_static_path = ['_static']

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down
24 changes: 23 additions & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1802,8 +1802,10 @@ The following operations are supported for async operations runs:
- ``list_file_jobs()`` - Query all async jobs for files.
- ``get_copy_files_job()`` - Get the details of an asynchronous bulk file copy job.
- ``get_delete_files_job()`` - Get the details of an asynchronous bulk file delete job.
- ``get_file_move_job()`` - Get the details of an asynchronous bulk file move job.
- ``get_results()`` - Parse results of a job as a bulk response.
- ``file_bulk_copy()`` - Perform a bulk copy operation of files and folders. Any underlying folder structure will be preserved.
- ``file_bulk_move()`` - Perform a bulk move operation of files and folders. Any underlying folder structure will be preserved.
- ``file_bulk_delete()`` - Perform a bulk delete operation of files and folders. Deleting folders which aren't empty is allowed.

Properties
Expand All @@ -1813,7 +1815,7 @@ Each async job has the following properties:

``id`` - Async job identifier.

``type`` - The type of job, which is COPY in the case of copying files, and DELETE in case of deleting files.
``type`` - The type of job, which is COPY in the case of copying files, MOVE in case of moving files and DELETE in case of deleting files.

``state`` - Current job state (RUNNING, FINISHED, SUBMITTED, RESOLVING)

Expand Down Expand Up @@ -1879,3 +1881,23 @@ Examples
},
]
new_delete_job = api.async_jobs.file_bulk_delete(files=files)
# Start bulk file move job
files = [
{
'file': 'file_id_1',
'project': project_id,
'name': 'name_1',
},
{
'file': 'file_id_2',
'project': project_id,
'name': 'name_2',
},
{
'file': 'file_id_3',
'project': project_id,
'name': 'name_2',
}
]
new_move_job = api.async_jobs.file_bulk_move(files=files)
30 changes: 29 additions & 1 deletion sevenbridges/models/async_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class AsyncJob(Resource):
'get_file_copy_job': '/async/files/copy/{id}',
'get_file_delete_job': '/async/files/delete/{id}',
'bulk_copy_files': '/async/files/copy',
'bulk_delete_files': '/async/files/delete'
'bulk_delete_files': '/async/files/delete',
'get_file_move_job': '/async/files/move/{id}',
'bulk_move_files': '/async/files/move',
}

id = StringField(read_only=True)
Expand Down Expand Up @@ -84,6 +86,22 @@ def get_file_copy_job(cls, id, api=None):
).json()
return AsyncJob(api=api, **async_job)

@classmethod
def get_file_move_job(cls, id, api=None):
"""
Retrieve file move async job
:param id: Async job identifier
:param api: Api instance
:return:
"""
id = Transform.to_async_job(id)

api = api if api else cls._API
async_job = api.get(
url=cls._URL['get_file_move_job'].format(id=id)
).json()
return AsyncJob(api=api, **async_job)

@classmethod
def get_file_delete_job(cls, id, api=None):
"""
Expand Down Expand Up @@ -138,6 +156,16 @@ def file_bulk_copy(cls, files, api=None):
).json()
return AsyncJob(api=api, **response)

@classmethod
def file_bulk_move(cls, files, api=None):
api = api or cls._API
data = {'items': files}
logger.info('Submitting async job for moving files in bulk')
response = api.post(
url=cls._URL['bulk_move_files'], data=data
).json()
return AsyncJob(api=api, **response)

@classmethod
def file_bulk_delete(cls, files, api=None):
api = api or cls._API
Expand Down
1 change: 1 addition & 0 deletions sevenbridges/models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class AsyncJobStates:
class AsyncFileOperations:
COPY = 'copy'
DELETE = 'delete'
MOVE = 'move'


class DivisionRole:
Expand Down
10 changes: 10 additions & 0 deletions sevenbridges/tests/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1780,3 +1780,13 @@ def can_delete_files(self, files):
self.request_mocker.post(
'/async/files/delete', json=async_job
)

def can_move_files(self, files):
async_job = self.default_async_job()
async_job['result'] = [
{'resource': {'id': file['file']}}
for file in files
]
self.request_mocker.post(
'/async/files/move', json=async_job
)
35 changes: 35 additions & 0 deletions sevenbridges/tests/test_async_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def test_get_copy_files_job(api, given, verifier):
verifier.async_jobs.file_copy_job_fetched(id=id)


def test_get_move_files_job(api, given, verifier):
# preconditions
id = generator.uuid4()
given.async_jobs.exists(id=id, type=AsyncFileOperations.MOVE)

# action
job = api.async_jobs.get_file_move_job(id=id)

# verification
assert job.id == id
verifier.async_jobs.file_move_job_fetched(id=id)


def test_get_delete_files_job(api, given, verifier):
# preconditions
id = generator.uuid4()
Expand Down Expand Up @@ -95,6 +108,28 @@ def test_async_copy_files(api, given, verifier, location):
verifier.async_jobs.async_files_copied()


@pytest.mark.parametrize("location", ['parent', 'project'])
def test_async_move_files(api, given, verifier, location):
# preconditions
total = 10
files = [
{
'file': generator.uuid4(),
'location': generator.uuid4(),
'name': generator.slug()
} for _ in range(total)
]
given.async_jobs.can_move_files(files=files)

# action
job = api.async_jobs.file_bulk_move(files=files)

# verification
assert job.state == AsyncJobStates.SUBMITTED
assert len(job.result) == total
verifier.async_jobs.async_files_moved()


def test_async_delete_files(api, given, verifier):
# preconditions
total = 10
Expand Down
6 changes: 6 additions & 0 deletions sevenbridges/tests/verifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,3 +602,9 @@ def async_files_copied(self):

def async_files_deleted(self):
self.checker.check_url('/async/files/delete')

def file_move_job_fetched(self, id):
self.checker.check_url('/async/files/move/{}'.format(id))

def async_files_moved(self):
self.checker.check_url('/async/files/move')

0 comments on commit 54fdca0

Please sign in to comment.