def test_many_roles(self, db_session): people = PersonFactory.create_batch(4) roles = RoleFactory.create_batch(2) db_session.flush() people[0].roles.append(roles[0]) people[1].roles.append(roles[1]) people[3].roles.append(roles[1]) db_session.flush() p1 = Person.find_by_id(people[0].id, abort_404=False) p2 = Person.find_by_id(people[1].id, abort_404=False) p3 = Person.find_by_id(people[2].id, abort_404=False) p4 = Person.find_by_id(people[3].id, abort_404=False) r1 = Role.find_by_id(roles[0].id, abort_404=False) r2 = Role.find_by_id(roles[1].id, abort_404=False) assert r1 in p1.roles assert r2 in p2.roles assert r2 in p4.roles assert len(p3.roles) == 0 assert r1 not in p2.roles assert r1 not in p3.roles assert r1 not in p4.roles assert r2 not in p1.roles assert r2 not in p3.roles
def test_create(self, db_session): person_id = 1 proposal_type_id = 10 proposal_id = 15 proposal_type = ProposalTypeFactory(id=proposal_type_id) person = PersonFactory(id=person_id) proposal = ProposalFactory(id=proposal_id, type=proposal_type) db_session.flush() # give this sub to person person.proposals.append(proposal) db_session.flush() proposal_type = ProposalType.find_by_id(proposal_type_id) person = Person.find_by_id(person_id, abort_404=False) proposal = Proposal.find_by_id(proposal_id, abort_404=False) assert person is not None assert proposal_type is not None assert proposal is not None assert len(person.proposals) == 1 assert proposal.title == person.proposals[0].title # check references assert person.proposals[0].people[0] == person assert person.proposals[0].type.name == proposal_type.name # check the proposal relations assert proposal.type.name == proposal_type.name assert proposal.people[0] == person # perform and check delete db_session.delete(proposal) db_session.delete(proposal_type) db_session.delete(person) assert ProposalType.find_by_id(proposal_type_id) is None assert Person.find_by_id(person_id, abort_404=False) is None assert Proposal.find_by_id(proposal_id, abort_404=False) is None
def test_select_by_url(self, db_session): the_hash = "8" * 64 fred = PersonFactory.create(url_hash=the_hash) db_session.flush() selected = Person.find_by_url_hash(the_hash) # one element, a person assert type(selected) is Person # and it looks like fred assert selected == fred
def test_select_by_url(self, db_session): the_hash = "8"*64 fred = PersonFactory.create(url_hash=the_hash) db_session.flush() selected = Person.find_by_url_hash(the_hash) # one element, a person assert type(selected) is Person # and it looks like fred assert selected == fred
def test_map_person(self, db_session): """Test mapping persons to roles""" person = PersonFactory() role = RoleFactory() db_session.flush() person.roles.append(role) db_session.flush() person = Person.find_by_id(person.id, abort_404=False) role = Role.find_by_id(role.id, abort_404=False) assert role in person.roles assert person in role.people
def test_submit_another(self, app, db_session, smtplib): # created guy and proposal pers = CompletePersonFactory() prop = ProposalFactory(title='sub one', people=[pers]) type = ProposalTypeFactory() stat = ProposalStatusFactory(name='Pending Review') # Required by code trav = TravelAssistanceTypeFactory() accm = AccommodationAssistanceTypeFactory() audc = TargetAudienceFactory() db_session.commit() # now go to list, click on the submit another link, and do so do_login(app, pers) resp = app.get(url_for(controller='proposal', action='index')) assert prop.title in unicode(resp.body, 'utf-8') assert "You haven't submitted any proposals" not in unicode( resp.body, 'utf-8') resp = resp.click(description='New proposal') resp = resp.maybe_follow() f = resp.form f['proposal.title'] = 'sub two' f['proposal.type'] = str(type.id) f['proposal.abstract'] = "cubist" f['proposal.accommodation_assistance'] = str(accm.id) f['proposal.travel_assistance'] = str(trav.id) f['proposal.audience'] = str(audc.id) f['person.experience'] = "n" f['attachment'] = "foo" f['person.mobile'] = "NONE" f['person.bio'] = "Jim isn't real Dave, he never was" resp = f.submit() resp.status_code = 302 # Failure suggests form didn't submit cleanly pers_id = pers.id db_session.expunge_all() # does it exist? s2 = Proposal.find_by_title('sub two') assert len(s2) == 1 s2 = s2[0] assert Person.find_by_id( pers_id) in s2.people # Attached to correct person assert len(s2.attachments) == 1 # With attachment # Ensure that confirmation email was sent assert smtplib.existing is not None assert "Thank you for proposing" in smtplib.existing.message
def test_person_mapping(self, db_session): # person.registration should point to a single registration object r = RegistrationFactory() p = PersonFactory() db_session.flush() r.person = p db_session.flush() p = Person.find_by_id(p.id, abort_404=False) r = Registration.find_by_id(r.id, abort_404=False) # test that p is mapped to r properly assert p is not None assert r is not None assert r == p.registration assert p == r.person
def test_person_mapping(self, db_session): # person.registration should point to a single registration object r = RegistrationFactory() p = PersonFactory() db_session.flush() r.person = p db_session.flush() p = Person.find_by_id(p.id, abort_404 = False) r = Registration.find_by_id(r.id, abort_404 = False) # test that p is mapped to r properly assert p is not None assert r is not None assert r == p.registration assert p == r.person
def test_submit_another(self, app, db_session, smtplib): # created guy and proposal pers = CompletePersonFactory() prop = ProposalFactory(title='sub one', people=[pers]) type = ProposalTypeFactory() stat = ProposalStatusFactory(name = 'Pending Review') # Required by code trav = TravelAssistanceTypeFactory() accm = AccommodationAssistanceTypeFactory() audc = TargetAudienceFactory() db_session.commit() # now go to list, click on the submit another link, and do so do_login(app, pers) resp = app.get(url_for(controller='proposal', action='index')) assert prop.title in unicode(resp.body, 'utf-8') assert "You haven't submitted any proposals" not in unicode(resp.body, 'utf-8') resp = resp.click(description='New proposal') resp = resp.maybe_follow() f = resp.form f['proposal.title'] = 'sub two' f['proposal.type'] = str(type.id) f['proposal.abstract'] = "cubist" f['proposal.accommodation_assistance'] = str(accm.id) f['proposal.travel_assistance'] = str(trav.id) f['proposal.audience'] = str(audc.id) f['person.experience'] = "n" f['attachment'] = "foo" f['person.mobile'] = "NONE" f['person.bio'] = "Jim isn't real Dave, he never was" resp = f.submit() resp.status_code = 302 # Failure suggests form didn't submit cleanly pers_id = pers.id db_session.expunge_all() # does it exist? s2 = Proposal.find_by_title('sub two') assert len(s2) == 1 s2 = s2[0] assert Person.find_by_id(pers_id) in s2.people # Attached to correct person assert len(s2.attachments) == 1 # With attachment # Ensure that confirmation email was sent assert smtplib.existing is not None assert "Thank you for proposing" in smtplib.existing.message