def test_rabbit_heavily_modify_coauthors():
     number_of_personids_before = get_count_of_pids()
     self.main_marcxml_record = get_modified_marc_for_test(
         self.main_marcxml_record,
         author_name=self.author_name,
         co_authors_names=self.heavily_mod_co_authors_names)
     self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                              opt_mode='replace')
     rabbit([self.main_bibrec], verbose=True)
     previous_bibref_value_of_author = self.current_bibref_value_of_author
     previous_bibrefs_of_coauthors = deepcopy(
         self.current_bibref_values_of_coauthors)
     for index, _ in enumerate(self.current_bibref_values_of_coauthors):
         self.current_bibref_values_of_coauthors[
             index] = get_bibref_value_for_name(
                 self.heavily_mod_co_authors_names[index])
     number_of_personids_after = get_count_of_pids()
     self.assertTrue(
         person_in_aidpersonidpapers(self.author_name,
                                     self.main_bibrec))
     self.assertEquals(previous_bibref_value_of_author,
                       self.current_bibref_value_of_author)
     self.assertNotEquals(set(previous_bibrefs_of_coauthors),
                          set(self.current_bibref_values_of_coauthors))
     self.assertEquals(number_of_personids_after,
                       number_of_personids_before)
     self.assertTrue(
         person_in_aidpersonidpapers(self.author_name,
                                     self.main_bibrec))
     self.assertTrue(person_in_aidpersoniddata(self.author_name))
     for coauthor_name in self.heavily_mod_co_authors_names:
         self.assertTrue(
             person_in_aidpersonidpapers(coauthor_name,
                                         self.main_bibrec))
         self.assertTrue(person_in_aidpersoniddata(coauthor_name))
        def test_rabbit_heavily_modify_author():
            '''
            The author's name is modified heavily. This means, that the modified string is significantly
            different than the original.. After the run of rabbit, the name in
            aidPERSONIDDATA SHOULD change, since this is a heavy modification.
            '''
            number_of_personids_before = get_count_of_pids()
            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record,
                author_name=self.heavily_modified_name)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')
            rabbit([self.main_bibrec], verbose=True)

            previous_bibref_value = self.current_bibref_value
            self.current_bibref_value = get_bibref_value_for_name(
                self.heavily_modified_name)
            number_of_personids_after = get_count_of_pids()
            self.assertNotEquals(previous_bibref_value,
                                 self.current_bibref_value)
            self.assertTrue(
                person_in_aidpersonidpapers(self.heavily_modified_name,
                                            self.main_bibrec))
            self.assertTrue(
                person_in_aidpersoniddata(self.heavily_modified_name))
            self.assertFalse(person_in_aidpersoniddata(self.author_name))
            self.assertFalse(
                person_in_aidpersonidpapers(self.slightly_modified_author_name,
                                            self.main_bibrec))
            self.assertEquals(number_of_personids_before,
                              number_of_personids_after)
        def test_rabbit_claim_record():
            '''
            The test record is artificially being claimed. Then, the name of the author is being modified:
                i) slightly
                A slight modification of a claimed record should have the same behavior as before:
                    Name changes in aidPERSONIDPAPERS but not in aidPERSONIDDATA.
                ii) heavily
                Due to the fact that the paper is claimed the canonical name should NOT change in aidPERSONIDDATA.
            '''
            number_of_personids_before = get_count_of_pids()
            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record, author_name=self.author_name)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')
            rabbit([self.main_bibrec], verbose=True)

            claim_test_paper(self.main_bibrec)

            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record,
                author_name=self.slightly_modified_author_name)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')
            rabbit([self.main_bibrec], verbose=True)

            number_of_personids_after = get_count_of_pids()
            self.assertEquals(number_of_personids_before,
                              number_of_personids_after)
            self.assertTrue(
                person_in_aidpersonidpapers(self.slightly_modified_author_name,
                                            self.main_bibrec))
            self.assertFalse(
                person_in_aidpersonidpapers(self.author_name,
                                            self.main_bibrec))
            self.assertTrue(is_test_paper_claimed(self.main_bibrec, 100))

            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record,
                author_name=self.heavily_modified_name)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')
            rabbit([self.main_bibrec], verbose=True)

            self.assertTrue(
                person_in_aidpersonidpapers(self.heavily_modified_name,
                                            self.main_bibrec))
            self.assertFalse(
                person_in_aidpersonidpapers(self.slightly_modified_author_name,
                                            self.main_bibrec))
            self.assertFalse(is_test_paper_claimed(self.main_bibrec, 100))
        def test_rabbit_claim_record():
            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record,
                author_name=self.author_name,
                co_authors_names=self.co_authors_names)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')
            rabbit([self.main_bibrec], verbose=True)
            claim_test_paper(self.main_bibrec)
            number_of_personids_before = get_count_of_pids()
            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record,
                author_name=self.author_name,
                co_authors_names=self.slightly_mod_co_authors_names)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')
            rabbit([self.main_bibrec], verbose=True)
            number_of_personids_after = get_count_of_pids()
            self.assertEquals(number_of_personids_before,
                              number_of_personids_after)
            self.assertTrue(is_test_paper_claimed(self.main_bibrec, 700))
            self.assertTrue(
                person_in_aidpersonidpapers(self.author_name,
                                            self.main_bibrec))
            self.assertTrue(person_in_aidpersoniddata(self.author_name))
            for coauthor_name in self.slightly_mod_co_authors_names:
                self.assertTrue(
                    person_in_aidpersonidpapers(coauthor_name,
                                                self.main_bibrec))
            for coauthor_name in self.co_authors_names:
                self.assertTrue(person_in_aidpersoniddata(coauthor_name))
            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record,
                author_name=self.author_name,
                co_authors_names=self.heavily_mod_co_authors_names)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')
            rabbit([self.main_bibrec], verbose=True)

            self.assertTrue(
                person_in_aidpersonidpapers(self.author_name,
                                            self.main_bibrec))
            self.assertTrue(person_in_aidpersoniddata(self.author_name))
            for coauthor_name in self.heavily_mod_co_authors_names:
                self.assertTrue(
                    person_in_aidpersonidpapers(coauthor_name,
                                                self.main_bibrec))
                self.assertTrue(person_in_aidpersoniddata(coauthor_name))
            self.assertFalse(is_test_paper_claimed(self.main_bibrec, 700))
        def test_rabbit_add_new_paper_with_four_coauthors():
            rabbit([self.main_bibrec], verbose=True)
            self.current_bibref_value_of_author = get_bibref_value_for_name(
                self.author_name)
            self.assertTrue(
                person_in_aidpersonidpapers(self.author_name,
                                            self.main_bibrec))
            self.assertTrue(person_in_aidpersoniddata(self.author_name))

            self.current_bdentifiers = [(
                self.ext_id,
                'i',
            )] + [None for i in range(len(self.co_authors_names))]
            self.current_bibref_values_of_coauthors = list()
            for coauthor_name in self.co_authors_names:
                bibref_value = get_bibref_value_for_name(coauthor_name)
                self.current_bibref_values_of_coauthors.append(bibref_value)
                self.assertTrue(
                    person_in_aidpersonidpapers(coauthor_name,
                                                self.main_bibrec))
                self.assertTrue(person_in_aidpersoniddata(coauthor_name))
        def test_rabbit_remove_coauthors_from_paper():

            number_of_personids_before = get_count_of_pids()
            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record, author_name=self.author_name)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')
            rabbit([self.main_bibrec], verbose=True)
            number_of_personids_after = get_count_of_pids()
            self.assertEquals(number_of_personids_before,
                              number_of_personids_after + 4)

            self.assertTrue(
                person_in_aidpersonidpapers(self.author_name,
                                            self.main_bibrec))
            self.assertTrue(person_in_aidpersoniddata(self.author_name))

            for coauthor_name in self.co_authors_names:
                self.assertFalse(
                    person_in_aidpersonidpapers(coauthor_name,
                                                self.main_bibrec))
                self.assertFalse(person_in_aidpersoniddata(coauthor_name))
 def test_rabbit_add_new_paper_with_one_author():
     '''
     Rabbit gets a record with a new author.
     Tests whether the author-related tables are populated with
     the author's name.
     '''
     rabbit([self.main_bibrec], verbose=True)
     self.current_bibref_value = get_bibref_value_for_name(
         self.author_name)  # saved for following tests
     self.assertTrue(
         person_in_aidpersonidpapers(self.author_name,
                                     self.main_bibrec))
     self.assertTrue(person_in_aidpersoniddata(self.author_name))
        def test_rabbit_remove_author_from_paper():
            '''
            The author field of the record is removed.
            Tests whether the author is actually removed by rabbit.
            '''
            number_of_personids_before = get_count_of_pids()
            self.main_marcxml_record = get_modified_marc_for_test(
                self.main_marcxml_record)
            self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                                     opt_mode='replace')

            rabbit([self.main_bibrec], verbose=True)
            number_of_personids_after = get_count_of_pids()
            self.assertEquals(number_of_personids_before,
                              number_of_personids_after + 1)
            self.assertFalse(
                person_in_aidpersonidpapers(self.author_name,
                                            self.main_bibrec))
            self.assertFalse(person_in_aidpersoniddata(self.author_name))
 def test_rabbit_add_author_again():
     '''
     The author field of the record is re-added.
     Tests whether the author is added again to aidPERSONIDPAPERS and aidPERSONIDDATA.
     '''
     number_of_personids_before = get_count_of_pids()
     self.main_marcxml_record = get_modified_marc_for_test(
         self.main_marcxml_record, author_name=self.author_name)
     self.main_bibrec = get_bibrec_for_record(self.main_marcxml_record,
                                              opt_mode='replace')
     rabbit([self.main_bibrec], verbose=True)
     previous_bibref_value = self.current_bibref_value
     self.current_bibref_value = get_bibref_value_for_name(
         self.author_name)
     number_of_personids_after = get_count_of_pids()
     self.assertEquals(previous_bibref_value, self.current_bibref_value)
     self.assertEquals(number_of_personids_after,
                       number_of_personids_before + 1)
     self.assertTrue(
         person_in_aidpersonidpapers(self.author_name,
                                     self.main_bibrec))
     self.assertTrue(person_in_aidpersoniddata(self.author_name))