Skip to content

Commit

Permalink
Merge pull request #253 from Nelson-Andrade/delete-resource
Browse files Browse the repository at this point in the history
Delete resource from collection
  • Loading branch information
pcattori committed Aug 16, 2019
2 parents 3f0210d + 8aa927f commit 6cafaf7
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [#224](https://github.com/Datatamer/unify-client-python/issues/224) Project spec to update a project
- [#275](https://github.com/Datatamer/unify-client-python/issues/275) Create a category with a category spec
- [#273](https://github.com/Datatamer/unify-client-python/issues/273) Attribute type spec to allow for attribute creation
- [#219](https://github.com/Datatamer/tamr-client/issues/219) Delete a resource from collection.

**BUG FIXES**
- [#235](https://github.com/Datatamer/unify-client-python/issues/235) Making `AttributeCollection` retrieve attributes directly instead of by streaming
Expand Down
12 changes: 12 additions & 0 deletions tamr_unify_client/base_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ def by_external_id(self, resource_class, external_id):

return items[0]

def delete_by_resource_id(self, resource_id):
"""Deletes a resource from this collection by resource_id.
:param resource_id: the resource_id of the resource that will be deleted.
:type: str
:return: HTTP response from the server.
:rtype: :class: `requests.Response`
"""
path = f"{self.api_path}/{resource_id}"
response = self.client.delete(path).successful()
return response

def __repr__(self):
return (
f"{self.__class__.__module__}."
Expand Down
52 changes: 52 additions & 0 deletions tests/unit/test_attribute_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest
import responses

from tamr_unify_client import Client
from tamr_unify_client.auth import UsernamePasswordAuth


@pytest.fixture
def client():
auth = UsernamePasswordAuth("username", "password")
tamr = Client(auth)
return tamr


@responses.activate
def test_delete_by_resource_id(client):
ds_url = url_prefix + "datasets/7"
attr_url = ds_url + "/attributes/family_role"

responses.add(responses.GET, ds_url, json=datasets_collection[0])
responses.add(responses.DELETE, attr_url, status=204)

attributes = client.datasets.by_resource_id("7").attributes
response = attributes.delete_by_resource_id("family_role")
assert response.status_code == 204


url_prefix = "http://localhost:9100/api/versioned/v1/"

datasets_collection = [
{
"id": "unify://unified-data/v1/datasets/115",
"name": "Globex_Store_Customers",
"description": "",
"version": "659",
"keyAttributeNames": ["custid"],
"tags": [],
"created": {
"username": "admin",
"time": "2019-08-02T20:11:51.643Z",
"version": "23388",
},
"lastModified": {
"username": "admin",
"time": "2019-08-08T18:18:14.047Z",
"version": "26090",
},
"relativeId": "datasets/115",
"upstreamDatasetIds": [],
"externalId": "05d15bfd-d709-472a-ad5a-048e3367cfab",
}
]
16 changes: 16 additions & 0 deletions tests/unit/test_attribute_configuration_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ def test_stream(self):
stream_content.append(char._data)
self.assertEqual(self.acc_json, stream_content)

@responses.activate
def test_delete_by_resource_id(self):
attr_config_url = self._base + "projects/1/attributeConfigurations/20"

responses.add(responses.GET, self.mastering_project, json=self.project_json)
responses.add(responses.DELETE, attr_config_url, status=204)

attr_config_collection = self.tamr.projects.by_resource_id(
"1"
).attribute_configurations()
response = attr_config_collection.delete_by_resource_id("20")
self.assertEqual(response.status_code, 204)

_base = "http://localhost:9100/api/versioned/v1/"
mastering_project = _base + "projects/1"

create_json = {
"similarityFunction": "ABSOLUTE_DIFF",
"enabledForMl": False,
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test_base_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pytest
import responses

from tamr_unify_client import Client
from tamr_unify_client.auth import UsernamePasswordAuth


@pytest.fixture
def client():
auth = UsernamePasswordAuth("username", "password")
tamr = Client(auth)
return tamr


@responses.activate
def test_delete_by_resource_id(client):
ds_url = url_prefix + "datasets/115"

responses.add(responses.DELETE, ds_url, status=204)

response = client.datasets.delete_by_resource_id("115")
assert response.status_code == 204


url_prefix = "http://localhost:9100/api/versioned/v1/"
59 changes: 59 additions & 0 deletions tests/unit/test_category_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import pytest
import responses

from tamr_unify_client import Client
from tamr_unify_client.auth import UsernamePasswordAuth


@pytest.fixture
def client():
auth = UsernamePasswordAuth("username", "password")
tamr = Client(auth)
return tamr


@responses.activate
def test_delete_by_resource_id(client):
taxonomy_url = categorization_project + "/taxonomy"
category_url = taxonomy_url + "/categories/3"

responses.add(
responses.GET, categorization_project, json=categorization_project_config
)

responses.add(responses.GET, taxonomy_url, json=taxonomy)
responses.add(responses.DELETE, category_url, status=204)

category_collection = client.projects.by_resource_id("2").as_categorization()
response = category_collection.taxonomy().categories().delete_by_resource_id("3")
assert response.status_code == 204


url_prefix = "http://localhost:9100/api/versioned/v1/"
categorization_project = url_prefix + "projects/2"

categorization_project_config = {
"id": "unify://unified-data/v1/projects/2",
"name": "cat",
"description": "Categorization Project",
"type": "CATEGORIZATION",
"unifiedDatasetName": "",
"relativeId": "projects/2",
"externalId": "904bf89e-74ba-45c5-8b4a-5ff913728f66",
}

taxonomy = {
"id": "unify://unified-data/v1/projects/2/taxonomy",
"name": "tax",
"created": {
"username": "admin",
"time": "2019-07-12T13:09:14.981Z",
"version": "405",
},
"lastModified": {
"username": "admin",
"time": "2019-07-12T13:09:14.981Z",
"version": "405",
},
"relativeId": "projects/2/taxonomy",
}
64 changes: 64 additions & 0 deletions tests/unit/test_input_datasets_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest
import responses

from tamr_unify_client import Client
from tamr_unify_client.auth import UsernamePasswordAuth


@pytest.fixture
def client():
auth = UsernamePasswordAuth("username", "password")
tamr = Client(auth)
return tamr


@responses.activate
def test_delete_by_resource_id(client):
input_collection = url_prefix + "projects/1/inputDatasets"
input_ds = input_collection + "/6"

responses.add(responses.GET, mastering_project, json=mastering_project_config)

responses.add(responses.GET, input_collection, json=input_ds_json)
responses.add(responses.DELETE, input_ds, status=204)

input_ds_collection = client.projects.by_resource_id("1").input_datasets()
response = input_ds_collection.delete_by_resource_id("6")
assert response.status_code == 204


url_prefix = "http://localhost:9100/api/versioned/v1/"
mastering_project = url_prefix + "projects/1"

mastering_project_config = {
"name": "Project 1",
"description": "Mastering Project",
"type": "DEDUP",
"unifiedDatasetName": "Project 1 - Unified Dataset",
"externalId": "Project1",
"resourceId": "1",
}

input_ds_json = [
{
"id": "unify://unified-data/v1/datasets/6",
"name": "febrl_sample_2k.csv",
"description": "charlotte SM dataset",
"version": "5",
"keyAttributeNames": ["rec_id"],
"tags": [],
"created": {
"username": "admin",
"time": "2019-06-05T16:16:31.964Z",
"version": "35",
},
"lastModified": {
"username": "admin",
"time": "2019-07-19T17:44:42.369Z",
"version": "22919",
},
"relativeId": "datasets/6",
"upstreamDatasetIds": [],
"externalId": "febrl_sample_2k.csv",
}
]

0 comments on commit 6cafaf7

Please sign in to comment.