def test_set_full_name(subschema):
    expected = {'full_name': 'Carberry, Josiah'}

    builder = SignatureBuilder()
    builder.set_full_name('Josiah Carberry')

    assert_field_valid(expected, builder.obj, 'full_name', subschema)
def test_curate(subschema):
    expected = {'curated_relation': True}

    builder = SignatureBuilder()
    builder.curate()

    assert_field_valid(expected, builder.obj, 'curated_relation', subschema)
def test_signature_builder(subschema):
    expected = {
        'full_name': 'Smith, John',
    }

    builder = SignatureBuilder()
    builder.set_full_name('Smith, John')
    result = builder.obj

    assert expected == result
    assert validate(result, subschema) is None
def test_add_raw_affiliation(subschema):
    expected = {
        'raw_affiliations': [
            {
                'value': 'Josiah Carberry',
                'source': 'source',
            },
        ],
    }

    builder = SignatureBuilder()
    builder.add_raw_affiliation('Josiah Carberry', 'source')

    assert_field_valid(expected, builder.obj, 'raw_affiliations', subschema)
def test_set_uid(subschema):
    expected = {
        'ids': [
            {
                'value': 'Josiah.Stinkney.Carberry.1',
                'schema': 'INSPIRE BAI',
            },
            {
                'value': '0000-0002-1825-0097',
                'schema': 'ORCID',
            },
            {
                'value': 'INSPIRE-12345678',
                'schema': 'INSPIRE ID',
            },
        ],
    }

    builder = SignatureBuilder()
    builder.set_uid('Josiah.Stinkney.Carberry.1')
    builder.set_uid('0000-0003-2635-0212')
    builder.set_uid('0000-0002-1825-0097')  # expect overwrite
    builder.set_uid('INSPIRE-12345678')

    assert_field_valid(expected, builder.obj, 'ids', subschema)
def test_add_affiliation(subschema):
    expected = {
        'affiliations': [
            {
                'value': 'Institution',
                'curated_relation': True,
                'record': {
                    '$ref': 'http://reference'
                },
            },
        ],
    }

    builder = SignatureBuilder()
    builder.add_affiliation('Institution', True, {'$ref': 'http://reference'})

    assert_field_valid(expected, builder.obj, 'affiliations', subschema)
def test_signature_builder_existing_author(subschema):
    existing = {
        'full_name': 'Smith, John',
    }
    expected = {
        'full_name': 'Smith, John',
        'emails': [
            '*****@*****.**',
        ],
        'ids': [
            {
                'value': '0000-0003-2635-0212',
                'schema': 'ORCID',
            },
        ],
    }

    builder = SignatureBuilder(existing)
    builder.add_email('*****@*****.**')
    builder.set_uid('0000-0003-2635-0212')
    result = builder.obj

    assert expected == result
    assert result is existing
    assert validate(result, subschema) is None
def test_add_inspire_role(subschema):
    expected = {'inspire_roles': ['supervisor', 'editor']}

    builder = SignatureBuilder()
    builder.add_inspire_role('supervisor')
    builder.add_inspire_role('editor')

    assert_field_valid(expected, builder.obj, 'inspire_roles', subschema)
def test_add_credit_role(subschema):
    expected = {'credit_roles': ['Conceptualization', 'Software']}

    builder = SignatureBuilder()
    builder.add_credit_role('Conceptualization')
    builder.add_credit_role('Software')

    assert_field_valid(expected, builder.obj, 'credit_roles', subschema)
def test_ensure_list_field():
    expected = {'created': ['new'], 'existing': ['old', 'new']}

    builder = SignatureBuilder({'existing': ['old']})
    builder._ensure_list_field('created', 'new')
    builder._ensure_list_field('existing', 'new')
    result = builder.obj

    assert expected == result
def test_public_method_ignores_none_params(field_name):
    builder = SignatureBuilder()
    field = getattr(builder, field_name)

    if not inspect.ismethod(field) or field_name.startswith('_'):
        return

    argc = len(inspect.getargspec(field).args) - 1

    if argc == 0:
        return

    argv = [None] * argc
    field(*argv)
    assert builder.obj == {}
def test_add_email(subschema):
    expected = {
        'emails': [
            '*****@*****.**',
            '*****@*****.**',
        ]
    }

    builder = SignatureBuilder()
    builder.add_email('*****@*****.**')
    builder.add_email('*****@*****.**')

    assert_field_valid(expected, builder.obj, 'emails', subschema)
def test_add_alternative_name(subschema):
    expected = {
        'alternative_names': [
            u'Petrovich Sidorov, Ivan',
            u'Петрович Сидоров, Иван',
        ]
    }

    builder = SignatureBuilder()
    builder.add_alternative_name(u'Petrovich Sidorov, Ivan')
    builder.add_alternative_name(u'Петрович Сидоров, Иван')

    assert_field_valid(expected, builder.obj, 'alternative_names', subschema)
Ejemplo n.º 14
0
    def make_author(self,
                    full_name,
                    affiliations=(),
                    roles=(),
                    raw_affiliations=(),
                    source=None,
                    ids=(),
                    emails=(),
                    alternative_names=(),
                    record=None):
        """Make a subrecord representing an author.

        Args:
            full_name(str): full name of the author. If not yet in standard
                Inspire form, it will be normalized.
            affiliations(List[str]): Inspire normalized affiliations of the
                author.
            roles(List[str]): Inspire roles of the author.
            raw_affiliations(List[str]): raw affiliation strings of the author.
            source(str): source for the affiliations when
                ``affiliations_normalized`` is ``False``.
            ids(List[Tuple[str,str]]): list of ids of the author, whose
                elements are of the form ``(schema, value)``.
            emails(List[str]): email addresses of the author.
            alternative_names(List[str]): alternative names of the author.
            record(dict): reference to the author record
        Returns:
            dict: a schema-compliant subrecord.
        """
        builder = SignatureBuilder()
        builder.set_full_name(full_name)
        builder.set_record(record)

        for affiliation in affiliations:
            builder.add_affiliation(affiliation)

        for role in roles:
            builder.add_inspire_role(role)

        for raw_affiliation in raw_affiliations:
            builder.add_raw_affiliation(raw_affiliation, source or self.source)

        for id_schema, id_value in ids:
            if id_schema and id_value:
                builder.set_uid(id_value, schema=id_schema)

        for email in emails:
            builder.add_email(email)

        for alternative_name in alternative_names:
            builder.add_alternative_name(alternative_name)

        return builder.obj