def test_invalid_operation(self):
        """ BibUpload Revision Verifier - Incorrect opt_mode parameter."""

        upload_recs = xml_marc_to_records(self.rev2_modified)
        orig_recs = xml_marc_to_records(self.data["rev3"][0])
        rev_verifier = RevisionVerifier()

        for item in ["append", "format", "insert", "delete", "reference"]:
            self.assertEqual(rev_verifier.verify_revision(upload_recs[0], orig_recs[0], item), None)
    def test_correcting_added_field_with_diff_ind(self):
        """ BibUpload Revision Verifier - Rev3-100/970__/888, Added 970CP in Rev2(100/970__), Patch Generated for 970CP"""
        upload_recs = xml_marc_to_records(self.rev2_mod_field_diff_ind)
        orig_recs = xml_marc_to_records(self.data["rev3"][0])

        rev_verifier = RevisionVerifier()
        (opt_mode, patch, dummy_affected_tags) = rev_verifier.verify_revision(upload_recs[0], orig_recs[0], "replace")
        self.assertEqual("correct", opt_mode)
        self.assertEqual(compare_xmbuffers(record_xml_output(patch), self.patch_diff_ind), "")
    def test_add_new_field(self):
        """ BibUpload Revision Verifier - Rev3-100/970/888, Added 300 to Rev2(100/970), Patch Generated for 300"""
        upload_recs = xml_marc_to_records(self.rev2_add_field)
        orig_recs = xml_marc_to_records(self.data["rev3"][0])

        rev_verifier = RevisionVerifier()
        (opt_mode, patch, dummy_affected_tags) = rev_verifier.verify_revision(upload_recs[0], orig_recs[0], "replace")
        self.assertEqual("correct", opt_mode)
        self.assertEqual(compare_xmbuffers(record_xml_output(patch), self.patch), "")
    def test_interchanged_fields(self):
        """ BibUpload Revision Verifier - Rev1--100-1/100-2/100-3/970/888, Rev1-Up--100-2/100-3/100-1/970/888, Patch Generated for 100"""

        upload_recs = xml_marc_to_records(self.rev1_mod)
        orig_recs = xml_marc_to_records(self.rev1)

        rev_verifier = RevisionVerifier()
        (opt_mode, patch, dummy_affected_tags) = rev_verifier.verify_revision(upload_recs[0], orig_recs[0], "replace")
        self.assertEqual("correct", opt_mode)
        self.assertEqual(compare_xmbuffers(record_xml_output(patch), self.patch), "")
    def test_for_special_delete_field(self):
        """ BibUpload Revision Verifier - Rev1-100/300, Modified 100 in Rev1-Mod, Deleted 300 in Rev1-Mod (100/300), Patch for DELETE generated"""
        upload_rec = xml_marc_to_records(self.rev1_mod)
        orig_rec = xml_marc_to_records(self.rev1)

        rev_verifier = RevisionVerifier()
        (opt_mode, final_patch, dummy_affected_tags) = rev_verifier.verify_revision(
            upload_rec[0], orig_rec[0], "replace"
        )
        self.assertEqual("correct", opt_mode)
        self.failUnless(
            (compare_xmbuffers(self.patch_1, record_xml_output(final_patch)) != "")
            or (compare_xmbuffers(self.patch_2, record_xml_output(final_patch)) != "")
        )
    def test_correcting_del_field_add_field_diff_ind(self):
        """ BibUpload Revision Verifier - Rev3-100/970__/888, Deleted 970__ and Added 970CP in Rev2(100/970__), Patch Generated for 970__/970CP"""
        upload_recs = xml_marc_to_records(self.rev2_mod_del_one_add_one)
        orig_recs = xml_marc_to_records(self.data["rev3"][0])

        rev_verifier = RevisionVerifier()
        (opt_mode, patch, dummy_affected_tags) = rev_verifier.verify_revision(upload_recs[0], orig_recs[0], "replace")
        self.assertEqual("correct", opt_mode)
        # NOTE:for multiple fields in patch it is better to compare with different possible patch strings
        # This is due to unsorted key-value pairs of generated patch dictionary
        # self.assertEqual(compare_xmbuffers(record_xml_output(patch), self.patch_del_one_add_one), '')
        self.failUnless(
            (compare_xmbuffers(record_xml_output(patch), self.patch_del_one_add_one) != "")
            or (compare_xmbuffers(record_xml_output(patch), self.patch_del_one_add_one_2) != "")
        )