Пример #1
0
def test_fill_missing_date_parts_adds_month_and_day():
    expected = "2019-01-01"
    result = fill_missing_date_parts("2019")

    assert expected == result
Пример #2
0
    def update_refs_in_citation_table(self, save_every=100):
        """Updates all references in citation table.
        First removes all references (where citer is this record),
        then adds all from the record again.
        Args:
            save_every (int): How often data should be saved into session.
            One by one is very inefficient, but so is 10000 at once.
        """
        RecordCitations.query.filter_by(citer_id=self.id).delete()
        if (self.is_superseded() or self.get("deleted")
                or self.pid_type not in ["lit"]
                or "Literature" not in self["_collections"]):
            # Record is not eligible to cite
            LOGGER.info(
                "Record's is not eligible to cite.",
                recid=self.get("control_number"),
                uuid=str(self.id),
            )
            return
        current_record_control_number = str(self.get("control_number"))
        records_pids = self.get_linked_pids_from_field("references.record")
        # Limit records to literature and data as only this types can be cited
        proper_records_pids = []
        allowed_types = ["lit", "dat"]
        for pid_type, pid_value in records_pids:
            if pid_type not in allowed_types:
                continue
            if pid_value == current_record_control_number:
                continue
            proper_records_pids.append((pid_type, pid_value))

        LOGGER.info(
            f"Record has {len(proper_records_pids)} linked references",
            recid=current_record_control_number,
            uuid=str(self.id),
        )
        records_uuids = self.get_records_ids_by_pids(proper_records_pids)
        referenced_records = set()
        references_waiting_for_commit = []
        citation_date = fill_missing_date_parts(self.earliest_date)
        for reference in records_uuids:
            if reference not in referenced_records:
                referenced_records.add(reference)
                references_waiting_for_commit.append(
                    RecordCitations(
                        citer_id=self.model.id,
                        cited_id=reference,
                        citation_date=citation_date,
                        is_self_citation=False,
                    ))
            if len(references_waiting_for_commit) >= save_every:
                db.session.bulk_save_objects(references_waiting_for_commit)
                references_waiting_for_commit = []
        if references_waiting_for_commit:
            db.session.bulk_save_objects(references_waiting_for_commit)

        if current_app.config.get("FEATURE_FLAG_ENABLE_SELF_CITATIONS"):
            LOGGER.info("Starting self citations check")
            self.update_self_citations()
        LOGGER.info(
            "Record citations updated",
            recid=current_record_control_number,
            uuid=str(self.id),
        )
Пример #3
0
def test_fill_missing_date_parts_adds_day():
    expected = "2019-06-01"
    result = fill_missing_date_parts("2019-06")

    assert expected == result