Skip to content

Commit

Permalink
Merge pull request #28 from OpenNeuroOrg/partial-status
Browse files Browse the repository at this point in the history
Draft status endpoint and partial flag
  • Loading branch information
nellh authored May 31, 2018
2 parents 3c6f89e + 489db59 commit ea4c4c3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
14 changes: 14 additions & 0 deletions datalad_service/handlers/draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datalad_service.common.annex import get_from_header
from datalad_service.common.celery import dataset_queue
from datalad_service.tasks.files import commit_files
from datalad_service.tasks.draft import is_dirty


class DraftResource(object):
Expand All @@ -13,6 +14,19 @@ def __init__(self, store):
def annex_path(self):
return self.store.annex_path

def on_get(self, req, resp, dataset):
"""
Return draft state (other than files).
"""
if dataset:
queue = dataset_queue(dataset)
# Maybe turn this into status?
partial = is_dirty.apply_async(
queue=queue, args=(self.annex_path, dataset))
partial.wait()
resp.media = {'partial': partial.get()}
resp.status = falcon.HTTP_OK

def on_post(self, req, resp, dataset):
"""
Commmit a draft change.
Expand Down
2 changes: 1 addition & 1 deletion datalad_service/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""All Celery tasks and related functions."""
__all__ = ['dataset', 'files', 'publish']
__all__ = ['dataset', 'draft', 'files', 'publish']
9 changes: 9 additions & 0 deletions datalad_service/tasks/draft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Working tree / draft related tasks."""
from datalad_service.common.celery import dataset_task


@dataset_task
def is_dirty(store, dataset):
"""Check if a dataset is dirty."""
ds = store.get_dataset(dataset)
return ds.repo.is_dirty()
18 changes: 18 additions & 0 deletions tests/test_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,21 @@ def test_add_commit_info(celery_app, client):
response_content = json.loads(response.content)
assert response_content['name'] == name
assert response_content['email'] == email


def test_is_dirty(celery_app, client, new_dataset):
ds_id = os.path.basename(new_dataset.path)
# Check if new_dataset is not dirty
response = client.simulate_get(
'/datasets/{}/draft'.format(ds_id))
assert response.status == falcon.HTTP_OK
assert json.loads(response.content)['partial'] == False
# Make the dataset dirty
response = client.simulate_post(
'/datasets/{}/files/NEW_FILE'.format(ds_id), body='some file data')
assert response.status == falcon.HTTP_OK
# Check if partial state is now true
response = client.simulate_get(
'/datasets/{}/draft'.format(ds_id))
assert response.status == falcon.HTTP_OK
assert json.loads(response.content)['partial'] == True

0 comments on commit ea4c4c3

Please sign in to comment.