def mock_participants(self):
     unfinished_id = Participant.convert_uid(self.unfinished_id)
     finished_id = Participant.convert_uid(self.finished_id)
     participants = [
         Participant.create(id=unfinished_id,
                            name='unfinished',
                            organization_id='Org_foo'),
         Participant.create(id=finished_id,
                            name='finished',
                            organization_id='Org_foo'),
     ]
     Participant.put_multi(participants)
     return participants
    def create(self):
        team_id = 'Team_001'
        p1 = Participant.create(
            student_id='4321',
            team_id=team_id,
            classroom_ids=['Classroom_001'],
        )
        p2 = Participant.create(
            student_id='4322',
            team_id=team_id,
            classroom_ids=['Classroom_001', 'Classroom_002'],
        )
        p3 = Participant.create(
            student_id='4323',
            team_id=team_id,
            classroom_ids=['Classroom_003'],
        )
        Participant.put_multi([p1, p2, p3])

        return p1, p2, p3
    def test_delete_disassociates_participants(self):
        captain, contact, classroom1, report1, report2 = \
            self.create_for_delete()

        # Create another classroom, so we check that participants remain on it
        # afterward.
        classroom2 = Classroom.create(
            name='Classroom Bar',
            code='steel snake',
            team_id=classroom1.team_id,
            contact_id=contact.uid,
            num_students=22,
        )
        classroom2.put()

        ppt_on_one = Participant.create(
            student_id='on_one',
            team_id=classroom1.team_id,
            classroom_ids=[classroom1.uid],
        )
        ppt_on_two = Participant.create(
            student_id='on_two',
            team_id=classroom1.team_id,
            classroom_ids=[classroom1.uid, classroom2.uid],
        )
        Participant.put_multi([ppt_on_one, ppt_on_two])

        url = '/api/classrooms/{}'.format(classroom1.uid)
        headers = self.login_headers(captain)

        # Delete the classroom.
        self.testapp.delete(url, headers=headers, status=204)

        # Both participants are still there, but neither is associated with
        # the deleted classroom.
        self.assertEqual(
            Participant.get_by_id(ppt_on_one.uid).classroom_ids, [])
        self.assertEqual(
            Participant.get_by_id(ppt_on_two.uid).classroom_ids,
            [classroom2.uid])
Beispiel #4
0
    def test_get_for_classroom(self):
        """You can list participants for a team you own."""
        other, teammate, contact, captain, team, classroom, ppnt = self.create(
        )

        # Forbidden for non-members.
        response = self.testapp.get('/api/classrooms/{}/participants'.format(
            classroom.uid),
                                    headers=jwt_headers(other),
                                    status=403)

        # Make sure query excludes participants on other teams and classrooms.
        other_classroom = Classroom.create(code='foo',
                                           team_id=team.uid,
                                           contact_id='Lebowski')
        other_classroom.put()
        other_team_ppnt = Participant.create(
            first_name='team',
            last_name='team',
            team_id='Team_foo',
            classroom_ids=['Classroom_foo'],
            student_id='STUDENTID001',
        )
        other_class_ppnt = Participant.create(
            first_name='classroom',
            last_name='classroom',
            team_id=team.uid,
            classroom_ids=[other_classroom.uid],
            student_id='STUDENTID002')
        Participant.put_multi([other_team_ppnt, other_class_ppnt])

        # Successful for members.
        response = self.testapp.get(
            '/api/classrooms/{}/participants'.format(classroom.uid),
            headers=jwt_headers(teammate),
        )
        response_list = json.loads(response.body)
        self.assertEqual(len(response_list), 1)