def update(self, entity: Entity, upsert=False) -> Entity:
     try:
         current = self.find_one(IdSpecification(entity.id))
     except ObjectNotFoundException:
         current = None
     if current or upsert:
         self.remove_one(IdSpecification(entity.id))
         return self.add(entity)
def test_find_with_specification(inmemory_repository, an_object):
    inmemory_repository.add(an_object)

    from fractal.core.specifications.id_specification import IdSpecification

    assert len(list(inmemory_repository.find(IdSpecification(
        an_object.id)))) == 1
def test_find_one(inmemory_repository, an_object):
    inmemory_repository.add(an_object)

    from fractal.core.specifications.id_specification import IdSpecification

    assert inmemory_repository.find_one(IdSpecification(
        an_object.id)) == an_object
def test_remove_one(inmemory_repository, an_object):
    inmemory_repository.add(an_object)

    from fractal.core.specifications.id_specification import IdSpecification

    inmemory_repository.remove_one(IdSpecification(an_object.id))

    assert len(inmemory_repository.entities) == 0
Exemple #5
0
def test_filter_specification(inmemory_filter_repository, an_object,
                              another_object):
    inmemory_filter_repository.add(an_object)
    inmemory_filter_repository.add(another_object)

    from fractal.core.specifications.id_specification import IdSpecification

    specification = IdSpecification("1")

    assert len(
        list(
            inmemory_filter_repository.find_filter(
                "_", fields=["name"], specification=specification))) == 1
Exemple #6
0
 def __update(self,
              entity: Entity,
              entity_dao_class: SqlAlchemyDao,
              *,
              upsert=False) -> Entity:
     """Recursive function"""
     with self:
         try:
             existing_entity_dao = self._find_one_raw(
                 IdSpecification(entity.id),
                 entity_dao_class=entity_dao_class)
         except ArgumentError:
             raise UnknownListItemTypeException(
                 f"DAO '{entity_dao_class}' has an unknown list collection DAO, please add the type for the list."
             )
         if existing_entity_dao:
             self.__update_existing_record(entity, entity_dao_class,
                                           existing_entity_dao)
             return entity
         elif upsert:
             return self.__add(entity, entity_dao_class)
 def __init__(self, object_id: Any, account_id: Any):
     self.specification = AndSpecification([
         AccountIdSpecification(account_id),
         IdSpecification(object_id),
     ])
def test_id_specification():
    spec = IdSpecification(1)
    DC = make_dataclass("DC", [("id", int)])
    assert spec.is_satisfied_by(DC(**dict(id=1)))