Exemplo n.º 1
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']))
Exemplo n.º 2
0
    def create(self):
        org = Organization.create(name='Foo Community',
                                  program_id=self.program.uid)
        org.put()
        team = Team.create(
            name='foo',
            captain_id='User_captain',
            program_id=self.program.uid,
            organization_ids=[org.uid],
        )
        teammate = User.create(name='teammate',
                               email='*****@*****.**',
                               owned_teams=[team.uid])
        other = User.create(name='other', email='*****@*****.**')
        User.put_multi((other, teammate))
        team.put()

        cycles = (
            Cycle.create(
                team_id=team.uid,
                ordinal=1,
                start_date=datetime.date(2000, 1, 1),
                end_date=datetime.date(2000, 2, 1),
            ),
            Cycle.create(
                team_id=team.uid,
                ordinal=2,
                start_date=datetime.date.today(),
                end_date=datetime.date.today() + datetime.timedelta(weeks=4),
            ),
        )
        Cycle.put_multi(cycles)

        responses = {
            # User-level, not related to our team or user, inaccessible.
            'user_other_other':
            Response.create(
                user_id=other.uid,
                team_id='Team_other',
                parent_id='Cycle_other',
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Related to our user but not our team.
            'user_other_user':
            Response.create(
                user_id=teammate.uid,
                team_id='Team_other',
                parent_id='Cycle_isolated',
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Related to both our team and user; two different cycles.
            'user_team_user1':
            Response.create(
                user_id=teammate.uid,
                team_id=team.uid,
                parent_id=cycles[0].uid,
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            'user_team_user2':
            Response.create(
                user_id=teammate.uid,
                team_id=team.uid,
                parent_id=cycles[1].uid,
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Related to our team but not our user; body should stay secret
            'user_team_other':
            Response.create(
                user_id='User_other-teammate',
                team_id=team.uid,
                parent_id=cycles[0].uid,
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Team-level response, readable for all team members
            'team_team':
            Response.create(
                type='Team',
                user_id='',
                team_id=team.uid,
                parent_id='launch-step',
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Team-level, but for a different team.
            'team_other':
            Response.create(
                type='Team',
                user_id='',
                team_id='Team_other',
                parent_id='launch-step',
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
        }
        Response.put_multi(responses.values())

        return (other, teammate, team, cycles, responses)