def test_from_attributes(conn): """Test creation of a new attribute store from attributes.""" with closing(conn.cursor()) as cursor: datasource = DataSource.from_name(cursor, "integration-test") entitytype = EntityType.from_name(cursor, "UtranCell") attributes = [ Attribute("cntr1", "integer", "description for this attribute"), Attribute("cntr2", "integer", "description for this attribute")] attributestore = AttributeStore.from_attributes( cursor, datasource, entitytype, attributes) expected_table_name = "integration-test_UtranCell" eq_(attributestore.table_name(), expected_table_name) conn.commit() query = ( "SELECT attribute_directory.to_table_name(attributestore) " "FROM attribute_directory.attributestore " "WHERE id = %s") args = attributestore.id, cursor.execute(query, args) table_name, = cursor.fetchone() eq_(table_name, expected_table_name)
def store(self, datasource, entitytype, datapackage): attributes = [Attribute(name) for name in datapackage.attribute_names] with closing(self.conn.cursor()) as cursor: attributestore = AttributeStore.from_attributes( cursor, datasource, entitytype, attributes) self.conn.commit() attributestore.store_txn(datapackage).run(self.conn)
def store(self, datasource, entitytype, datapackage): attributes = datapackage.deduce_attributes() with closing(self.conn.cursor()) as cursor: attributestore = AttributeStore.from_attributes( cursor, datasource, entitytype, attributes) self.conn.commit() attributestore.store_txn(datapackage).run(self.conn)
def store(self, column_names, fields, raw_data_rows): rows = list(raw_data_rows) raw_datapackage = DataPackage(column_names, rows) attributes = raw_datapackage.deduce_attributes() entity_ref = EntityDnRef(rows[0][0]) with closing(self.conn.cursor()) as cursor: datasource = DataSource.from_name(cursor, self.datasource) entitytype = entity_ref.get_entitytype(cursor) attributestore = AttributeStore.from_attributes( cursor, datasource, entitytype, attributes) self.conn.commit() attributestore.store_raw(raw_datapackage).run(self.conn)
def store(self, column_names, fields, raw_data_rows): rows = list(raw_data_rows) raw_datapackage = DataPackage(column_names, rows) attributes = raw_datapackage.deduce_attributes() entity_ref = EntityDnRef(rows[0][0]) with closing(self.conn.cursor()) as cursor: datasource = DataSource.from_name(cursor, self.datasource) entitytype = entity_ref.get_entitytype(cursor) attributestore = AttributeStore.from_attributes( cursor, datasource, entitytype, attributes ) self.conn.commit() attributestore.store_raw(raw_datapackage).run(self.conn)
def test_store_txn_with_empty(conn): """Test transactional storing with empty value.""" with closing(conn.cursor()) as cursor: datasource = DataSource.from_name(cursor, "integration-test") entitytype = EntityType.from_name(cursor, "UtranCell") timestamp = pytz.utc.localize(datetime.utcnow()) datapackage = DataPackage( attribute_names=['freeText'], rows=[ (10023, timestamp, ('',)) ] ) attributes = datapackage.deduce_attributes() eq_(attributes[0].datatype, 'smallint') attributestore = AttributeStore.from_attributes( cursor, datasource, entitytype, attributes) conn.commit() attributestore.store_txn(datapackage).run(conn)