Esempio n. 1
0
def test_it_can_get_all_affiliations_including_restricted(yesterday):
    address = Address(countries.get('gb'), 'City')

    affiliation = Affiliation('1',
                              address=address,
                              organisation='Org',
                              starts=yesterday)
    affiliation2 = Affiliation('2',
                               address=address,
                               organisation='Org',
                               starts=yesterday,
                               restricted=True)
    affiliation3 = Affiliation('3',
                               address=address,
                               organisation='Org',
                               starts=yesterday)

    profile = Profile('12345678', Name('foo'), '0000-0002-1825-0097')

    profile.add_affiliation(affiliation, position=1)
    profile.add_affiliation(affiliation2, position=0)
    profile.add_affiliation(affiliation3, position=2)

    affiliations = profile.get_affiliations(include_restricted=True)

    assert len(affiliations) == 3
Esempio n. 2
0
def normalize_profile(profile: Profile) -> dict:
    data = normalize_profile_snippet(profile)
    data['emailAddresses'] = [
        normalize(email) for email in profile.get_email_addresses()
    ]
    data['affiliations'] = [
        normalize(aff) for aff in profile.get_affiliations()
    ]
    return data
Esempio n. 3
0
def test_it_can_get_all_affiliations_including_non_current(
        tomorrow, yesterday):
    address = Address(countries.get('gb'), 'City')

    affiliation1 = Affiliation('1',
                               address=address,
                               organisation='Org',
                               starts=yesterday)
    affiliation2 = Affiliation('2',
                               address=address,
                               organisation='Org',
                               starts=yesterday,
                               ends=tomorrow)
    affiliation3 = Affiliation('3',
                               address=address,
                               organisation='Org',
                               starts=tomorrow)
    affiliation4 = Affiliation('4',
                               address=address,
                               organisation='Org',
                               starts=yesterday,
                               ends=yesterday)

    profile = Profile('12345678', Name('foo'), '0000-0002-1825-0097')

    # current affiliations
    profile.add_affiliation(affiliation1)
    profile.add_affiliation(affiliation2)

    # future affiliation, should be returned when requesting 'all' affiliations
    profile.add_affiliation(affiliation3)

    # past affiliation, should be returned when requesting 'all' affiliations
    profile.add_affiliation(affiliation4)

    affiliations = profile.get_affiliations(current_only=False)

    assert len(affiliations) == 4
    assert affiliations[0] == affiliation4
    assert affiliations[1] == affiliation3
    assert affiliations[2] == affiliation2
    assert affiliations[3] == affiliation1
Esempio n. 4
0
def test_it_can_get_current_affiliations(tomorrow, yesterday):
    address = Address(countries.get('gb'), 'City')

    affiliation1 = Affiliation('1',
                               address=address,
                               organisation='Org',
                               starts=yesterday)
    affiliation2 = Affiliation('2',
                               address=address,
                               organisation='Org',
                               starts=yesterday,
                               ends=tomorrow)
    affiliation3 = Affiliation('3',
                               address=address,
                               organisation='Org',
                               starts=tomorrow)
    affiliation4 = Affiliation('4',
                               address=address,
                               organisation='Org',
                               starts=yesterday,
                               ends=yesterday)

    profile = Profile('12345678', Name('foo'), '0000-0002-1825-0097')

    # current affiliations
    profile.add_affiliation(affiliation1)
    profile.add_affiliation(affiliation2)

    # future affiliation, should not be returned with current affiliations
    profile.add_affiliation(affiliation3)

    # past affiliation, should not be returned with current affiliations
    profile.add_affiliation(affiliation4)

    affiliations = profile.get_affiliations()

    assert len(affiliations) == 2
    assert affiliations[0] == affiliation2
    assert affiliations[1] == affiliation1