def _upsert(self, event, revisions, _filter): """Update and (if needed) create snapshots Args: event: A ggrc.models.Event instance revisions: A set of tuples of pairs with revisions to which it should either create or update a snapshot of that particular audit _filter: Callable that should return True if it should be updated Returns: OperationResponse """ for_create, for_update = self.analyze() create, update = None, None created, updated = set(), set() if for_update: update = self._update( for_update=for_update, event=event, revisions=revisions, _filter=_filter) updated = update.response if for_create: create = self._create(for_create=for_create, event=event, revisions=revisions, _filter=_filter) created = create.response to_reindex = updated | created if not self.dry_run: reindex_pairs(to_reindex) return OperationResponse("upsert", True, { "create": create, "update": update }, { "dry-run": self.dry_run })
def _upsert(self, event, revisions, _filter): """Update and (if needed) create snapshots Args: event: A ggrc.models.Event instance revisions: A set of tuples of pairs with revisions to which it should either create or update a snapshot of that particular audit _filter: Callable that should return True if it should be updated Returns: OperationResponse """ for_create, for_update = self.analyze() create, update = None, None created, updated = set(), set() if for_update: update = self._update( for_update=for_update, event=event, revisions=revisions, _filter=_filter) updated = update.response if for_create: create = self._create(for_create=for_create, event=event, revisions=revisions, _filter=_filter) created = create.response to_reindex = updated | created if not self.dry_run: reindex_pairs(to_reindex) self._copy_snapshot_relationships() return OperationResponse("upsert", True, { "create": create, "update": update }, { "dry-run": self.dry_run })
def update(self, event, revisions, _filter=None): """Update parent object's snapshots.""" _, for_update = self.analyze() result = self._update(for_update=for_update, event=event, revisions=revisions, _filter=_filter) updated = result.response if not self.dry_run: reindex_pairs(updated) return result
def update(self, event, revisions, _filter=None): """Update parent object's snapshots.""" _, for_update = self.analyze() result = self._update(for_update=for_update, event=event, revisions=revisions, _filter=_filter) updated = result.response if not self.dry_run: reindex_pairs(updated) self._copy_snapshot_relationships() return result
def create(self, event, revisions, _filter=None): """Create snapshots of parent object's neighborhood per provided rules and split in chuncks if there are too many snapshottable objects.""" for_create, _ = self.analyze() result = self._create( for_create=for_create, event=event, revisions=revisions, _filter=_filter) created = result.response if not self.dry_run: reindex_pairs(created) return result
def create(self, event, revisions, _filter=None): """Create snapshots of parent object's neighborhood per provided rules and split in chuncks if there are too many snapshottable objects.""" for_create, _ = self.analyze() result = self._create( for_create=for_create, event=event, revisions=revisions, _filter=_filter) created = result.response if not self.dry_run: reindex_pairs(created) self._copy_snapshot_relationships() return result
def test_reindex_pairs(self, external_model_factory): """Test reindex_pairs for same CADs in internal and external. Test that `reindex_pairs` functionality works correctly for snapshots when they have same CADs both in internal and external CAD tables but this CADs have titles in lower and upper case. """ with factories.single_commit(): audit = factories.AuditFactory() external_object = external_model_factory() self._create_int_and_ext_cads(external_object) self._create_snapshot_from_last_rev( parent=audit, child=external_object, ) try: snapshotter_indexer.reindex_pairs([ snapshotter_datastructures.Pair(audit, external_object), ]) except sa_exc.IntegrityError: self.fail("`reindex_pairs` failed due to IntegrityError")