示例#1
0
    def test_extended_end_dates_some_unset(self):
        cycles = [
            Cycle.create(
              team_id="Team_001",
              ordinal=1,
              start_date=date(2019, 1, 1),
              end_date=date(2019, 1, 15)
            ),
            Cycle.create(
              team_id="Team_001",
              ordinal=2,
              start_date=None,
              end_date=None,
            ),
            Cycle.create(
              team_id="Team_001",
              ordinal=3,
              start_date=None,
              end_date=None,
            ),
        ]

        # Should match output of Cycle.cycleless_end_date().
        last_day_of_program = date(2019, 6, 30)

        reordered = Cycle.reorder_and_extend(cycles)
        self.assertEqual(reordered[0].extended_end_date, last_day_of_program)
        self.assertEqual(reordered[1].extended_end_date, None)
        self.assertEqual(reordered[2].extended_end_date, None)
示例#2
0
 def test_reorders(self):
     """
     Cycles without dates are placed at the end ordered by ordinal.
     """
     cycles = [
         Cycle.create(
           team_id="Team_001",
           ordinal=1,
           start_date=None,
           end_date=None
         ),
         Cycle.create(
           team_id="Team_001",
           ordinal=2,
           start_date=None,
           end_date=None
         ),
         Cycle.create(
           team_id="Team_001",
           ordinal=3,
           start_date=date(2018, 1, 1),
           end_date=date(2019, 1, 1)
         ),
     ]
     reordered = Cycle.reorder_and_extend(cycles)
     self.assertEqual(reordered, [cycles[2], cycles[0], cycles[1]])
示例#3
0
 def test_extended_end_dates_all_set(self):
     cycles = [
         Cycle.create(
           team_id="Team_001",
           ordinal=1,
           start_date=date(2019, 1, 1),
           end_date=date(2019, 1, 15)
         ),
         Cycle.create(
           team_id="Team_001",
           ordinal=2,
           start_date=date(2019, 2, 1),
           end_date=date(2019, 2, 15)
         ),
         Cycle.create(
           team_id="Team_001",
           ordinal=3,
           start_date=date(2019, 3, 1),
           end_date=date(2019, 3, 15)
         ),
     ]
     reordered = Cycle.reorder_and_extend(cycles)
     self.assertEqual(
         reordered[0].extended_end_date,
         date(2019, 1, 31),  # day before 2/1
     )
     self.assertEqual(
         reordered[1].extended_end_date,
         date(2019, 2, 28),  # day before 3/1
     )
     self.assertEqual(
         reordered[2].extended_end_date,
         date(2019, 6, 30)  # last day of program
     )
示例#4
0
    def test_get_current_no_extended_end_date(self):
        team_id = 'Team_001'
        strictly_past_cycle = Cycle.create(
          team_id=team_id,
          ordinal=1,
          start_date=date.today() - timedelta(days=2),
          end_date=date.today() - timedelta(days=1),
        )
        strictly_past_cycle.put()
        strictly_current_cycle = Cycle.create(
          team_id=team_id,
          ordinal=2,
          start_date=date.today() - timedelta(days=1),
          end_date=date.today() + timedelta(days=1),
        )
        strictly_current_cycle.put()
        strictly_future_cycle = Cycle.create(
          team_id=team_id,
          ordinal=3,
          start_date=date.today() + timedelta(days=1),
          end_date=date.today() + timedelta(days=2),
        )
        strictly_future_cycle.put()

        self.assertEqual(
            Cycle.get_current_for_team(team_id),
            strictly_current_cycle
        )
