Example #1
0
    def test_set_user_override(self, initial_date, override_date,
                               expected_date):
        items = make_items()
        first = items[0]
        block_id = first[0]
        items[0][1]['due'] = initial_date

        api.set_dates_for_course(str(block_id.course_key), items)

        api.set_date_for_block(block_id.course_key,
                               block_id,
                               'due',
                               override_date,
                               user=self.user)
        DEFAULT_REQUEST_CACHE.clear()
        cache.clear()
        retrieved = api.get_dates_for_course(block_id.course_key,
                                             user=self.user.id)
        assert len(retrieved) == NUM_OVERRIDES
        assert retrieved[block_id, 'due'] == expected_date

        overrides = api.get_overrides_for_block(block_id.course_key, block_id)
        assert len(overrides) == 1
        assert overrides[0][2] == expected_date

        overrides = list(
            api.get_overrides_for_user(block_id.course_key, self.user))
        assert len(overrides) == 1
        assert overrides[0] == {
            'location': block_id,
            'actual_date': expected_date
        }
Example #2
0
def dump_module_extensions(course, unit):
    """
    Dumps data about students with due date extensions for a particular module,
    specified by 'url', in a particular course.
    """
    header = [_("Username"), _("Full Name"), _("Extended Due Date")]
    data = []
    for username, fullname, due_date in api.get_overrides_for_block(course.id, unit.location):
        due_date = due_date.strftime(u'%Y-%m-%d %H:%M')
        data.append(dict(list(zip(header, (username, fullname, due_date)))))
    data.sort(key=operator.itemgetter(_("Username")))
    return {
        "header": header,
        "title": _(u"Users with due date extensions for {0}").format(
            title_or_url(unit)),
        "data": data
    }
Example #3
0
def dump_module_extensions(course, unit):
    """
    Dumps data about students with due date extensions for a particular module,
    specified by 'url', in a particular course.
    """
    header = [_("Username"), _("Full Name"), _("Extended Due Date")]
    data = []
    for username, fullname, due_date in api.get_overrides_for_block(course.id, unit.location):
        due_date = due_date.strftime(u'%Y-%m-%d %H:%M')
        data.append(dict(zip(header, (username, fullname, due_date))))
    data.sort(key=operator.itemgetter(_("Username")))
    return {
        "header": header,
        "title": _(u"Users with due date extensions for {0}").format(
            title_or_url(unit)),
        "data": data
    }
Example #4
0
    def test_allow_relative_dates(self):
        course_key = CourseLocator('testX', 'tt101', '2019')
        block1 = make_block_id(course_key)
        date1 = datetime(2019, 3, 22)
        block2 = make_block_id(course_key)
        date2 = datetime(2019, 3, 23)
        date2_override_delta = timedelta(days=10)
        date2_override = date2 + date2_override_delta
        block3 = make_block_id(course_key)
        date3_delta = timedelta(days=1)
        date3 = self.schedule.start_date + date3_delta
        block4 = make_block_id(course_key)
        date4_delta = timedelta(days=2)
        date4 = self.schedule.start_date + date4_delta
        date4_override = datetime(2019, 4, 24)
        items = [
            (block1, {
                'due': date1
            }),  # absolute
            (block2, {
                'due': date2
            }),  # absolute, to be overwritten by relative date
            (block3, {
                'due': date3_delta
            }),  # relative
            (block4, {
                'due': date4_delta
            }),  # relative, to be overwritten by absolute date
        ]
        api.set_dates_for_course(course_key, items)
        api.set_date_for_block(course_key,
                               block2,
                               'due',
                               date2_override_delta,
                               user=self.user)
        api.set_date_for_block(course_key,
                               block4,
                               'due',
                               date4_override,
                               user=self.user)

        # get_dates_for_course
        dates = [
            ((block1, 'due'), date1),
            ((block2, 'due'), date2),
            ((block3, 'due'), date3),
            ((block4, 'due'), date4),
        ]
        user_dates = [
            ((block1, 'due'), date1),
            ((block2, 'due'), date2_override),
        ]
        assert api.get_dates_for_course(course_key,
                                        schedule=self.schedule) == dict(dates)
        with patch('edx_when.api._are_relative_dates_enabled',
                   return_value=False):
            assert api.get_dates_for_course(
                course_key, schedule=self.schedule) == dict(dates[0:2])
            assert api.get_dates_for_course(course_key,
                                            schedule=self.schedule,
                                            user=self.user) == dict(user_dates)

        # get_date_for_block
        assert api.get_date_for_block(course_key, block2) == date2
        assert api.get_date_for_block(course_key, block4,
                                      user=self.user) == date4_override
        with patch('edx_when.api._are_relative_dates_enabled',
                   return_value=False):
            assert api.get_date_for_block(course_key, block2) == date2
            assert api.get_date_for_block(course_key, block1,
                                          user=self.user) == date1
            assert api.get_date_for_block(course_key, block2,
                                          user=self.user) == date2_override
            assert api.get_date_for_block(course_key, block4,
                                          user=self.user) is None

        # get_overrides_for_block
        block2_overrides = [(self.user.username, 'unknown', date2_override)]
        assert api.get_overrides_for_block(course_key,
                                           block2) == block2_overrides
        with patch('edx_when.api._are_relative_dates_enabled',
                   return_value=False):
            assert api.get_overrides_for_block(course_key, block2) == [
                (self.user.username, 'unknown', date2_override)
            ]

        # get_overrides_for_user
        user_overrides = [
            {
                'location': block4,
                'actual_date': date4_override
            },
            {
                'location': block2,
                'actual_date': date2_override
            },
        ]
        assert list(api.get_overrides_for_user(course_key,
                                               self.user)) == user_overrides
        with patch('edx_when.api._are_relative_dates_enabled',
                   return_value=False):
            assert list(api.get_overrides_for_user(
                course_key, self.user)) == user_overrides