def test_get_project_cohort_participation(self):
        """Get stats for all surveys in the project cohort."""
        pds1 = self.mock_one_finished_one_unfinished(1)
        pds2 = self.mock_one_finished_one_unfinished(2)
        project_cohort_id = pds1[0].project_cohort_id
        ProjectCohort(
            id=project_cohort_id,
            program_label=self.program_label,
        ).put()
        start = datetime.date.today()
        end = start + datetime.timedelta(days=1)

        expected = [
            {
                'value': '1',
                'n': 1,
                'survey_ordinal': 1
            },
            {
                'value': '100',
                'n': 1,
                'survey_ordinal': 1
            },
            {
                'value': '1',
                'n': 1,
                'survey_ordinal': 2
            },
            {
                'value': '100',
                'n': 1,
                'survey_ordinal': 2
            },
        ]

        result = ParticipantData.participation(
            project_cohort_id=project_cohort_id, start=start, end=end)
        self.assertEqual(result, expected)

        # The same result should also now be available in memcache, so if we
        # clear the db the result should be the same.
        ParticipantData.delete_multi(pds1 + pds2)
        result = ParticipantData.participation(
            project_cohort_id=project_cohort_id, start=start, end=end)
        self.assertEqual(result, expected)

        # It should also work if some other kwargs are set with value None.
        result = ParticipantData.participation(
            project_cohort_id=project_cohort_id,
            start=start,
            end=end,
            cohort_label=None)
        self.assertEqual(result, expected)
    def test_get_project_cohort_completion_ids(self):
        participants = {p.uid: p for p in self.mock_participants()}
        pds1 = self.mock_one_finished_one_unfinished(1)
        pds2 = self.mock_one_finished_one_unfinished(2)
        ProjectCohort(
            id=pds1[0].project_cohort_id,
            program_label=self.program_label,
        ).put()

        result = ParticipantData.completion_ids(
            project_cohort_id=pds1[0].project_cohort_id)

        expected = [
            {
                'token': 'unfinished',
                'percent_progress': '1',
                'module': 1
            },
            {
                'token': 'finished',
                'percent_progress': '100',
                'module': 1
            },
            {
                'token': 'unfinished',
                'percent_progress': '1',
                'module': 2
            },
            {
                'token': 'finished',
                'percent_progress': '100',
                'module': 2
            },
        ]

        self.assertEqual(result, expected)