def test_get_synonym_key(self): self.assertRaises(NoRecordFoundError, TaxonomyManager.get_synonym_key, 'Not existing') TaxonomyManager.register_synonym_key("test") TaxonomyManager.get_synonym_key("test") with Connector.get_connection() as connection: TaxonomyManager.get_synonym_key("test", bind=connection)
def update_data_provider(cls, current_name, *args, new_name=None, properties={}, synonym_key=None, return_object=True, **kwargs): if new_name is None: new_name = current_name m = "DataProvider(current_name='{}', new_name='{}', type_name='{}'," \ "properties='{}', synonym_key='{}'): updating data provider...'" LOGGER.debug( m.format(current_name, new_name, cls.get_type_name(), properties, synonym_key)) with Connector.get_connection() as connection: cls.assert_data_provider_exists(current_name, bind=connection) synonym_key_id = None if synonym_key is not None: synonym_key_id = TaxonomyManager.get_synonym_key( synonym_key, bind=connection)['id'] upd = niamoto_db_meta.data_provider.update().values({ 'name': new_name, 'properties': properties, 'synonym_key_id': synonym_key_id, 'date_update': datetime.now(), }).where(niamoto_db_meta.data_provider.c.name == current_name) connection.execute(upd) m = "DataProvider(current_name='{}', new_name='{}', type_name='{}'," \ " properties='{}', synonym_key='{}'): Data provider had been " \ "successfully updated!'" LOGGER.debug( m.format(current_name, new_name, cls.get_type_name(), properties, synonym_key)) if return_object: return cls(new_name, *args, **kwargs)
def register_data_provider(cls, name, *args, properties={}, synonym_key=None, return_object=True, **kwargs): m = "DataProvider(name='{}', type_name='{}', properties='{}', " \ "synonym_key='{}'): Registering data provider...'" LOGGER.debug( m.format(name, cls.get_type_name(), properties, synonym_key)) with Connector.get_connection() as connection: cls.assert_data_provider_does_not_exist(name, bind=connection) synonym_key_id = None if synonym_key is not None: synonym_key_id = TaxonomyManager.get_synonym_key( synonym_key, bind=connection)['id'] ins = niamoto_db_meta.data_provider.insert({ 'name': name, 'provider_type_key': cls.get_type_name(), 'properties': properties, 'synonym_key_id': synonym_key_id, 'date_create': datetime.now(), }) connection.execute(ins) m = "DataProvider(name='{}', type_name='{}', properties='{}', " \ "synonym_key='{}'): Data provider had been successfully" \ " registered!'" LOGGER.debug( m.format(name, cls.get_type_name(), properties, synonym_key)) if return_object: return cls(name, *args, **kwargs)