Skip to content

Commit

Permalink
Merge pull request #244 from juliamcclellan/input_dataset
Browse files Browse the repository at this point in the history
Remove an input dataset from a project
  • Loading branch information
pcattori committed Aug 12, 2019
2 parents 0df543d + f1c747c commit 6f45c7b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.9.0-dev
**NEW FEATURES**
- [#218](https://github.com/Datatamer/unify-client-python/issues/218) Delete a `BaseResource`
- [#233](https://github.com/Datatamer/unify-client-python/issues/233) Remove an input dataset from a project

**BUG FIXES**
- [#235](https://github.com/Datatamer/unify-client-python/issues/235) Making `AttributeCollection` retrieve attributes directly instead of by streaming
Expand Down
14 changes: 14 additions & 0 deletions tamr_unify_client/project/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ def add_input_dataset(self, dataset):
).successful()
return response

def remove_input_dataset(self, dataset):
"""Remove a dataset from a project.
:param dataset: The dataset to be removed from this project.
:type dataset: :class:`~tamr_unify_client.dataset.resource.Dataset`
:return: HTTP response from the server
:rtype: :class:`requests.Response`
"""
params = {"id": dataset.relative_id}
response = self.client.delete(
self.api_path + "/inputDatasets", params=params
).successful()
return response

def input_datasets(self):
"""Retrieve a collection of this project's input datasets.
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ def test_project_add_input_dataset(self):
input_datasets = project.client.get(alias).successful().json()
self.assertEqual(self.dataset_json, input_datasets)

@responses.activate
def test_project_remove_input_dataset(self):
dataset_id = self.dataset_json[0]["relativeId"]

responses.add(responses.GET, self.input_datasets_url, json=self.dataset_json)
responses.add(
responses.DELETE, f"{self.input_datasets_url}?id={dataset_id}", status=204
)
responses.add(responses.GET, self.input_datasets_url, json=[])

project = Project(self.unify, self.project_json[0])
dataset = next(project.input_datasets().stream())

response = project.remove_input_dataset(dataset)
self.assertEqual(response.status_code, 204)

input_datasets = project.input_datasets()
self.assertEqual(list(input_datasets), [])

@responses.activate
def test_project_by_external_id__raises_when_not_found(self):
responses.add(responses.GET, self.projects_url, json=[])
Expand Down

0 comments on commit 6f45c7b

Please sign in to comment.