Skip to content

Commit

Permalink
Merge pull request #453 from skalish/test-cov
Browse files Browse the repository at this point in the history
Improve test coverage
  • Loading branch information
pcattori committed Sep 6, 2020
2 parents 63f0433 + b96af87 commit b55ba82
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 9 deletions.
2 changes: 0 additions & 2 deletions tamr_client/_types/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ class SubAttribute:
Args:
name: Name of sub-attribute
description: Description of sub-attribute
type: See https://docs.tamr.com/reference#attribute-types
is_nullable: If this sub-attribute can be null
"""

name: str
type: "AttributeType"
is_nullable: bool
description: Optional[str] = None


# attribute types
Expand Down
2 changes: 0 additions & 2 deletions tamr_client/attribute/sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ def to_json(subattr: SubAttribute) -> JsonDict:
"type": attribute_type.to_json(subattr.type),
"isNullable": subattr.is_nullable,
}
if subattr.description is not None:
d["description"] = subattr.description
return d
2 changes: 2 additions & 0 deletions tests/tamr_client/attribute/test_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ def test_create():
name="attr",
is_nullable=False,
type=tc.attribute.type.Record(attributes=attrs),
description="an attribute",
)

assert attr.name == "attr"
assert not attr.is_nullable
assert isinstance(attr.type, tc.attribute.type.Record)
assert attr.type.attributes == attrs
assert attr.description == "an attribute"


@fake.json
Expand Down
40 changes: 37 additions & 3 deletions tests/tamr_client/attribute/test_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

import tamr_client as tc
from tests.tamr_client import utils

Expand All @@ -13,14 +15,12 @@ def test_from_json():
assert subattr.name == "point"
assert subattr.type == tc.attribute.type.Array(tc.attribute.type.DOUBLE)
assert subattr.is_nullable
assert subattr.description is None
elif i == 1:
assert subattr.name == "lineString"
assert subattr.type == tc.attribute.type.Array(
tc.attribute.type.Array(tc.attribute.type.DOUBLE)
)
assert subattr.is_nullable
assert subattr.description is None
elif i == 2:
assert subattr.name == "polygon"
assert subattr.type == tc.attribute.type.Array(
Expand All @@ -29,7 +29,41 @@ def test_from_json():
)
)
assert subattr.is_nullable
assert subattr.description is None


def test_from_json_missing_base_type():
type_json: tc._types.JsonDict = {"attributes": []}

with pytest.raises(ValueError):
tc.attribute.type.from_json(type_json)


def test_from_json_unrecognized_base_type():
type_json: tc._types.JsonDict = {"baseType": "NOT_A_TYPE", "attributes": []}

with pytest.raises(ValueError):
tc.attribute.type.from_json(type_json)


def test_from_json_array_missing_inner_type():
type_json: tc._types.JsonDict = {"baseType": "ARRAY"}

with pytest.raises(ValueError):
tc.attribute.type.from_json(type_json)


def test_from_json_map_missing_inner_type():
type_json: tc._types.JsonDict = {"baseType": "MAP"}

with pytest.raises(ValueError):
tc.attribute.type.from_json(type_json)


def test_from_json_record_missing_attributes():
type_json: tc._types.JsonDict = {"baseType": "RECORD"}

with pytest.raises(ValueError):
tc.attribute.type.from_json(type_json)


def test_json():
Expand Down
18 changes: 18 additions & 0 deletions tests/tamr_client/categorization/test_categorization_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import tamr_client as tc
from tests.tamr_client import fake


@fake.json
def test_create():
s = fake.session()
instance = fake.instance()

project = tc.categorization.project.create(
s,
instance,
name="New Categorization Project",
description="A Categorization Project",
)
assert isinstance(project, tc.CategorizationProject)
assert project.name == "New Categorization Project"
assert project.description == "A Categorization Project"
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
}
}
]
}
},
"description": "an attribute"
}
},
"response": {
Expand Down Expand Up @@ -102,7 +103,8 @@
}
}
]
}
},
"description": "an attribute"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
{
"request": {
"method": "POST",
"path": "projects",
"json": {
"name": "New Categorization Project",
"type": "CATEGORIZATION",
"unifiedDatasetName": "New Categorization Project_unified_dataset",
"description": "A Categorization Project",
"externalId": null
}
},
"response": {
"status": 200,
"json": {
"id": "unify://unified-data/v1/projects/2",
"name": "New Categorization Project",
"description": "A Categorization Project",
"type": "CATEGORIZATION",
"unifiedDatasetName": "New Categorization Project_unified_dataset",
"created": {
"username": "admin",
"time": "2018-09-10T16:06:20.636Z",
"version": "created version"
},
"lastModified": {
"username": "admin",
"time": "2018-09-10T16:06:20.851Z",
"version": "modified version"
},
"relativeId": "projects/2",
"externalId": "b129f3b1-82f5-4e30-90a3-e562ca977992"
}
}
},
{
"request": {
"method": "GET",
"path": "projects/2"
},
"response": {
"status": 200,
"json": {
"id": "unify://unified-data/v1/projects/2",
"name": "New Categorization Project",
"description": "A Categorization Project",
"type": "CATEGORIZATION",
"unifiedDatasetName": "New Categorization Project_unified_dataset",
"created": {
"username": "admin",
"time": "2018-09-10T16:06:20.636Z",
"version": "created version"
},
"lastModified": {
"username": "admin",
"time": "2018-09-10T16:06:20.851Z",
"version": "modified version"
},
"relativeId": "projects/2",
"externalId": "b129f3b1-82f5-4e30-90a3-e562ca977992"
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
{
"request": {
"method": "POST",
"path": "projects",
"json": {
"name": "New Mastering Project",
"type": "DEDUP",
"unifiedDatasetName": "New Mastering Project_unified_dataset",
"description": "A Mastering Project",
"externalId": null
}
},
"response": {
"status": 200,
"json": {
"id": "unify://unified-data/v1/projects/1",
"name": "New Mastering Project",
"description": "A Mastering Project",
"type": "DEDUP",
"unifiedDatasetName": "New Mastering Project_unified_dataset",
"created": {
"username": "admin",
"time": "2018-09-10T16:06:20.636Z",
"version": "created version"
},
"lastModified": {
"username": "admin",
"time": "2018-09-10T16:06:20.851Z",
"version": "modified version"
},
"relativeId": "projects/1",
"externalId": "b129f3b1-82f5-4e30-90a3-e562ca977992"
}
}
},
{
"request": {
"method": "GET",
"path": "projects/1"
},
"response": {
"status": 200,
"json": {
"id": "unify://unified-data/v1/projects/1",
"name": "New Mastering Project",
"description": "A Mastering Project",
"type": "DEDUP",
"unifiedDatasetName": "New Mastering Project_unified_dataset",
"created": {
"username": "admin",
"time": "2018-09-10T16:06:20.636Z",
"version": "created version"
},
"lastModified": {
"username": "admin",
"time": "2018-09-10T16:06:20.851Z",
"version": "modified version"
},
"relativeId": "projects/1",
"externalId": "b129f3b1-82f5-4e30-90a3-e562ca977992"
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[
{
"request": {
"method": "POST",
"path": "projects",
"json": {
"name": "New Schema Mapping Project",
"type": "SCHEMA_MAPPING_RECOMMENDATIONS",
"unifiedDatasetName": "New Schema Mapping Project_unified_dataset",
"description": "A Schema Mapping Project",
"externalId": null
}
},
"response": {
"status": 200,
"json": {
"id": "unify://unified-data/v1/projects/3",
"name": "New Schema Mapping Project",
"description": "A Schema Mapping Project",
"type": "SCHEMA_MAPPING_RECOMMENDATIONS",
"unifiedDatasetName": "New Schema Mapping Project_unified_dataset",
"created": {
"username": "admin",
"time": "2018-09-10T16:06:20.636Z",
"version": "created version"
},
"lastModified": {
"username": "admin",
"time": "2018-09-10T16:06:20.851Z",
"version": "modified version"
},
"relativeId": "projects/3",
"externalId": "b129f3b1-82f5-4e30-90a3-e562ca977992"
}
}
},
{
"request": {
"method": "GET",
"path": "projects/3"
},
"response": {
"status": 200,
"json": {
"id": "unify://unified-data/v1/projects/3",
"name": "New Schema Mapping Project",
"description": "A Schema Mapping Project",
"type": "SCHEMA_MAPPING_RECOMMENDATIONS",
"unifiedDatasetName": "New Schema Mapping Project_unified_dataset",
"created": {
"username": "admin",
"time": "2018-09-10T16:06:20.636Z",
"version": "created version"
},
"lastModified": {
"username": "admin",
"time": "2018-09-10T16:06:20.851Z",
"version": "modified version"
},
"relativeId": "projects/3",
"externalId": "b129f3b1-82f5-4e30-90a3-e562ca977992"
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"request": {
"method": "POST",
"path": "projects",
"json": {
"name": "New Mastering Project",
"type": "DEDUP",
"unifiedDatasetName": "New Mastering Project_unified_dataset",
"description": "A Mastering Project",
"externalId": null
}
},
"response": {
"status": 409,
"json": {
"message": "Can't create project with the requested name 'New Mastering Project' because a project with that name already exists"
}
}
}
]
15 changes: 15 additions & 0 deletions tests/tamr_client/mastering/test_mastering_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import tamr_client as tc
from tests.tamr_client import fake


@fake.json
def test_create():
s = fake.session()
instance = fake.instance()

project = tc.mastering.project.create(
s, instance, name="New Mastering Project", description="A Mastering Project",
)
assert isinstance(project, tc.MasteringProject)
assert project.name == "New Mastering Project"
assert project.description == "A Mastering Project"
Empty file.
18 changes: 18 additions & 0 deletions tests/tamr_client/schema_mapping/test_schema_mapping_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import tamr_client as tc
from tests.tamr_client import fake


@fake.json
def test_create():
s = fake.session()
instance = fake.instance()

project = tc.schema_mapping.project.create(
s,
instance,
name="New Schema Mapping Project",
description="A Schema Mapping Project",
)
assert isinstance(project, tc.SchemaMappingProject)
assert project.name == "New Schema Mapping Project"
assert project.description == "A Schema Mapping Project"

0 comments on commit b55ba82

Please sign in to comment.