Exemplo n.º 1
0
    def test_nobody_done(self):
        """If no one finished the survey, counts are zero."""
        survey = Survey.create([], ordinal=1, program_label=self.program_label)
        survey.put()
        kwargs = {
            'key': 'progress',
            'program_label': self.program_label,
            'project_id': 'Project_12345678',
            'cohort_label': '2017_spring',
            'project_cohort_id': 'ProjectCohort_12345678',
            'code': 'trout viper',
            'survey_id': survey.uid,
            'survey_ordinal': survey.ordinal,
        }

        pd = [
            ParticipantData.create(participant_id='Participant_unfinished1',
                                   value=1,
                                   **kwargs),
            ParticipantData.create(participant_id='Participant_unfinished2',
                                   value=1,
                                   **kwargs),
        ]
        ParticipantData.put_multi(pd)

        result = ParticipantData.participation(survey_id=pd[0].survey_id)
        expected = [
            {
                'value': '1',
                'n': 2,
                'survey_ordinal': 1
            },
        ]

        self.assertEqual(result, expected)
    def create_pd_context(self):
        program_label = 'demo-program'
        program_config = Program.get_config(program_label)
        template = program_config['surveys'][0]['survey_tasklist_template']

        project_cohort = ProjectCohort.create(
            program_label=program_label,
            organization_id='Organization_foo',
            project_id='Project_foo',
            cohort_label='2018',
        )
        project_cohort.put()

        survey = Survey.create(
            template,
            program_label=program_label,
            organization_id='Organization_foo',
            project_cohort_id=project_cohort.uid,
            ordinal=1,
        )
        survey.put()

        participant = Participant.create(name='Pascal',
                                         organization_id='PERTS')
        participant.put()

        return (project_cohort, survey, participant)
Exemplo n.º 3
0
    def test_should_notify(self):
        team_id = 'Team_foo'
        survey = Survey.create(team_id=team_id)

        cycle = Cycle.create(
            team_id=team_id,
            ordinal=1,
            start_date=datetime.date.today() - datetime.timedelta(days=1),
            end_date=datetime.date.today() + datetime.timedelta(days=1),
        )
        cycle.put()

        today = datetime.date.today()
        now = datetime.datetime.now()

        # Case 1: notified time is not set.
        self.assertEqual(survey.should_notify(today), cycle)

        # Case 2: sent within cycle
        survey.notified = now - datetime.timedelta(days=1)
        self.assertEqual(survey.should_notify(today), False)

        # Case 3: sent before cycle
        survey.notified = now - datetime.timedelta(days=10)
        self.assertEqual(survey.should_notify(today), cycle)

        # import pdb
        # pdb.set_trace()
        # Case 4: today is not in any cycle (there is no current cycle)
        self.assertEqual(
            survey.should_notify(today - datetime.timedelta(days=10)),
            False,
        )
Exemplo n.º 4
0
    def test_survey_task_body(self):
        """Tasks should get dynamic properties from their definition."""
        program_label = 'demo-program'
        task_label = 'task_foo'
        survey = Survey.create(
            [],
            program_label='demo-program',
            organization_id='Organization_Foo',
            ordinal=1,
        )

        task_template = {
            'label': task_label,
            'body': "<p>Demo body.</p>",
        }
        Program.mock_program_config(
            program_label, {
                'surveys': [{
                    'survey_tasklist_template': [{
                        'tasks': [task_template]
                    }]
                }]
            })

        t = Task.create(task_label,
                        1,
                        'checkpoint_foo',
                        parent=survey,
                        program_label=program_label)
        t_dict = t.to_client_dict()

        self.assertIsInstance(t_dict['body'], basestring)
        self.assertGreater(len(t_dict['body']), 0)
Exemplo n.º 5
0
    def test_get_metrics(self):
        metric1 = Metric.create(name="Community of Helpers",
                                label='community_of_helpers')
        metric1.put()
        metric2 = Metric.create(name="Feedback for Growth",
                                label='feedback_for_growth')
        metric2.put()

        survey = Survey.create(team_id='Team_foo',
                               metrics=[metric1.uid, metric2.uid])
        self.assertEqual(set(survey.get_metrics()), {metric1, metric2})
Exemplo n.º 6
0
def mock_one_finished_one_unfinished(survey_ordinal,
                                     unfinished_id,
                                     finished_id,
                                     pc_id='ProjectCohort_foo',
                                     code='cool cat',
                                     program_label=None,
                                     cohort_label=None,
                                     organization_id=None):
    """Simulating one who finished and one who didn't."""
    survey = Survey.create(
        [],
        ordinal=survey_ordinal,
        program_label=program_label,
        organization_id=organization_id or 'Org_foo',
    )
    survey.put()
    kwargs = {
        'key': 'progress',
        'program_label': program_label,
        'project_id': 'Project_12345678',
        'cohort_label': cohort_label or cohort_label,
        'project_cohort_id': pc_id,
        'code': code,
        'survey_id': survey.uid,
        'survey_ordinal': survey.ordinal,
    }

    pd1 = ParticipantData.create(participant_id=unfinished_id,
                                 value=1,
                                 **kwargs)
    pd2 = ParticipantData.create(participant_id=finished_id, value=1, **kwargs)
    pd3 = ParticipantData.create(participant_id=finished_id,
                                 value=100,
                                 **kwargs)

    return [
        ParticipantData.put_for_index(pd1, 'participant-survey-key'),
        ParticipantData.put_for_index(pd2, 'participant-survey-key'),
        # Writing this third one should should update the second, so the third
        # uid will never get to the db.
        ParticipantData.put_for_index(pd3, 'participant-survey-key'),
    ]
Exemplo n.º 7
0
    def test_config_enabled(self):
        program = Program.create(
            name='Program Foo',
            label='TP1',
            survey_config_enabled=True,
            preview_url='foo.com',
        )
        program.put()

        team = Team.create(captain_id='User_captain', program_id=program.uid)
        team.put()

        survey = Survey.create(team_id=team.uid)
        survey.put()

        # Enabled by program.
        self.assertEqual(Survey.config_enabled(survey.uid), True)

        # Disabled by program.
        program.survey_config_enabled = False
        program.put()
        self.assertEqual(Survey.config_enabled(survey.uid), False)
Exemplo n.º 8
0
 def test_get_empty_metrics(self):
     survey = Survey.create(team_id='Team_foo', metrics=[])
     self.assertEqual(survey.get_metrics(), [])