Exemple #1
0
    def test_identifiers_deleted_with_previous_cover(doc):
        """It should remove the cover_metadata because there are no ISBNs."""
        del doc["identifiers"]
        doc["cover_metadata"] = dict(ISBN="112344343")
        doc.commit()
        db.session.commit()

        pick_identifier_with_cover(app, record=doc)
        doc = Document.get_record_by_pid(doc["pid"])
        assert "cover_metadata" not in doc
Exemple #2
0
    def test_no_identifiers_no_previous_cover(doc):
        """It should not have cover_metadata because there are no ISBNs."""
        del doc["identifiers"]
        doc.pop("cover_metadata", "")  # delete if present
        doc.commit()
        db.session.commit()

        pick_identifier_with_cover(app, record=doc)
        doc = Document.get_record_by_pid(doc["pid"])
        assert "cover_metadata" not in doc
Exemple #3
0
    def test_with_identifiers_with_valid_cover(doc):
        """It should have the ISBN in cover_metadata."""
        # return cover is valid
        mocker.patch(
            "cds_ils.literature.tasks.is_valid_cover", return_value=True
        )

        doc["identifiers"] = [dict(scheme="ISBN", value="valid-isbn")]
        doc["cover_metadata"] = dict(ISBN="valid-isbn")
        doc.commit()
        db.session.commit()

        pick_identifier_with_cover(app, record=doc)
        doc = Document.get_record_by_pid(doc["pid"])
        assert doc["cover_metadata"] == dict(ISBN="valid-isbn")
Exemple #4
0
    def test_add_new_identifier(doc):
        """It should change the cover_metadata to the new identifier."""
        # return cover is not valid
        mocker.patch(
            "cds_ils.literature.tasks.is_valid_cover", return_value=True
        )

        # the ISBN has been changed to a not valid one
        doc["identifiers"] = [dict(scheme="ISBN", value="valid-isbn")]
        # it had a previously valid ISBN
        doc["cover_metadata"] = dict(ISBN="123456789")
        doc.commit()
        db.session.commit()

        pick_identifier_with_cover(app, record=doc)
        doc = Document.get_record_by_pid(doc["pid"])
        assert doc["cover_metadata"] == dict(ISBN="valid-isbn")
Exemple #5
0
    def test_with_invalid_identifiers_no_valid_cover(doc):
        """It should remove cover_metadata, the ISBN is not valid."""
        # return cover is not valid
        mocker.patch(
            "cds_ils.literature.tasks.is_valid_cover", return_value=False
        )

        # the ISBN has been changed to a not valid one
        doc["identifiers"] = [dict(scheme="ISBN", value="not-valid-isbn")]
        # it had a previously valid ISBN
        doc["cover_metadata"] = dict(ISBN="valid-isbn")
        doc.commit()
        db.session.commit()

        pick_identifier_with_cover(app, record=doc)
        doc = Document.get_record_by_pid(doc["pid"])
        assert "cover_metadata" not in doc