def test_by_name(): s = fake.session() instance = fake.instance() project = tc.project.by_name(s, instance, "proj") assert project.name == "proj" assert project.description == "Mastering Project"
def test_by_name(): s = fake.session() instance = fake.instance() dataset = tc.dataset.by_name(s, instance, "dataset 1 name") assert dataset.name == "dataset 1 name" assert dataset.description == "dataset 1 description" assert dataset.key_attribute_names == ("tamr_id",)
def test_from_resource_id(): s = fake.session() instance = fake.instance() dataset = tc.dataset.from_resource_id(s, instance, "1") assert dataset.name == "dataset 1 name" assert dataset.description == "dataset 1 description" assert dataset.key_attribute_names == ("tamr_id", )
def test_by_resource_id(): s = fake.session() instance = fake.instance() resource_id = "2020-08-17_21-32-10-961" tc.backup.by_resource_id(session=s, instance=instance, resource_id=resource_id)
def test_by_resource_id_categorization(): s = fake.session() instance = fake.instance() project = tc.project.by_resource_id(s, instance, "2") assert isinstance(project, tc.CategorizationProject) assert project.name == "Party Categorization" assert project.description == "Categorizes organization at the Party/Domestic level"
def test_create_no_primary_key(): s = fake.session() instance = fake.instance() df = pd.DataFrame(_records_with_keys_json_2) with pytest.raises(tc.primary_key.NotFound): tc.dataframe.create(s, instance, df, name="df_dataset")
def test_by_resource_id_mastering(): s = fake.session() instance = fake.instance() project = tc.project.by_resource_id(s, instance, "1") assert isinstance(project, tc.MasteringProject) assert project.name == "proj" assert project.description == "Mastering Project"
def test_manual_labels(): s = fake.session() instance = fake.instance() project = fake.categorization_project() tc.categorization.project.manual_labels(session=s, instance=instance, project=project)
def test_from_project_dataset_not_found(): s = fake.session() instance = fake.instance() project = fake.mastering_project() url = tc.URL(path="projects/1/unifiedDataset") responses.add(responses.GET, str(url), status=404) with pytest.raises(tc.dataset.unified.NotFound): tc.dataset.unified.from_project(s, instance, project)
def test_create_handle_record_failure(): s = fake.session() instance = fake.instance() df = pd.DataFrame(_records_with_keys_json_2) with pytest.raises(tc.dataframe.CreationFailure): tc.dataframe.create(s, instance, df, name="df_dataset", primary_key_name="primary_key")
def test_create_dataset_already_exists(): s = fake.session() instance = fake.instance() with pytest.raises(tc.dataset.AlreadyExists): tc.dataset.create( s, instance, name="new dataset", key_attribute_names=("primary_key",), description="a new dataset", )
def test_get_all_filter(): s = fake.session() instance = fake.instance() all_projects = tc.project.get_all( s, instance, filter="description==Categorization Project") assert len(all_projects) == 1 project = all_projects[0] assert isinstance(project, tc.CategorizationProject) assert project.name == "project 2" assert project.description == "Categorization Project"
def test_create_project_already_exists(): s = fake.session() instance = fake.instance() with pytest.raises(tc.project.AlreadyExists): tc.project._create( s, instance, name="New Mastering Project", project_type="DEDUP", description="A Mastering Project", )
def test_from_project(): s = fake.session() instance = fake.instance() project = fake.mastering_project() dataset_json = utils.load_json("dataset.json") url = tc.URL(path="projects/1/unifiedDataset") responses.add(responses.GET, str(url), json=dataset_json) unified_dataset = tc.dataset.unified.from_project(s, instance, project) assert unified_dataset.name == "dataset 1 name" assert unified_dataset.description == "dataset 1 description" assert unified_dataset.key_attribute_names == ("tamr_id", )
def test_create(): s = fake.session() instance = fake.instance() df = pd.DataFrame(_records_with_keys_json_2) dataset = tc.dataframe.create(s, instance, df, name="df_dataset", primary_key_name="primary_key") assert dataset.name == "df_dataset" assert dataset.key_attribute_names == ("primary_key", )
def test_create_infer_primary_key_from_index(): s = fake.session() instance = fake.instance() df = pd.DataFrame( _records_json_2, index=[record["primary_key"] for record in _records_with_keys_json_2], ) df.index.name = "primary_key" dataset = tc.dataframe.create(s, instance, df, name="df_dataset") assert dataset.name == "df_dataset" assert dataset.key_attribute_names == ("primary_key", )
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"
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"
def test_get_all_filter(): s = fake.session() instance = fake.instance() all_datasets = tc.dataset.get_all( s, instance, filter="description==dataset 2 description" ) assert len(all_datasets) == 1 dataset = all_datasets[0] assert dataset.name == "dataset 2 name" assert dataset.description == "dataset 2 description" assert dataset.key_attribute_names == ("tamr_id",)
def test_create(): s = fake.session() instance = fake.instance() dataset = tc.dataset.create( s, instance, name="new dataset", key_attribute_names=("primary_key",), description="a new dataset", ) assert dataset.name == "new dataset" assert dataset.description == "a new dataset" assert dataset.key_attribute_names == ("primary_key",)
def test_by_resource_id(): s = fake.session() instance = fake.instance() url = tc.URL(path="operations/1") operation_json = utils.load_json("operation_succeeded.json") responses.add(responses.GET, str(url), json=operation_json) resource_id = "1" op = tc.operation.by_resource_id(s, instance, resource_id) assert op.url == url assert op.type == operation_json["type"] assert op.description == operation_json["description"] assert op.status == operation_json["status"] assert tc.operation.succeeded(op)
def test_operation_from_response(): s = fake.session() instance = fake.instance() url = tc.URL(path="operations/1") operation_json = utils.load_json("operation_succeeded.json") responses.add(responses.GET, str(url), json=operation_json) r = s.get(str(url)) op = tc.operation._from_response(instance, r) assert op.url == url assert op.type == operation_json["type"] assert op.description == operation_json["description"] assert op.status == operation_json["status"] assert tc.operation.succeeded(op)
def test_get_all(): s = fake.session() instance = fake.instance() all_projects = tc.project.get_all(s, instance) assert len(all_projects) == 2 project_1 = all_projects[0] assert isinstance(project_1, tc.MasteringProject) assert project_1.name == "project 1" assert project_1.description == "Mastering Project" project_2 = all_projects[1] assert isinstance(project_2, tc.CategorizationProject) assert project_2.name == "project 2" assert project_2.description == "Categorization Project"
def test_get_all(): s = fake.session() instance = fake.instance() all_datasets = tc.dataset.get_all(s, instance) assert len(all_datasets) == 2 dataset_1 = all_datasets[0] assert dataset_1.name == "dataset 1 name" assert dataset_1.description == "dataset 1 description" assert dataset_1.key_attribute_names == ("tamr_id",) dataset_2 = all_datasets[1] assert dataset_2.name == "dataset 2 name" assert dataset_2.description == "dataset 2 description" assert dataset_2.key_attribute_names == ("tamr_id",)
def test_from_json_unrecognized_project_type(): instance = fake.instance() url = tc.URL("project/1", instance) data: tc._types.JsonDict = { "id": "unify://unified-data/v1/projects/1", "name": "project 1", "description": "A project of unknown type", "type": "UNKNOWN", "unifiedDatasetName": "", "relativeId": "projects/1", "externalId": "58bdbe72-3c08-427d-97bd-45b16d92c79c", } project = tc.project._from_json(url, data) assert isinstance(project, tc.UnknownProject) assert project.name == "project 1" assert project.description == "A project of unknown type"
def test_operation_from_response_noop(): s = fake.session() instance = fake.instance() url = tc.URL(path="operations/2") responses.add(responses.GET, str(url), status=204) url_dummy = tc.URL(path="operations/-1") responses.add(responses.GET, str(url_dummy), status=404) r = s.get(str(url)) op2 = tc.operation._from_response(instance, r) assert op2.url is not None assert op2.type == "NOOP" assert op2.description is not None assert op2.status is not None assert op2.status["state"] == "SUCCEEDED" assert tc.operation.succeeded(op2) op2w = tc.operation.wait(s, op2) assert tc.operation.succeeded(op2w) with pytest.raises(tc.operation.NotFound): tc.operation.poll(s, op2w)
def test_from_json_unrecognized_project_type(): instance = fake.instance() url = tc.URL("project/1", instance) data: tc._types.JsonDict = {"type": "NOT_A_PROJECT_TYPE"} with pytest.raises(ValueError): tc.project._from_json(url, data)
def test_by_name_project_ambiguous(): s = fake.session() instance = fake.instance() with pytest.raises(tc.project.Ambiguous): tc.project.by_name(s, instance, "ambiguous project")
def test_by_name_project_not_found(): s = fake.session() instance = fake.instance() with pytest.raises(tc.project.NotFound): tc.project.by_name(s, instance, "missing project")
def test_by_resource_id_not_found(): s = fake.session() instance = fake.instance() with pytest.raises(tc.project.NotFound): tc.project.by_resource_id(s, instance, "1")