def test_update_attribute(self): def create_callback(request, snoop): snoop["payload"] = request.body return 200, {}, json.dumps(self._updated_attribute_json) relative_id = "dataset/1/attributes/RowNum" attribute_url = f"http://localhost:9100/api/versioned/v1/{relative_id}" snoop_dict = {} responses.add_callback(responses.PUT, attribute_url, partial(create_callback, snoop=snoop_dict)) attribute = Attribute(self.tamr, self._attributes_json[0], relative_id) temp_spec = attribute.spec() new_attribute = temp_spec.with_description( self._updated_attribute_json["description"]).put() self.assertEqual(new_attribute.name, self._updated_attribute_json["name"]) self.assertEqual(new_attribute.description, self._updated_attribute_json["description"]) self.assertEqual(json.loads(snoop_dict["payload"]), self._updated_attribute_json) self.assertEqual(attribute.name, self._attributes_json[0]["name"]) self.assertEqual(attribute.description, self._attributes_json[0]["description"]) # checking that intermediate didn't change self.assertEqual(temp_spec.to_dict()["description"], self._attributes_json[0]["description"])
def test_simple_type(self): alias = "datasets/1/attributes/RowNum" row_num = Attribute(self.tamr, self._attributes_json[0], alias) row_num_type = row_num.type expected = self._attributes_json[0]["type"]["baseType"] self.assertEqual(expected, row_num_type.base_type) self.assertIsNone(row_num_type.inner_type) self.assertSequenceEqual([], list(row_num_type.attributes))
def create(self, creation_spec): """ Create an Attribute in this collection :param creation_spec: Attribute creation specification should be formatted as specified in the `Public Docs for adding an Attribute <https://docs.tamr.com/reference#add-attributes>`_. :type creation_spec: dict[str, str] :returns: The created Attribute :rtype: :class:`~tamr_unify_client.attribute.resource.Attribute` """ data = self.client.post(self.api_path, json=creation_spec).successful().json() alias = self.api_path + "/" + creation_spec["name"] return Attribute.from_json(self.client, data, alias)
def test_complex_type(self): alias = "datasets/1/attributes/geom" geom = Attribute(self.tamr, self._attributes_json[1], alias) self.assertEqual("RECORD", geom.type.base_type) self.assertIsNone(geom.type.inner_type) self.assertEqual(3, len(list(geom.type.attributes))) point = geom.type.attributes[0] self.assertEqual("point", point.name) self.assertTrue(point.is_nullable) self.assertEqual("ARRAY", point.type.base_type) self.assertEqual("DOUBLE", point.type.inner_type.base_type) self.assertSequenceEqual([], list(point.type.attributes))
def test_resource(self): alias = "datasets/1/attributes/RowNum" row_num = Attribute(self.tamr, self._attributes_json[0], alias) expected = alias self.assertEqual(expected, row_num.relative_id) expected = self._attributes_json[0]["name"] self.assertEqual(expected, row_num.name) expected = self._attributes_json[0]["description"] self.assertEqual(expected, row_num.description) expected = self._attributes_json[0]["isNullable"] self.assertEqual(expected, row_num.is_nullable)
def stream(self): """Stream attributes in this collection. Implicitly called when iterating over this collection. :returns: Stream of attributes. :rtype: Python generator yielding :class:`~tamr_unify_client.attribute.resource.Attribute` Usage: >>> for attribute in collection.stream(): # explicit >>> do_stuff(attribute) >>> for attribute in collection: # implicit >>> do_stuff(attribute) """ data = self.client.get(self.api_path).successful().json() for resource_json in data: alias = self.api_path + "/" + resource_json["name"] yield Attribute.from_json(self.client, resource_json, alias)
def test_resource_from_json(self): alias = "datasets/1/attributes/RowNum" expected = Attribute(self.tamr, self._attributes_json[0], alias) actual = Attribute.from_json(self.tamr, self._attributes_json[0], alias) self.assertEqual(repr(expected), repr(actual))