def get( self, fqid: str, mapped_fields: List[str] = [], get_deleted_models: DeletedModelsBehaviour = DeletedModelsBehaviour. NO_DELETED, ) -> Model: models = self.get_many([fqid], {fqid: mapped_fields}, get_deleted_models) try: return models[fqid] except KeyError: raise get_exception_for_deleted_models_behaviour( fqid, get_deleted_models)
def get( self, fqid: str, mapped_fields: List[str] = [], get_deleted_models: DeletedModelsBehaviour = DeletedModelsBehaviour. ALL_MODELS, ) -> Model: collection = collection_from_fqid(fqid) models = self.get_many([fqid], {collection: mapped_fields}, get_deleted_models) try: return models[fqid] except KeyError: raise get_exception_for_deleted_models_behaviour( fqid, get_deleted_models)
def get(self, request: GetRequest) -> Model: with self.database.get_context(): if request.position: # if a position is given, first test if the model is in the correct # state to prevent the unneccessary building of the model if it's not fqids = self.filter_fqids_by_deleted_status( [request.fqid], request.position, request.get_deleted_models) if not len(fqids): raise get_exception_for_deleted_models_behaviour( request.fqid, request.get_deleted_models) model = self.database.build_model_ignore_deleted( request.fqid, request.position) model = self.apply_mapped_fields(model, request.mapped_fields) else: model = self.database.get(request.fqid, request.mapped_fields, request.get_deleted_models) return model
def test_raise_exception_for_deleted_models_behaviour_only_deleted(): exception = get_exception_for_deleted_models_behaviour( MagicMock(), DeletedModelsBehaviour.ONLY_DELETED) assert type(exception) is ModelNotDeleted
def test_raise_exception_for_deleted_models_behaviour_no_deleted(): exception = get_exception_for_deleted_models_behaviour( MagicMock(), DeletedModelsBehaviour.NO_DELETED) assert type(exception) is ModelDoesNotExist
def test_raise_exception_for_deleted_models_behaviour_all_models(): exception = get_exception_for_deleted_models_behaviour( MagicMock(), DeletedModelsBehaviour.ALL_MODELS) assert type(exception) is ModelDoesNotExist