<commit_before># -*- encoding: utf-8 -*-

# Dissemin: open access policy enforcement tool
# Copyright (C) 2014 <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#


from __future__ import unicode_literals

import unittest

from papers.orcid import OrcidProfile


class OrcidProfileTest(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.antonin = OrcidProfile(id='0000-0002-8612-8827')
        self.thomas = OrcidProfile(id='0000-0003-0524-631X')
        self.sergey = OrcidProfile(id='0000-0003-3397-9895')

    def test_simple_name(self):
        self.assertEqual(self.antonin.name, ('Antonin', 'Delpeuch'))
        self.assertEqual(self.thomas.name, ('Thomas', 'Bourgeat'))

    def test_credit_name(self):
        self.assertEqual(self.sergey.name, ('<NAME>.', 'Natanzon'))
        self.assertEqual(OrcidProfile(
            id='0000-0001-9547-293X').name, ('Darío', 'Álvarez'))

    def test_empty_lastname(self):
        self.assertEqual(OrcidProfile(
            id='0000-0001-5006-3868').name, ('Qiang', ''))

    def test_other_names(self):
        self.assertEqual(set(self.sergey.other_names),
                         set([('Sergey', 'Natanzon'), ('S.', 'Natanzon'),
                              ('<NAME>.', 'Natanzon'), ('Sergey', 'Natanzon')]))

    def test_homepage_without_http(self):
        self.assertEqual(OrcidProfile(
            id='0000-0002-5710-3989').homepage, 'http://evrard.perso.enseeiht.fr')

    def test_iterable(self):
        for key in self.thomas:
            self.assertEqual(type(key), unicode)

    def test_attr(self):
        self.assertTrue('orcid-profile' in self.thomas)
        self.assertEqual(type(self.thomas['orcid-profile']), dict)

    def test_wrong_instance(self):
        with self.assertRaises(ValueError):
            p = OrcidProfile()
            p.fetch('0000-0002-2963-7764', 'dissem.in')

    def test_sandbox(self):
        self.assertEqual(OrcidProfile(
            id='0000-0002-5654-4053').name, ('Peter', 'Lieth'))

    def test_search(self):
        results = list(OrcidProfile.search_by_name('John', 'Doe'))
        self.assertTrue(all(map(lambda x: len(x['orcid']) and (
            len(x['first']) or len(x['last'])), results)))
        names_returned = map(lambda x: (x['first'], x['last']), results)
        self.assertTrue(('John', 'Doe') in names_returned)

    def test_institution(self):
        self.assertEqual(OrcidProfile(
            id='0000-0002-0022-2290').institution,
            {'name':'<NAME>ale Superieure',
             'identifier':None,
             'country':'FR'})
        self.assertEqual(OrcidProfile(
            id='0000-0002-5654-4053').institution,
            {'country': 'FR',
             'identifier': None,
             'name': "Polytech'Rambouillet"})

<commit_msg>Fix ORCID search by name test (as we now search in the sandbox)<commit_after># -*- encoding: utf-8 -*-

# Dissemin: open access policy enforcement tool
# Copyright (C) 2014 <NAME>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#


from __future__ import unicode_literals

import unittest

from papers.orcid import OrcidProfile


class OrcidProfileTest(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.antonin = OrcidProfile(id='0000-0002-8612-8827')
        self.thomas = OrcidProfile(id='0000-0003-0524-631X')
        self.sergey = OrcidProfile(id='0000-0003-3397-9895')

    def test_simple_name(self):
        self.assertEqual(self.antonin.name, ('Antonin', 'Delpeuch'))
        self.assertEqual(self.thomas.name, ('Thomas', 'Bourgeat'))

    def test_credit_name(self):
        self.assertEqual(self.sergey.name, ('<NAME>.', 'Natanzon'))
        self.assertEqual(OrcidProfile(
            id='0000-0001-9547-293X').name, ('Darío', 'Álvarez'))

    def test_empty_lastname(self):
        self.assertEqual(OrcidProfile(
            id='0000-0001-5006-3868').name, ('Qiang', ''))

    def test_other_names(self):
        self.assertEqual(set(self.sergey.other_names),
                         set([('Sergey', 'Natanzon'), ('S.', 'Natanzon'),
                              ('<NAME>.', 'Natanzon'), ('Sergey', 'Natanzon')]))

    def test_homepage_without_http(self):
        self.assertEqual(OrcidProfile(
            id='0000-0002-5710-3989').homepage, 'http://evrard.perso.enseeiht.fr')

    def test_iterable(self):
        for key in self.thomas:
            self.assertEqual(type(key), unicode)

    def test_attr(self):
        self.assertTrue('orcid-profile' in self.thomas)
        self.assertEqual(type(self.thomas['orcid-profile']), dict)

    def test_wrong_instance(self):
        with self.assertRaises(ValueError):
            p = OrcidProfile()
            p.fetch('0000-0002-2963-7764', 'dissem.in')

    def test_sandbox(self):
        self.assertEqual(OrcidProfile(
            id='0000-0002-5654-4053').name, ('Peter', 'Lieth'))

    def test_search(self):
        results = list(OrcidProfile.search_by_name('Peter', 'Lieth'))
        self.assertTrue(all(map(lambda x: len(x['orcid']) and (
            len(x['first']) or len(x['last'])), results)))
        names_returned = map(lambda x: (x['first'], x['last']), results)
        self.assertTrue(('Peter', 'Lieth') in names_returned)

    def test_institution(self):
        self.assertEqual(OrcidProfile(
            id='0000-0002-0022-2290').institution,
            {'name':'<NAME>',
             'identifier':None,
             'country':'FR'})
        self.assertEqual(OrcidProfile(
            id='0000-0002-5654-4053').institution,
            {'country': 'FR',
             'identifier': None,
             'name': "Polytech'Rambouillet"})


{'fraction_non_alphanumeric': 0.13511972633979474, 'fraction_numerical': 0.049885974914481185, 'mean_word_length': 3.009714285714286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '191008', 'n_tokens_mistral': 2423, 'n_tokens_neox': 2141, 'n_words': 523}