def setUp(self): self.gsoc_program = seeder_logic.seed(GSoCProgram) self.gsoc_organization = seeder_logic.seed(GSoCOrganization, {'scope': self.gsoc_program}) slot_transfer_properties = {'program': self.gsoc_program, 'status': 'accepted'} organization_properties = {'scope': self.gsoc_program} self.org_entities = seeder_logic.seedn(GSoCOrganization, 10, organization_properties) #Assign one slot transfer entity to each of the organization in #self.org_entities self.slot_transfer_entities = [] properties = slot_transfer_properties.copy() for i in range(10): properties['parent'] = self.org_entities[i] entity = seeder_logic.seed(GSoCSlotTransfer, properties) self.slot_transfer_entities.append(entity) #Assign multiple slot transfer entities to self.gsoc_organization properties = slot_transfer_properties.copy() properties.update({'parent': self.gsoc_organization}) self.gsoc_organization_slot_transfer_entities = seeder_logic.seedn( GSoCSlotTransfer, 5, properties)
def setUp(self): self.program = seeder_logic.seed(GSoCProgram) #An organization which has all its slots allocated. org_properties = {'scope':self.program, 'slots': 2} self.foo_organization = seeder_logic.seed(GSoCOrganization, org_properties) proposal_properties = {'program': self.program, 'org': self.foo_organization, 'mentor': None, 'status': 'accepted'} self.foo_proposals = seeder_logic.seedn(GSoCProposal, 2, proposal_properties) #Create organization which has slots to be allocated. We create both #rejected and accepted proposals for this organization entity. org_properties = {'scope':self.program, 'slots': 5} self.bar_organization = seeder_logic.seed(GSoCOrganization, org_properties) #Create some already accepted proposals for bar_organization. proposal_properties = {'program': self.program, 'org': self.bar_organization, 'mentor': None, 'status': 'accepted'} self.bar_accepted_proposals = seeder_logic.seedn(GSoCProposal, 2, proposal_properties) #proposals which are yet to be accepted. proposal_properties = {'status': 'pending', 'accept_as_project': True, 'has_mentor': True, 'program': self.program, 'org': self.bar_organization} self.bar_to_be_accepted_proposals = seeder_logic.seedn(GSoCProposal, 3, proposal_properties) #proposals which were rejected. proposal_properties = {'status': 'pending', 'accept_as_project': False, 'has_mentor': False, 'program': self.program, 'org': self.bar_organization} self.bar_rejected_proposals = seeder_logic.seedn(GSoCProposal, 2, proposal_properties) #Create an organization for which the accepted proposals are more than #the available slots. org_properties = {'scope': self.program, 'slots': 1} self.happy_organization = seeder_logic.seed(GSoCOrganization, org_properties) proposal_properties = {'status': 'pending', 'accept_as_project': True, 'has_mentor': True, 'program': self.program, 'org': self.happy_organization} self.happy_accepted_proposals = [] proposal_properties['score'] = 2 self.happy_accepted_proposals.append(seeder_logic.seed(GSoCProposal, proposal_properties)) proposal_properties['score'] = 5 self.happy_accepted_proposals.append(seeder_logic.seed(GSoCProposal, proposal_properties))
def seedn(self, model, properties, n, auto_seed_optional_properties=True): return seeder_logic.seedn( model, n, properties, recurse=False, auto_seed_optional_properties=auto_seed_optional_properties)
def setUp(self): from soc.modules.gsoc.models.student_project import StudentProject self.init() properties = {'scope': self.org, 'program': self.gsoc} self.student_projects = seeder_logic.seedn(StudentProject, 2, properties)
def setUp(self): self.program = program_utils.seedGSoCProgram() self.organization = org_utils.seedSOCOrganization(self.program.key()) slot_transfer_properties = {'program': self.program, 'status': 'accepted'} self.org_entities = [ org_utils.seedSOCOrganization(self.program.key()) for _ in range(NUMBER_OF_ORGS)] #Assign one slot transfer entity to each of the organization in #self.org_entities self.slot_transfer_entities = [] properties = slot_transfer_properties.copy() for i in range(10): properties['parent'] = self.org_entities[i].key.to_old_key() entity = seeder_logic.seed(GSoCSlotTransfer, properties) self.slot_transfer_entities.append(entity) #Assign multiple slot transfer entities to self.organization properties = slot_transfer_properties.copy() properties.update({'parent': self.organization.key.to_old_key()}) self.gsoc_organization_slot_transfer_entities = seeder_logic.seedn( GSoCSlotTransfer, 5, properties)
def setUp(self): self.program = program_utils.seedGSoCProgram() self.organization = org_utils.seedSOCOrganization(self.program.key()) slot_transfer_properties = { 'program': self.program, 'status': 'accepted' } self.org_entities = [ org_utils.seedSOCOrganization(self.program.key()) for _ in range(NUMBER_OF_ORGS) ] #Assign one slot transfer entity to each of the organization in #self.org_entities self.slot_transfer_entities = [] properties = slot_transfer_properties.copy() for i in range(10): properties['parent'] = self.org_entities[i].key.to_old_key() entity = seeder_logic.seed(GSoCSlotTransfer, properties) self.slot_transfer_entities.append(entity) #Assign multiple slot transfer entities to self.organization properties = slot_transfer_properties.copy() properties.update({'parent': self.organization.key.to_old_key()}) self.gsoc_organization_slot_transfer_entities = seeder_logic.seedn( GSoCSlotTransfer, 5, properties)
def testSeedn(self): """Tests the seedn method. """ from soc.models.student import Student # Test seeding multiple data and generating all properties randomly n = 3 students = seeder_logic.seedn(Student, n) self.assertEqual(len(students), n) self.assertTrue(all(students))
def testQueryAllMentorKeysForOrg(self): """Tests if a list of keys of all the mentors for an organization is returned. """ #Since there are no mentors assigned to foo_org or bar_org, an empty list #should be returned. expected_keys = [] actual_keys = profile_logic.queryAllMentorsKeysForOrg(self.foo_org) self.assertEqual(expected_keys, actual_keys) actual_keys = profile_logic.queryAllMentorsKeysForOrg(self.bar_org) self.assertEqual(expected_keys, actual_keys) mentor_properties = { 'mentor_for': [self.foo_org.key()], 'is_mentor': True } foo_mentors = seeder_logic.seedn(GCIProfile, 5, mentor_properties) org_admin_properties = { 'org_admin_for': [self.foo_org.key()], 'mentor_for': [self.foo_org.key()], 'is_mentor': True, 'is_org_admin': True } foo_org_admin = seeder_logic.seed(GCIProfile, org_admin_properties) mentor_properties['mentor_for'] = [self.bar_org.key()] bar_mentors = seeder_logic.seedn(GCIProfile, 5, mentor_properties) org_admin_properties['org_admin_for'] = [self.bar_org.key()] org_admin_properties['mentor_for'] = [self.bar_org.key()] bar_org_admin = seeder_logic.seed(GCIProfile, org_admin_properties) expected = [mentor.key() for mentor in foo_mentors] + [foo_org_admin.key()] actual = profile_logic.queryAllMentorsKeysForOrg(self.foo_org) self.assertEqual(expected, actual) expected = [mentor.key() for mentor in bar_mentors] + [bar_org_admin.key()] actual = profile_logic.queryAllMentorsKeysForOrg(self.bar_org) self.assertEqual(expected, actual)
def testQueryAllMentorKeysForOrg(self): """Tests if a list of keys of all the mentors for an organization is returned. """ #Since there are no mentors assigned to foo_org or bar_org, an empty list #should be returned. expected_keys = [] actual_keys = profile_logic.queryAllMentorsKeysForOrg(self.foo_org) self.assertEqual(expected_keys, actual_keys) actual_keys = profile_logic.queryAllMentorsKeysForOrg(self.bar_org) self.assertEqual(expected_keys,actual_keys) mentor_properties = {'mentor_for': [self.foo_org.key()], 'is_mentor': True} foo_mentors = seeder_logic.seedn(GCIProfile, 5, mentor_properties) org_admin_properties = {'org_admin_for': [self.foo_org.key()], 'mentor_for': [self.foo_org.key()], 'is_mentor': True, 'is_org_admin': True} foo_org_admin = seeder_logic.seed(GCIProfile, org_admin_properties) mentor_properties['mentor_for'] = [self.bar_org.key()] bar_mentors = seeder_logic.seedn(GCIProfile, 5, mentor_properties) org_admin_properties['org_admin_for'] = [self.bar_org.key()] org_admin_properties['mentor_for'] = [self.bar_org.key()] bar_org_admin = seeder_logic.seed(GCIProfile, org_admin_properties) expected = [mentor.key() for mentor in foo_mentors] + [foo_org_admin.key()] actual = profile_logic.queryAllMentorsKeysForOrg(self.foo_org) self.assertEqual(expected, actual) expected = [mentor.key() for mentor in bar_mentors] + [bar_org_admin.key()] actual = profile_logic.queryAllMentorsKeysForOrg(self.bar_org) self.assertEqual(expected, actual)
def seedn(self, model, properties, n, auto_seed_optional_properties=True): return seeder_logic.seedn(model, n, properties, recurse=False, auto_seed_optional_properties=auto_seed_optional_properties)
def testSeedAGSoCProgram(self): """Tests seeding a GSoC program using both seedn and seed methods. """ import random from soc.modules.gsoc.models.mentor import GSoCMentor from soc.modules.gsoc.models.org_admin import GSoCOrgAdmin from soc.modules.gsoc.models.organization import GSoCOrganization from soc.modules.gsoc.models.program import GSoCProgram from soc.modules.gsoc.models.student import GSoCStudent from soc.modules.gsoc.models.student_proposal import StudentProposal # Seed 'GSoC2011' properties = { 'name': 'Google Summer of Code 2011', 'short_name': 'GSoC2011' } gsoc2011 = seeder_logic.seed(GSoCProgram, properties=properties) # Seed num_gsoc_orgs GSoC orgs num_gsoc_orgs = 10 properties = {'scope': gsoc2011} gsoc_orgs = seeder_logic.seedn(GSoCOrganization, num_gsoc_orgs, properties) self.assertEqual(len(gsoc_orgs), num_gsoc_orgs) self.assertTrue(all(gsoc_orgs)) # Seed IntegerUniformDistribution(min_num_gsoc_org_admins, # max_num_gsoc_org_admins) admins and IntegerUniformDistribution( # min_num_gsoc_org_mentors, max_num_gsoc_org_mentors) mentors for GSoC orgs min_num_gsoc_org_admins = 1 max_num_gsoc_org_admins = 5 min_num_gsoc_org_mentors = 0 max_num_gsoc_org_mentors = 10 for gsoc_org in gsoc_orgs: properties = {'scope': gsoc_org, 'program': gsoc2011} num_gsoc_org_admins = random.randint(min_num_gsoc_org_admins, max_num_gsoc_org_admins) gsoc_org_admins = seeder_logic.seedn(GSoCOrgAdmin, num_gsoc_org_admins, properties) self.assertEqual(len(gsoc_org_admins), num_gsoc_org_admins) self.assertTrue(all(gsoc_org_admins)) num_gsoc_org_mentors = random.randint(min_num_gsoc_org_mentors, max_num_gsoc_org_mentors) gsoc_org_mentors = seeder_logic.seedn(GSoCMentor, num_gsoc_org_mentors, properties) self.assertEqual(len(gsoc_org_mentors), num_gsoc_org_mentors) self.assertTrue(all(gsoc_org_mentors)) # Seed num_gsoc_students GSoC students num_gsoc_students = 20 properties = {'scope': gsoc2011} gsoc_students = seeder_logic.seedn(GSoCStudent, num_gsoc_students, properties) self.assertEqual(len(gsoc_students), num_gsoc_students) self.assertTrue(all(gsoc_students)) # Seed IntegerUniformDistribution(min_num_gsoc_student_proposals, # max_num_gsoc_student_proposals) student proposals for each student, # org is chosen randomly from gsoc_orgs min_num_gsoc_student_proposals = 0 max_num_gsoc_student_proposals = 2 for gsoc_student in gsoc_students: properties = { 'scope': gsoc_student, 'org': random.choice(gsoc_orgs), 'program': gsoc2011, 'mentor': None } num_gsoc_student_proposals = random.randint( min_num_gsoc_student_proposals, max_num_gsoc_student_proposals) gsoc_student_proposals = seeder_logic.seedn( StudentProposal, num_gsoc_student_proposals, properties) self.assertEqual(len(gsoc_student_proposals), num_gsoc_student_proposals) self.assertTrue(all(gsoc_student_proposals))
def testSeedAGSoCProgram(self): """Tests seeding a GSoC program using both seedn and seed methods. """ import random from soc.modules.gsoc.models.mentor import GSoCMentor from soc.modules.gsoc.models.org_admin import GSoCOrgAdmin from soc.modules.gsoc.models.organization import GSoCOrganization from soc.modules.gsoc.models.program import GSoCProgram from soc.modules.gsoc.models.student import GSoCStudent from soc.modules.gsoc.models.student_proposal import StudentProposal # Seed 'GSoC2011' properties = {'name': 'Google Summer of Code 2011','short_name': 'GSoC2011'} gsoc2011 = seeder_logic.seed(GSoCProgram, properties=properties) # Seed num_gsoc_orgs GSoC orgs num_gsoc_orgs = 10 properties = {'scope': gsoc2011} gsoc_orgs = seeder_logic.seedn(GSoCOrganization, num_gsoc_orgs, properties) self.assertEqual(len(gsoc_orgs), num_gsoc_orgs) self.assertTrue(all(gsoc_orgs)) # Seed IntegerUniformDistribution(min_num_gsoc_org_admins, # max_num_gsoc_org_admins) admins and IntegerUniformDistribution( # min_num_gsoc_org_mentors, max_num_gsoc_org_mentors) mentors for GSoC orgs min_num_gsoc_org_admins = 1 max_num_gsoc_org_admins = 5 min_num_gsoc_org_mentors = 0 max_num_gsoc_org_mentors = 10 for gsoc_org in gsoc_orgs: properties = {'scope': gsoc_org, 'program': gsoc2011} num_gsoc_org_admins = random.randint(min_num_gsoc_org_admins, max_num_gsoc_org_admins) gsoc_org_admins = seeder_logic.seedn(GSoCOrgAdmin, num_gsoc_org_admins, properties) self.assertEqual(len(gsoc_org_admins), num_gsoc_org_admins) self.assertTrue(all(gsoc_org_admins)) num_gsoc_org_mentors = random.randint(min_num_gsoc_org_mentors, max_num_gsoc_org_mentors) gsoc_org_mentors = seeder_logic.seedn(GSoCMentor, num_gsoc_org_mentors, properties) self.assertEqual(len(gsoc_org_mentors), num_gsoc_org_mentors) self.assertTrue(all(gsoc_org_mentors)) # Seed num_gsoc_students GSoC students num_gsoc_students = 20 properties = {'scope': gsoc2011} gsoc_students = seeder_logic.seedn(GSoCStudent, num_gsoc_students, properties) self.assertEqual(len(gsoc_students), num_gsoc_students) self.assertTrue(all(gsoc_students)) # Seed IntegerUniformDistribution(min_num_gsoc_student_proposals, # max_num_gsoc_student_proposals) student proposals for each student, # org is chosen randomly from gsoc_orgs min_num_gsoc_student_proposals = 0 max_num_gsoc_student_proposals = 2 for gsoc_student in gsoc_students: properties = {'scope': gsoc_student, 'org':random.choice(gsoc_orgs), 'program': gsoc2011, 'mentor': None} num_gsoc_student_proposals = random.randint( min_num_gsoc_student_proposals, max_num_gsoc_student_proposals) gsoc_student_proposals = seeder_logic.seedn( StudentProposal, num_gsoc_student_proposals, properties) self.assertEqual(len(gsoc_student_proposals), num_gsoc_student_proposals) self.assertTrue(all(gsoc_student_proposals))