예제 #1
0
def factory_entity_service(business_identifier='CP1234567',
                           business_number='791861073BC0001',
                           name='Foobar, Inc.'):
    """Produce a templated entity model."""
    entity = EntityModel.create_from_dict({
        'business_identifier': business_identifier,
        'business_number': business_number,
        'name': name
    })
    entity.save()
    entity_service = EntityService(entity)
    return entity_service
예제 #2
0
파일: entity.py 프로젝트: jeznorth/sbc-auth
    def save_entity(entity_info: dict):
        """Create/update an entity from the given dictionary."""
        if not entity_info:
            return None

        existing_entity = EntityModel.find_by_business_identifier(entity_info['businessIdentifier'])
        if existing_entity is None:
            entity_model = EntityModel.create_from_dict(entity_info)
        else:
            # TODO temporary allow update passcode, should replace with reset passcode endpoint.
            entity_info['passCode'] = passcode_hash(entity_info['passCode'])
            existing_entity.update_from_dict(**camelback2snake(entity_info))
            entity_model = existing_entity
            entity_model.commit()

        entity = Entity(entity_model)
        return entity
예제 #3
0
 def create_entity(entity_info: dict):
     """Create an Entity."""
     entity = EntityModel.create_from_dict(entity_info)
     entity.commit()
     return Entity(entity)