def test_rserve_skips_existing(self): program = Program.create( name="The Engagement Project", label="ep19", preview_url='foo.com', ) week = util.datelike_to_iso_string(datetime.date.today()) org = Organization.create(name="Organization", captain_id="User_cap", program_id=program.uid) org_to_skip = Organization.create(name="Organization", captain_id="User_cap", program_id=program.uid) Organization.put_multi([org, org_to_skip]) team = Team.create(name="Team", captain_id="User_cap", program_id=program.uid) team_to_skip = Team.create(name="Team", captain_id="User_cap", program_id=program.uid) Team.put_multi([team, team_to_skip]) cl = Classroom.create(name="Classroom", team_id=team.uid, code="foo", contact_id="User_contact") cl_to_skip = Classroom.create(name="Classroom", team_id=team.uid, code="foo", contact_id="User_contact") Classroom.put_multi([cl, cl_to_skip]) Report.put_multi([ Report.create(parent_id=org_to_skip.uid, filename="foo", issue_date=week), Report.create(parent_id=team_to_skip.uid, filename="foo", issue_date=week), Report.create(parent_id=cl_to_skip.uid, filename="foo", issue_date=week), ]) # Skips all the parents who have reports already this week. orgs, teams, classes = cron_rserve.get_report_parents( program, week, False) self.assertEqual(len(orgs), 1) self.assertEqual(len(teams), 1) self.assertEqual(len(classes), 1) # ...unless you force it, then they're all there. orgs, teams, classes = cron_rserve.get_report_parents( program, week, True) self.assertEqual(len(orgs), 2) self.assertEqual(len(teams), 2) self.assertEqual(len(classes), 2)
def create_for_paging(self, n): # Pad numeric names so they sort alphabetically. orgs = [ Organization.create(name=str(x).rjust(2, '0'), program_id=self.program.uid) for x in range(n) ] Organization.put_multi(orgs) super_admin = User.create(name='super', email='*****@*****.**', user_type='super_admin') super_admin.put() return orgs, super_admin
def create_for_search(self): # Test that users can be matched on either name or email. admin_foo = User.create(name="Admin Foo", email="*****@*****.**") user_foo1 = User.create(name="User Foo", email="*****@*****.**") user_foo2 = User.create(name="Generic Name", email="*****@*****.**") user_bar = User.create(name="User Bar", email="*****@*****.**") org_foo = Organization.create(name="Org Foo", program_id=self.ep.uid) org_bar = Organization.create(name="Org Bar", program_id=self.ep.uid) team_foo = Team.create(name="Team Foo", program_id=self.ep.uid, captain_id=user_foo1.uid) team_bar = Team.create(name="Team Bar", program_id=self.ep.uid, captain_id=user_bar.uid) cl_foo = Classroom.create( name="Class Foo", code="foo", team_id=team_foo.uid, contact_id=user_foo2.uid, ) cl_bar = Classroom.create( name="Class Bar", code="bar", team_id=team_bar.uid, contact_id="User_contact", ) # Test that users can be matched on either name or email. admin_foo.owned_organizations = [org_foo.uid] user_foo1.owned_teams = [team_foo.uid] user_foo2.owned_teams = [team_foo.uid] user_bar.owned_teams = [team_bar.uid] Organization.put_multi([org_foo, org_bar]) Team.put_multi([team_foo, team_bar]) Classroom.put_multi([cl_foo, cl_bar]) User.put_multi([admin_foo, user_foo1, user_foo2, user_bar]) return (org_foo, org_bar, team_foo, team_bar, cl_foo, cl_bar, admin_foo, user_foo1, user_foo2, user_bar)
def test_create_with_org_codes(self, org=None): """Can send org code(s) on POST to associate with team.""" other_program = Program.create( name='Test Program', label='TP1', metrics=['Metric_1', 'Metric_2'], min_cycles=2, active=False, preview_url='foo.com', ) other_program.put() if org is None: org = Organization.create( name='Org Correct', program_id=self.demo_program.uid, code='correct code', ) org2 = Organization.create( name='Org Second', program_id=self.demo_program.uid, code='second code', ) other_org = Organization.create( name='Org Other', program_id=other_program.uid, code='other code', ) Organization.put_multi([org, org2, other_org]) user = User.create(name='foo', email='*****@*****.**') user.put() # Invalid org code. team_params = { 'name': 'Team Foo', 'organization_code': 'does not exist', 'program_id': self.demo_program.uid, } self.testapp.post_json( '/api/teams', team_params, headers=self.login_headers(user), status=400, ) # Org program and team program don't match. self.testapp.post_json( '/api/teams', dict(team_params, organization_code=other_org.code), headers=self.login_headers(user), status=400, ) # Success. multi_code = ', '.join([org.code, org2.code]) response = self.testapp.post_json( '/api/teams', dict(team_params, organization_code=multi_code), headers=self.login_headers(user), ) team_dict = json.loads(response.body) self.assertEqual( set(team_dict['organization_ids']), set([org.uid, org2.uid]), ) self.assert_created_with_program(team_dict, self.demo_program)