Exemplo n.º 1
0
    def test_team_in_program_with_use_cycles_false_gets_single_cycle(self):
        user = User.create(name='foo', email='*****@*****.**')
        user.put()

        cycleless_program = Program.create(
            label='cycleless',
            name='Cycleless Program',
            preview_url='http://cycle.less',
            use_cycles=False,
            min_cycles=1,
            max_cycles=1
        )
        cycleless_program.put()

        cycleless_team_params = {
            "name": 'Cycleless Team',
            "uid": 'Team_cycleless',
            "program_id": cycleless_program.uid
        }
        response = self.testapp.post_json(
            '/api/teams',
            cycleless_team_params,
            headers=self.login_headers(user)
        )

        team_uid = json.loads(response.body)['uid']

        cycles = Cycle.get(team_id=team_uid)

        self.assertEqual(len(cycles), 1)
Exemplo n.º 2
0
    def test_overlap_forbidden(self):
        other, teammate, captain, team, cycles = self.create()

        # Try to create a new cycle that wraps the others.
        before = cycles[1].start_date - datetime.timedelta(days=1)
        after = cycles[2].end_date + datetime.timedelta(days=1)
        wrapping_params = {
            'team_id': team.uid,
            'ordinal': 1,
            'start_date': before.strftime(config.iso_date_format),
            'end_date': after.strftime(config.iso_date_format),
        }
        self.testapp.post_json(
            '/api/cycles',
            wrapping_params,
            headers=jwt_headers(captain),
            status=400,
        )

        # Nothing created in db.
        self.assertEqual(len(Cycle.get()), 3)

        # Same story for updating.
        self.testapp.put_json(
            '/api/cycles/{}'.format(cycles[1].uid),
            wrapping_params,
            headers=jwt_headers(captain),
            status=400,
        )

        # Cycle's dates haven't changed.
        fetched = Cycle.get_by_id(cycles[1].uid)
        self.assertEqual(fetched.start_date, cycles[1].start_date)
        self.assertEqual(fetched.end_date, cycles[1].end_date)
Exemplo n.º 3
0
    def assert_created_with_program(self, team_dict, program):
        # Survey should have program's metrics.
        survey = Survey.get(team_id=team_dict['uid'])[0]
        self.assertEqual(survey.metrics, program.metrics)
        self.assertEqual(survey.open_responses, program.metrics)

        # Correct number of cycles created.
        cycles = Cycle.get(team_id=team_dict['uid'])
        self.assertEqual(len(cycles), program.min_cycles or 0)
Exemplo n.º 4
0
    def get(self, user_id=None, team_id=None):
        complete = False

        # Determine authenticated user based on JWT token
        # @todo: can we apply jti or some other rule to make sure this URL isn't
        # inappropriately shareable?
        token = self.request.get('token', None)
        payload, error = jwt_helper.decode(token)
        if not payload or error:
            return self.http_forbidden()

        auth_user = User.get_by_id(payload['user_id'])

        user = User.get_by_id(user_id)
        team = Team.get_by_id(team_id)

        if not user or not team:
            return self.http_not_found()

        # The authenticated user can only retrieve their own certificate.
        # The authenticated user must own the team that they are requesting the
        #   certificate for.
        if not auth_user == user and not owns(auth_user, team):
            return self.http_forbidden()

        classrooms = Classroom.get(
            contact_id=user.uid,
            team_id=team_id,
        )

        cycles = Cycle.get(
            team_id=team_id,
            order='ordinal',
        )

        if len(classrooms) > 0 and len(cycles) > 0:
            cycle_participation = self.get_cycle_participation_pct(
                cycles,
                classrooms,
            )

            participation_complete = self.has_completed_three_cycles(
                cycle_participation)
        else:
            cycle_participation = [{
                'ordinal': c.ordinal,
                'pct': 0,
            } for c in cycles]
            participation_complete = False

        exit_survey_complete = self.has_completed_exit_survey(
            user,
            team_id,
        )

        if (exit_survey_complete and participation_complete):
            complete = True

        if (complete):
            # If a teacher has successfully completed participation for three
            # cycles, the certificate should not show any incomplete cycles
            # because they aren't relevant for the requirement of receiving the
            # completion certificate. See #1223.
            cycles_to_display = [
                c for c in cycle_participation if c['pct'] >= 80
            ][0:3]
        else:
            cycles_to_display = cycle_participation

        if util.is_localhost():
            neptune_protocol = 'http'
            neptune_domain = 'localhost:8080'
        else:
            neptune_protocol = 'https'
            neptune_domain = os.environ['NEPTUNE_DOMAIN']

        self.write(
            'completion.html',
            neptune_protocol=neptune_protocol,
            neptune_domain=neptune_domain,
            complete=complete,
            user_to_display=user,
            team=team,
            cycles_to_display=cycles_to_display,
            exit_survey_complete=exit_survey_complete,
        )