# Path: processing/importaffiliation.py
# REGEX_ARTICLE = re.compile("^S[0-9]{4}-[0-9]{3}[0-9xX][0-2][0-9]{3}[0-9]{4}[0-9]{5}$")
# def _config_logging(logging_level='INFO', logging_file=None):
# def is_valid_pid(pid):
# def parse_csv_line(data):
# def is_clean_checked(parsed_line, original_article):
# def get_original_article(pid, collection):
# def isis_like_json(data):
# def import_doc_affiliations(data, normalized_affiliations):
# def check_affiliations(file_name='processing/normalized_affiliations.csv', import_data=False, encoding='utf-8'):
# def main():


import unittest
from processing import importaffiliation
        line = u'27136|scl|S0001-37652013000100001|2013|An. Acad. Bras. Ciênc.|v85n1|af1|Museu Nacional/UFJ|Brasil|Universidade Federal do Rio de Janeiro|Brazil|BR|São Paulo|SP'

        parsed_line = importaffiliation.parse_csv_line(line.split('|'))

        self.assertFalse(
            importaffiliation.is_clean_checked(parsed_line, self.mockarticle)
        )

    def test_is_clean_checked_false_record_without_affiliations(self):

        line = u'27136|scl|S0001-37652013000100001|2013|An. Acad. Bras. Ciênc.|v85n1|aff1|Museu Nacional/UFRJ|Brasil|Universidade Federal do Rio de Janeiro|Brazil|BR|São Paulo|SP'

        parsed_line = importaffiliation.parse_csv_line(line.split('|'))

        self.mockarticle.affiliations = None

        self.assertFalse(
            importaffiliation.is_clean_checked(parsed_line, self.mockarticle)
        )

    def test_is_like_json(self):

        line1 = u'27136|scl|S0001-37652013000100001|2013|An. Acad. Bras. Ciênc.|v85n1|aff1|Museu Nacional/UFRJ|Brasil|Universidade Federal do Rio de Janeiro|Brazil|BR|São Paulo|SP'
        line2 = u'27137|scl|S0001-37652013000100001|2013|An. Acad. Bras. Ciênc.|v85n1|aff2|Museu Nacional/UFRJ|Brasil|Universidade Federal do Rio de Janeiro|Brazil|BR|São Paulo|SP'

        data = [
            importaffiliation.parse_csv_line(line1.split('|')),
            importaffiliation.parse_csv_line(line2.split('|'))
        ]


# Path: processing/importaffiliation.py
# REGEX_ARTICLE = re.compile("^S[0-9]{4}-[0-9]{3}[0-9xX][0-2][0-9]{3}[0-9]{4}[0-9]{5}$")
# def _config_logging(logging_level='INFO', logging_file=None):
# def is_valid_pid(pid):
# def parse_csv_line(data):
# def is_clean_checked(parsed_line, original_article):
# def get_original_article(pid, collection):
# def isis_like_json(data):
# def import_doc_affiliations(data, normalized_affiliations):
# def check_affiliations(file_name='processing/normalized_affiliations.csv', import_data=False, encoding='utf-8'):
# def main():


# Path: tests/test_processing_importaff.py
import unittest
from processing import importaffiliation

        line = u'27136|scl|S0001-37652013000100001|2013|An. Acad. Bras. Ciênc.|v85n1|af1|Museu Nacional/UFJ|Brasil|Universidade Federal do Rio de Janeiro|Brazil|BR|São Paulo|SP'

        parsed_line = importaffiliation.parse_csv_line(line.split('|'))

        self.assertFalse(
            importaffiliation.is_clean_checked(parsed_line, self.mockarticle)
        )

    def test_is_clean_checked_false_record_without_affiliations(self):

        line = u'27136|scl|S0001-37652013000100001|2013|An. Acad. Bras. Ciênc.|v85n1|aff1|Museu Nacional/UFRJ|Brasil|Universidade Federal do Rio de Janeiro|Brazil|BR|São Paulo|SP'

        parsed_line = importaffiliation.parse_csv_line(line.split('|'))

        self.mockarticle.affiliations = None

        self.assertFalse(
            importaffiliation.is_clean_checked(parsed_line, self.mockarticle)
        )

    def test_is_like_json(self):

        line1 = u'27136|scl|S0001-37652013000100001|2013|An. Acad. Bras. Ciênc.|v85n1|aff1|Museu Nacional/UFRJ|Brasil|Universidade Federal do Rio de Janeiro|Brazil|BR|São Paulo|SP'
        line2 = u'27137|scl|S0001-37652013000100001|2013|An. Acad. Bras. Ciênc.|v85n1|aff2|Museu Nacional/UFRJ|Brasil|Universidade Federal do Rio de Janeiro|Brazil|BR|São Paulo|SP'

        data = [
            importaffiliation.parse_csv_line(line1.split('|')),
            importaffiliation.parse_csv_line(line2.split('|'))
        ]


        result = importaffiliation.isis_like_json(data)