Beispiel #1
0
    def test_delete_disassociates_teams(self):
        """When you delete an org, associated teams lose their org id."""
        user, org_dict = self.test_create()
        teams = [
            Team.create(
                name="Team Foo",
                organization_ids=[org_dict['uid']],
                captain_id='User_captain',
                program_id=self.program.uid,
            ),
            Team.create(
                name="Team Bar",
                organization_ids=[org_dict['uid']],
                captain_id='User_captain',
                program_id=self.program.uid,
            ),
        ]
        Team.put_multi(teams)

        response = self.testapp.delete('/api/organizations/{}'.format(
            org_dict['uid']),
                                       headers=self.login_headers(user),
                                       status=204)

        # Make sure the teams have lost their association to the org.
        for t in teams:
            fetched = Team.get_by_id(t.uid)
            self.assertNotIn(org_dict['uid'], fetched.organization_ids)
Beispiel #2
0
    def resolve_id_mismatch(klass, user, new_id):
        """Change all references to user's id to a new id.

        N.B. this is obviously brittle; when the relationship schema changes,
        this will also have to change.
        """
        # The auth server has a different id for this user; defer to it.

        teams = Team.get(captain_id=user.uid)
        for t in teams:
            t.captain_id = new_id
        Team.put_multi(teams)

        classrooms = Classroom.get(contact_id=user.uid)
        for c in classrooms:
            c.contact_id = new_id
        Classroom.put_multi(classrooms)

        params = {'uid': new_id, 'short_uid': SqlModel.convert_uid(new_id)}
        with mysql_connection.connect() as sql:
            sql.update_row(klass.table, 'uid', user.uid, **params)

        for k, v in params.items():
            setattr(user, k, v)

        return user
Beispiel #3
0
    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.
        teams = [
            Team.create(name=str(x).rjust(2, '0'), captain_id='User_captain',
                        program_id=self.demo_program.uid)
            for x in range(n)
        ]
        Team.put_multi(teams)
        super_admin = User.create(name='super', email='*****@*****.**',
                                  user_type='super_admin')
        super_admin.put()

        return teams, super_admin
Beispiel #5
0
    def test_dashboard(self):
        org = Organization.create(
            name='Org Foo',
            program_id=self.program.uid,
        )
        org.put()
        org_admin = User.create(
            name='Org Admin',
            email='*****@*****.**',
            owned_organizations=[org.uid],
        )
        org_admin.put()

        zipped = []
        for x in range(5):
            zipped.append(self.create_for_dashboard(org, x))
        teams, users, cycles, responses = zip(*zipped)

        Team.put_multi(teams)
        User.put_multi(users)
        Cycle.put_multi(cycles)
        Response.put_multi(responses)

        raw_result = self.testapp.get(
            '/api/organization_dashboards/{}'.format(org.uid),
            headers=self.login_headers(org_admin),
        )
        result = json.loads(raw_result.body)

        # Expected ids.
        team_ids = set(t.uid for t in teams)
        user_ids = set(u.uid for u in users)
        cycle_ids = set(c.uid for c in cycles)
        response_ids = set(r.uid for r in responses)

        # All ids present.
        self.assertEqual(set(t['uid'] for t in result['teams']), team_ids)
        self.assertEqual(set(u['uid'] for u in result['users']), user_ids)
        self.assertEqual(set(c['uid'] for c in result['cycles']), cycle_ids)
        self.assertEqual(set(r['uid'] for r in result['responses']),
                         response_ids)

        # Responses have no body.
        self.assertTrue(all(len(r['body']) == 0 for r in result['responses']))
    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)