def test_get_emails_for_sending(self):
     all = contact_corresponding.get_isi_fields(test_isi_fake_data_file)
     assert_equals(len(all), 35)
     unique = contact_corresponding.get_unique_items(all)
     assert_equals(len(unique), 31)
     articles = contact_corresponding.get_filtered_dict(unique, lambda k, v: k == "type" and v == "Article")
     assert_equals(len(articles), 23)
     articles_of_months = contact_corresponding.get_filtered_dict(
         articles, lambda k, v: k == "data_month" and v in ["OCT", "NOV", "FAL"]
     )
     assert_equals(len(articles_of_months), 12)
     one_row_per_email = contact_corresponding.get_one_row_per_email(articles_of_months)
     assert_equals(len(one_row_per_email), 14)
     (first_occurrence, dupes) = contact_corresponding.email_first_occurrence(one_row_per_email, True)
     assert_equals(len(first_occurrence), 10)
     assert_equals(len(dupes), 4)
     (first_occurrence2, dupes2) = contact_corresponding.email_not_in_already_sent(first_occurrence, test_sent_file)
     assert_equals(len(first_occurrence2), 9)
     assert_equals(len(dupes2), 1)
     (first_occurrence3, dupes3) = contact_corresponding.filter_unsubscribe_list(first_occurrence2)
     assert_equals(len(first_occurrence3), 8)
     assert_equals(len(dupes3), 1)
     (first_occurrence4, dupes4) = contact_corresponding.filter_exclude_list(first_occurrence3, test_exclude_file)
     assert_equals(len(first_occurrence4), 6)
     assert_equals(len(dupes4), 2)
 def test_unique_emails_for_sending(self):
     all = contact_corresponding.get_isi_fields(test_isi_fake_data_file)
     assert_equals(len(all), 35)
     one_row_per_email = contact_corresponding.get_one_row_per_email(all)
     assert_equals(len(one_row_per_email), 38)
     (first_occurrence, dupes) = contact_corresponding.email_first_occurrence(one_row_per_email, True)
     assert_equals(len(first_occurrence), 27)
     assert_equals(len(dupes), 11)
     (first_occurrence2, dupes2) = contact_corresponding.email_not_in_already_sent(first_occurrence, test_sent_file)
     assert_equals(len(first_occurrence2), 24)
     assert_equals(len(dupes2), 3)
    def test_filter_research_articles(self):
        all = contact_corresponding.get_isi_fields(test_isi_fake_data_file)
        assert_equals(len(all), 35)
        all_types = [d["type"] for d in all]
        assert_equals(
            set(all_types),
            set(["Biographical-Item", "Review", "Letter", "Editorial Material", "Article", "Correction"]),
        )

        result = contact_corresponding.get_filtered_dict(all, lambda k, v: k == "type" and v == "Article")
        assert_equals(len(result), 24)
        result_types = [d["type"] for d in result]
        assert_equals(set(result_types), set(["Article"]))
    def test_filter_months(self):
        all = contact_corresponding.get_isi_fields(test_isi_fake_data_file)
        assert_equals(len(all), 35)
        all_months = [d["data_month"] for d in all]
        assert_equals(set(all_months), set(["NOV", "DEC"]))

        result = contact_corresponding.get_filtered_dict(
            all, lambda k, v: k == "data_month" and v in ["OCT", "NOV", "FAL"]
        )
        assert_equals(len(result), 14)
        result_months = [d["data_month"] for d in result]
        assert_equals(set(result_months), set(["NOV"]))

        result = contact_corresponding.get_filtered_dict(
            all, lambda k, v: k == "data_month" and v in ["NOV", "DEC", "FAL"]
        )
        assert_equals(len(result), 35)
        result_months = [d["data_month"] for d in result]
        assert_equals(set(result_months), set(["NOV", "DEC"]))
    def test_get_isi_fields(self):
        response = contact_corresponding.get_isi_fields(test_isi_data_file)
        assert_equals(len(response), get_wc_number_lines(test_isi_data_file) - 1)
        assert_equals(
            response[1:5],
            [
                {
                    "journal": "Evolution",
                    "volume_issue": "64_12",
                    "emails": ["*****@*****.**"],
                    "pretty_month": "DEC",
                    "year": "2010",
                    "type": "Article",
                    "data_month": "DEC",
                },
                {
                    "journal": "Evolution",
                    "volume_issue": "64_12",
                    "emails": ["*****@*****.**"],
                    "pretty_month": "DEC",
                    "year": "2010",
                    "type": "Article",
                    "data_month": "DEC",
                },
                {
                    "journal": "Evolution",
                    "volume_issue": "64_12",
                    "emails": ["*****@*****.**", "*****@*****.**", "*****@*****.**"],
                    "pretty_month": "DEC",
                    "year": "2010",
                    "type": "Article",
                    "data_month": "DEC",
                },
                {
                    "journal": "Evolution",
                    "volume_issue": "64_12",
                    "emails": ["*****@*****.**"],
                    "pretty_month": "DEC",
                    "year": "2010",
                    "type": "Article",
                    "data_month": "DEC",
                },
            ],
        )

        response = contact_corresponding.get_isi_fields(test_isi_data_file2)
        assert_equals(len(response), get_wc_number_lines(test_isi_data_file2) - 1)
        assert_equals(
            response[1:5],
            [
                {
                    "journal": "Am. Nat.",
                    "volume_issue": "176_6",
                    "emails": ["*****@*****.**"],
                    "pretty_month": "DEC",
                    "year": "2010",
                    "type": "Article",
                    "data_month": "DEC",
                },
                {
                    "journal": "Am. Nat.",
                    "volume_issue": "176_6",
                    "emails": ["*****@*****.**"],
                    "pretty_month": "DEC",
                    "year": "2010",
                    "type": "Article",
                    "data_month": "DEC",
                },
                {
                    "journal": "Am. Nat.",
                    "volume_issue": "176_6",
                    "emails": ["*****@*****.**"],
                    "pretty_month": "DEC",
                    "year": "2010",
                    "type": "Article",
                    "data_month": "DEC",
                },
                {
                    "journal": "Am. Nat.",
                    "volume_issue": "176_6",
                    "emails": ["*****@*****.**"],
                    "pretty_month": "DEC",
                    "year": "2010",
                    "type": "Article",
                    "data_month": "DEC",
                },
            ],
        )
 def test_get_one_row_per_email(self):
     all = contact_corresponding.get_isi_fields(test_isi_fake_data_file)
     assert_equals(len(all), 35)
     response = contact_corresponding.get_one_row_per_email(all)
     assert_equals(len(response), 38)
 def test_get_unique_items(self):
     all = contact_corresponding.get_isi_fields(test_isi_fake_data_file)
     assert_equals(len(all), 35)
     unique = contact_corresponding.get_unique_items(all)
     assert_equals(len(unique), 31)