示例#5
0
    def create_for_dashboard(self, org, x=0):
        x_label = str(x).rjust(2, '0')
        team = Team.create(
            name='Team {}'.format(x_label),
            captain_id='User_captain_{}'.format(x_label),
            organization_ids=[org.uid],
            program_id=self.program.uid,
        )
        user = User.create(name='User {}'.format(x_label),
                           email='foo.{}@bar.com'.format(x_label),
                           owned_teams=[team.uid])
        cycle = Cycle.create(
            team_id=team.uid,
            ordinal=1,
            start_date=datetime.date.today() - datetime.timedelta(days=1),
            end_date=datetime.date.today() + datetime.timedelta(days=1),
        )
        response = Response.create(
            type=Response.USER_LEVEL_SYMBOL,
            user_id=user.uid,
            team_id=team.uid,
            parent_id=cycle.uid,
            module_label='DemoModule',
            progress=50,
            page=1,
            body={
                'question1': {
                    'modified': '2019-01-01T00:00:00Z',
                    'value': 'foo',
                },
            },
        )

        return (team, user, cycle, response)
示例#6
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,
        )
示例#7
0
    def create(self):
        program = Program.create(
            name="Demo",
            label='demo',
            min_cycles=1,
            preview_url='foo.com',
        )
        program.put()

        team = Team.create(name='foo', program_id=program.uid)
        captain = User.create(name='captain', email='*****@*****.**',
                              owned_teams=[team.uid])
        team.captain_id = captain.uid
        teammate = User.create(name='teammate', email='*****@*****.**',
                               owned_teams=[team.uid])
        other = User.create(name='other', email='*****@*****.**')
        User.put_multi((other, teammate, captain))
        team.put()

        cycles = (
            # From a different team.
            Cycle.create(
                team_id='Team_other',
                ordinal=1,
                start_date=datetime.date(2000, 1, 1),
                end_date=datetime.date(2000, 1, 1),
            ),
            Cycle.create(
                team_id=team.uid,
                ordinal=1,
                start_date=datetime.date(2000, 1, 1),
                end_date=datetime.date(2000, 2, 1),
            ),
            # Current.
            Cycle.create(
                team_id=team.uid,
                ordinal=2,
                start_date=datetime.date.today(),
                end_date=datetime.date.today() + datetime.timedelta(weeks=4),
            ),
        )
        Cycle.put_multi(cycles)

        return other, teammate, captain, team, cycles
示例#8
0
    def create(self, program_label):
        program = Program.create(
            name="Foo",
            label=program_label,
            active=True,
            preview_url='foo.com',
        )
        program.put()

        captain = User.create(email='*****@*****.**', name="Captain PERTS")

        team = Team.create(name='Team Foo',
                           program_id=program.uid,
                           captain_id=captain.uid)
        team.put()

        classrooms = [
            Classroom.create(name='Class A',
                             team_id=team.uid,
                             num_students=5,
                             contact_id='User_contact',
                             code='foo'),
            Classroom.create(name='Class B',
                             team_id=team.uid,
                             num_students=5,
                             contact_id='User_contact',
                             code='bar'),
            Classroom.create(name='Class C',
                             team_id=team.uid,
                             num_students=5,
                             contact_id='User_contact',
                             code='baz'),
        ]
        Classroom.put_multi(classrooms)

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

        captain.owned_teams = [team.uid]
        captain.put()

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

        return (program, captain, team, classrooms, cycle)
示例#9
0
    def create(self):
        captain = User.create(email='*****@*****.**', name="Captain PERTS")
        teacher = User.create(email='*****@*****.**', name="Edward Teach")
        team = Team.create(name='Team Foo', program_id='Program_ep',
                           captain_id=captain.uid)
        classroom = Classroom.create(name='Class Foo', team_id=team.uid,
                                     contact_id=teacher.uid)
        cycle = Cycle.create(
            team_id=team.uid,
            ordinal=1,
            start_date=datetime.date.today() - datetime.timedelta(days=7),
            end_date=datetime.date.today() + datetime.timedelta(days=7),
        )

        captain.owned_teams = [team.uid]
        teacher.owned_teams = [team.uid]

        return (captain, teacher, team, classroom, cycle)
