def test_full_membership(): org = Organization.objects.create(id="fnd", name="Foundation", classification="foundation", jurisdiction_id="fnd-jid") hari = Person.objects.create(id="hs", name="Hari Seldon") robot = Person.objects.create(id="robot", name="R. Daneel Olivaw") post = Post.objects.create(id='f', label="founder", role="Founder", organization=org) # add a membership through a post m1 = ScrapeMembership(person_id=hari.id, organization_id=org.id, post_id=post.id) m1.add_contact_detail(type='phone', value='555-555-1234', note='this is fake') m1.add_link('http://example.com/link') # add a membership direct to an organization m2 = ScrapeMembership(person_id=robot.id, organization_id=org.id, label='member', role='member') dumb_imp = DumbMockImporter() memimp = MembershipImporter('fnd-jid', dumb_imp, dumb_imp, dumb_imp) memimp.import_data([m1.as_dict(), m2.as_dict()]) # ensure that the memberships attached in the right places assert org.memberships.count() == 2 assert hari.memberships.count() == 1 assert robot.memberships.count() == 1 assert post.memberships.count() == 1 # ensure that the first membership has contact details and links m = hari.memberships.get() cd = m.contact_details.get() assert cd.type == 'phone' assert cd.value == '555-555-1234' assert cd.note == 'this is fake' assert m.links.all()[0].url == 'http://example.com/link'
def test_full_membership(): create_jurisdiction() org = Organization.objects.create(id="fnd", name="Foundation", classification="foundation", jurisdiction_id="fnd-jid") hari = Person.objects.create(id="hs", name="Hari Seldon") robot = Person.objects.create(id="robot", name="R. Daneel Olivaw") post = Post.objects.create(id='f', label="founder", role="Founder", organization=org) # add a membership through a post m1 = ScrapeMembership(person_id=hari.id, organization_id=org.id, post_id=post.id) m1.add_contact_detail(type='phone', value='555-555-1234', note='this is fake') m1.add_link('http://example.com/link') # add a membership direct to an organization m2 = ScrapeMembership(person_id=robot.id, organization_id=org.id, label='member', role='member') dumb_imp = DumbMockImporter() memimp = MembershipImporter('fnd-jid', dumb_imp, dumb_imp, dumb_imp) memimp.import_data([m1.as_dict(), m2.as_dict()]) # ensure that the memberships attached in the right places assert org.memberships.count() == 2 assert hari.memberships.count() == 1 assert robot.memberships.count() == 1 assert post.memberships.count() == 1 # ensure that the first membership has contact details and links m = hari.memberships.get() cd = m.contact_details.get() assert cd.type == 'phone' assert cd.value == '555-555-1234' assert cd.note == 'this is fake' assert m.links.all()[0].url == 'http://example.com/link'
def test_full_membership(): create_jurisdiction() org = Organization.objects.create(id="fnd", name="Foundation", classification="foundation", jurisdiction_id="fnd-jid") hari = Person.objects.create(id="hs", name="Hari Seldon") robot = Person.objects.create(id="robot", name="R. Daneel Olivaw") post = Post.objects.create(id='f', label="founder", role="Founder", organization=org) # add a membership through a post, with a start date m1 = ScrapeMembership(person_id=hari.id, organization_id=org.id, post_id=post.id, start_date='2020-03-10', end_date='2021-06-30') m1.add_contact_detail(type='phone', value='555-555-1234', note='this is fake') m1.add_link('http://example.com/link') # add a membership direct to an organization, with an end date m2 = ScrapeMembership(person_id=robot.id, organization_id=org.id, label='member', role='member', end_date='2019-11-09') dumb_imp = DumbMockImporter() memimp = MembershipImporter('fnd-jid', dumb_imp, dumb_imp, dumb_imp) memimp.import_data([m1.as_dict(), m2.as_dict()]) # ensure that the memberships attached in the right places assert org.memberships.count() == 2 assert hari.memberships.count() == 1 assert robot.memberships.count() == 1 assert post.memberships.count() == 1 # ensure that the first membership has contact details and links m = hari.memberships.get() cd = m.contact_details.get() assert cd.type == 'phone' assert cd.value == '555-555-1234' assert cd.note == 'this is fake' assert m.links.all()[0].url == 'http://example.com/link' # update the imported memberships (i.e., change attributes that are not # in the spec) and confirm they resolve correctly memimp2 = MembershipImporter('fnd-jid', dumb_imp, dumb_imp, dumb_imp) m1.end_date = '2022-03-10' m2.extras = {'note': 'bleep blorp'} import_log = memimp2.import_data([m1.as_dict(), m2.as_dict()]) assert import_log['membership']['insert'] == 0 assert import_log['membership']['update'] == 2 # confirm the membership resolved based on start date and its end date was updated assert hari.memberships.count() == 1 assert hari.memberships.get().end_date == '2022-03-10' # confirm the membership resolved based on end date and its extras were updated assert robot.memberships.count() == 1 assert robot.memberships.get().extras == {'note': 'bleep blorp'}