From fc7dc5921d79ab84bfb13d32d308593f2fd9559e Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Thu, 31 May 2018 12:50:37 -0700 Subject: [PATCH 1/2] Add a test for getting the partial flag from datasets. --- tests/test_draft.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_draft.py b/tests/test_draft.py index 9cfa1d335..eb89854a1 100644 --- a/tests/test_draft.py +++ b/tests/test_draft.py @@ -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 From 489db59b8b69e159e870e84864a41ac522fcbb7e Mon Sep 17 00:00:00 2001 From: Nell Hardcastle Date: Thu, 31 May 2018 12:50:56 -0700 Subject: [PATCH 2/2] Implement partial flag on drafts. Returns true if the working tree contains files that are not committed. --- datalad_service/handlers/draft.py | 14 ++++++++++++++ datalad_service/tasks/__init__.py | 2 +- datalad_service/tasks/draft.py | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 datalad_service/tasks/draft.py diff --git a/datalad_service/handlers/draft.py b/datalad_service/handlers/draft.py index e1265315b..29703190b 100644 --- a/datalad_service/handlers/draft.py +++ b/datalad_service/handlers/draft.py @@ -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): @@ -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. diff --git a/datalad_service/tasks/__init__.py b/datalad_service/tasks/__init__.py index 8bd6823c7..3dd53b95b 100644 --- a/datalad_service/tasks/__init__.py +++ b/datalad_service/tasks/__init__.py @@ -1,2 +1,2 @@ """All Celery tasks and related functions.""" -__all__ = ['dataset', 'files', 'publish'] \ No newline at end of file +__all__ = ['dataset', 'draft', 'files', 'publish'] \ No newline at end of file diff --git a/datalad_service/tasks/draft.py b/datalad_service/tasks/draft.py new file mode 100644 index 000000000..d6216bd3a --- /dev/null +++ b/datalad_service/tasks/draft.py @@ -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()