示例#10
0
    def test_check_roster_cycle_data(self):
        team = Team.create(name='foo',
                           captain_id="User_cap",
                           program_id=self.program.uid)
        classroom = Classroom.create(
            name="CompSci 101",
            team_id=team.uid,
            contact_id="User_contact",
            code="foo bar",
            num_students=1,
        )
        ppt = Participant.create(team_id=team.uid,
                                 classroom_ids=[classroom.uid],
                                 student_id='STUDENTID001')
        today = datetime.date.today()
        cycle1 = Cycle.create(
            team_id=team.uid,
            ordinal=1,
            # schedule to not be current (starts and ends in the past)
            start_date=today - datetime.timedelta(days=3),
            end_date=today - datetime.timedelta(days=2),
        )
        cycle1.put()

        team.put()
        classroom.put()
        ppt.put()

        # Without a current cycle, no cycle data
        response = self.testapp.get(
            '/api/codes/{}/participants/{}'.format(classroom.url_code,
                                                   ppt.student_id),
            status=200,
        )
        self.assertEqual(
            json.loads(response.body),
            {
                'uid': ppt.uid,
                'team_id': ppt.team_id
            },
        )

        # Add a new cycle that is current.
        cycle2 = Cycle.create(
            team_id=team.uid,
            ordinal=2,
            # schedule to not be current (starts and ends in the past)
            start_date=today - datetime.timedelta(days=1),
            end_date=today + datetime.timedelta(days=1),
        )
        cycle2.put()

        # Cycle data present.
        response = self.testapp.get(
            '/api/codes/{}/participants/{}'.format(classroom.url_code,
                                                   ppt.student_id),
            status=200,
        )
        expected = {
            'uid': ppt.uid,
            'team_id': ppt.team_id,
            'cycle': {
                'uid': cycle2.uid,
                'team_id': cycle2.team_id,
                'ordinal': cycle2.ordinal,
                'start_date': util.datelike_to_iso_string(cycle2.start_date),
                'end_date': util.datelike_to_iso_string(cycle2.end_date),
            }
        }
        self.assertEqual(json.loads(response.body), expected)
示例#11
0
    def create(self):
        org = Organization.create(name='Foo Community',
                                  program_id=self.program.uid)
        org.put()
        team = Team.create(
            name='foo',
            captain_id='User_captain',
            program_id=self.program.uid,
            organization_ids=[org.uid],
        )
        teammate = User.create(name='teammate',
                               email='*****@*****.**',
                               owned_teams=[team.uid])
        other = User.create(name='other', email='*****@*****.**')
        User.put_multi((other, teammate))
        team.put()

        cycles = (
            Cycle.create(
                team_id=team.uid,
                ordinal=1,
                start_date=datetime.date(2000, 1, 1),
                end_date=datetime.date(2000, 2, 1),
            ),
            Cycle.create(
                team_id=team.uid,
                ordinal=2,
                start_date=datetime.date.today(),
                end_date=datetime.date.today() + datetime.timedelta(weeks=4),
            ),
        )
        Cycle.put_multi(cycles)

        responses = {
            # User-level, not related to our team or user, inaccessible.
            'user_other_other':
            Response.create(
                user_id=other.uid,
                team_id='Team_other',
                parent_id='Cycle_other',
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Related to our user but not our team.
            'user_other_user':
            Response.create(
                user_id=teammate.uid,
                team_id='Team_other',
                parent_id='Cycle_isolated',
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Related to both our team and user; two different cycles.
            'user_team_user1':
            Response.create(
                user_id=teammate.uid,
                team_id=team.uid,
                parent_id=cycles[0].uid,
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            'user_team_user2':
            Response.create(
                user_id=teammate.uid,
                team_id=team.uid,
                parent_id=cycles[1].uid,
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Related to our team but not our user; body should stay secret
            'user_team_other':
            Response.create(
                user_id='User_other-teammate',
                team_id=team.uid,
                parent_id=cycles[0].uid,
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Team-level response, readable for all team members
            'team_team':
            Response.create(
                type='Team',
                user_id='',
                team_id=team.uid,
                parent_id='launch-step',
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
            # Team-level, but for a different team.
            'team_other':
            Response.create(
                type='Team',
                user_id='',
                team_id='Team_other',
                parent_id='launch-step',
                module_label='ModuleFoo',
                body=self.default_body(),
            ),
        }
        Response.put_multi(responses.values())

        return (other, teammate, team, cycles, responses)