Exemple #1
0
 def test_delete_not_implemented(self):
     user, team_dict = self.test_create_team_creates_survey()
     survey = Survey.get(team_id=team_dict['uid'])[0]
     self.testapp.delete(
         '/api/surveys/{}'.format(survey.uid),
         headers=self.login_headers(user),
         status=405,
     )
    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)
Exemple #3
0
    def post(self, team_id, date_str=None):
        survey = Survey.get(team_id=team_id)[0]
        if date_str:
            today = datetime.strptime(date_str, config.iso_date_format).date()
        else:
            today = date.today()

        # Cycle ultimately comes from Cycle.get_current_for_team() and so is
        # guaranteed to have start and end dates.
        cycle = survey.should_notify(today)
        if not cycle:
            # This task is run every week, but only actually send notifications
            # if the date matches the survey interval.
            return

        team = Team.get_by_id(survey.team_id)
        program = Program.get_by_id(team.program_id)
        classrooms = Classroom.get(team_id=team_id)
        users = User.query_by_team(team_id)

        if len(classrooms) == 0:
            pct_complete_by_id = {}
        else:
            ppn = get_participation(cycle, classrooms)
            pct_complete_by_id = self.participation_to_pct(ppn, classrooms)

        # Get all the responses once to save trips to the db. Redact them later
        # according to the relevate user.
        unsafe_responses = Response.get_for_teams_unsafe([team_id],
                                                         parent_id=cycle.uid)

        to_put = []
        for user in users:
            if user.receive_email:
                safe_responses = Response.redact_private_responses(
                    unsafe_responses, user)
                email = cycle_emailers.create_cycle_email(
                    program.label,
                    user,  # recipient
                    users,
                    team,
                    classrooms,
                    safe_responses,
                    cycle,
                    pct_complete_by_id,
                )

                to_put.append(email)

        ndb.put_multi(to_put)
def add_survey_ids_to_project_cohorts(project_cohort):
    """To make batch querying of dashboard views easier, we want to be able to
    get surveys by id, given project cohorts. This is a change to how pcs are
    created, so legacy data needs updating.

    Configure this job in map_reduce.yaml and initiate it from /mapreduce. You
    must be signed in as a project admin.

    See: https://sookocheff.com/post/appengine/mapreduce/mapreduce-yaml/
    """
    if len(project_cohort.survey_ids) > 0:
        return

    keys = Survey.get(project_cohort_id=project_cohort.uid, keys_only=True)
    project_cohort.survey_ids = [k.id() for k in keys]
    yield op.db.Put(project_cohort)
    def test_survey_creation(self):
        """Creating a project cohort should create surveys."""

        # Hack eventual consistency for just this test because we don't
        # expect surveys to be available instantly upon creation, unlike the
        # project cohort itself.
        self.policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(
            probability=1)
        self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)

        pc, user = self.test_join_cohort()

        program_label = 'demo-program'
        program = Program.get_config(program_label)

        surveys = Survey.get(project_cohort_id=pc.uid)
        self.assertEqual(len(surveys), len(program['surveys']))
Exemple #6
0
    def test_create_team_creates_survey(self):
        """When a team is created, its survey is automatically created."""
        user = User.create(name='User Foo', email='*****@*****.**')
        user.put()

        code = 'trout viper'

        team_response = self.testapp.post_json(
            '/api/teams',
            {
                'name': 'Team Foo',
                'code': code,
                'program_id': self.ep_program.uid,
            },
            headers=self.login_headers(user),
        )
        team_dict = json.loads(team_response.body)

        survey_result = Survey.get(team_id=team_dict['uid'])
        self.assertEqual(len(survey_result), 1)
        survey = survey_result[0]

        return user, team_dict