# Path: td_biblio/forms.py
# def text_to_list(raw):
#     """Transform a raw text list to a python sorted object list
#     Supported separators: coma, space and carriage return
#     """
#     return sorted(
#         list(
#             set(
#                 id.strip()
#                 for r in map(methodcaller("split", ","), raw.split())
#                 for id in r
#                 if len(id)
#             )
#         )
#     )
# 
# class EntryBatchImportForm(forms.Form):
# 
#     pmids = forms.CharField(
#         label=_("PMID"),
#         widget=forms.Textarea(attrs={"placeholder": "ex: 26588162, 19569182"}),
#         help_text=_(
#             "Paste a list of PubMed Identifiers " "(comma separated or one per line)"
#         ),
#         required=False,
#     )
# 
#     dois = forms.CharField(
#         label=_("DOI"),
#         widget=forms.Textarea(
#             attrs={"placeholder": "ex: 10.1093/nar/gks419, 10.1093/nar/gkp323"}
#         ),
#         help_text=_(
#             "Paste a list of Digital Object Identifiers "
#             "(comma separated or one per line)"
#         ),
#         required=False,
#     )
# 
#     def clean_pmids(self):
#         """Transform raw data in a PMID list"""
#         pmids = text_to_list(self.cleaned_data["pmids"])
#         for pmid in pmids:
#             pmid_validator(pmid)
#         return pmids
# 
#     def clean_dois(self):
#         """Transform raw data in a DOI list"""
#         dois = text_to_list(self.cleaned_data["dois"])
#         for doi in dois:
#             doi_validator(doi)
#         return dois
# 
#     def clean(self):
#         super(EntryBatchImportForm, self).clean()
# 
#         dois = self.cleaned_data.get("dois", [])
#         pmids = self.cleaned_data.get("pmids", [])
# 
#         if not len(dois) and not len(pmids):
#             raise forms.ValidationError(
#                 _("You need to submit at least one valid DOI or PMID")
#             )


from django.test import TestCase
from ..forms import text_to_list, EntryBatchImportForm
            {"dois": "lorem, 19569182"},
            {"dois": "lorem42\nipsum234"},
        ]

        for input in inputs:
            form = EntryBatchImportForm(input)
            self.assertFalse(form.is_valid())

    def test_clean_with_pmids_and_dois(self):
        """Test clean method with DOIs & PMIDs"""

        data = {
            "dois": "10.1093/nar/gks419\n10.1093/nar/gkp323",
            "pmids": "26588162\n19569182",
        }

        expected = {
            "dois": ["10.1093/nar/gkp323", "10.1093/nar/gks419"],
            "pmids": ["19569182", "26588162"],
        }

        form = EntryBatchImportForm(data)
        self.assertTrue(form.is_valid())
        self.assertDictEqual(expected, form.cleaned_data)

    def test_clean_without_pmids_or_dois(self):
        """Test clean method without DOIs or PMIDs"""

        data = {"dois": "", "pmids": ""}


# Path: td_biblio/forms.py
# def text_to_list(raw):
#     """Transform a raw text list to a python sorted object list
#     Supported separators: coma, space and carriage return
#     """
#     return sorted(
#         list(
#             set(
#                 id.strip()
#                 for r in map(methodcaller("split", ","), raw.split())
#                 for id in r
#                 if len(id)
#             )
#         )
#     )
# 
# class EntryBatchImportForm(forms.Form):
# 
#     pmids = forms.CharField(
#         label=_("PMID"),
#         widget=forms.Textarea(attrs={"placeholder": "ex: 26588162, 19569182"}),
#         help_text=_(
#             "Paste a list of PubMed Identifiers " "(comma separated or one per line)"
#         ),
#         required=False,
#     )
# 
#     dois = forms.CharField(
#         label=_("DOI"),
#         widget=forms.Textarea(
#             attrs={"placeholder": "ex: 10.1093/nar/gks419, 10.1093/nar/gkp323"}
#         ),
#         help_text=_(
#             "Paste a list of Digital Object Identifiers "
#             "(comma separated or one per line)"
#         ),
#         required=False,
#     )
# 
#     def clean_pmids(self):
#         """Transform raw data in a PMID list"""
#         pmids = text_to_list(self.cleaned_data["pmids"])
#         for pmid in pmids:
#             pmid_validator(pmid)
#         return pmids
# 
#     def clean_dois(self):
#         """Transform raw data in a DOI list"""
#         dois = text_to_list(self.cleaned_data["dois"])
#         for doi in dois:
#             doi_validator(doi)
#         return dois
# 
#     def clean(self):
#         super(EntryBatchImportForm, self).clean()
# 
#         dois = self.cleaned_data.get("dois", [])
#         pmids = self.cleaned_data.get("pmids", [])
# 
#         if not len(dois) and not len(pmids):
#             raise forms.ValidationError(
#                 _("You need to submit at least one valid DOI or PMID")
#             )


# Path: td_biblio/tests/test_forms.py
from django.test import TestCase
from ..forms import text_to_list, EntryBatchImportForm

            {"dois": "lorem, 19569182"},
            {"dois": "lorem42\nipsum234"},
        ]

        for input in inputs:
            form = EntryBatchImportForm(input)
            self.assertFalse(form.is_valid())

    def test_clean_with_pmids_and_dois(self):
        """Test clean method with DOIs & PMIDs"""

        data = {
            "dois": "10.1093/nar/gks419\n10.1093/nar/gkp323",
            "pmids": "26588162\n19569182",
        }

        expected = {
            "dois": ["10.1093/nar/gkp323", "10.1093/nar/gks419"],
            "pmids": ["19569182", "26588162"],
        }

        form = EntryBatchImportForm(data)
        self.assertTrue(form.is_valid())
        self.assertDictEqual(expected, form.cleaned_data)

    def test_clean_without_pmids_or_dois(self):
        """Test clean method without DOIs or PMIDs"""

        data = {"dois": "", "pmids": ""}


        form = EntryBatchImportForm(data)