def test__has_access_descriptor_staff_lock(self):
        """
        Tests that "visible_to_staff_only" overrides start date.
        """
        mock_unit = Mock(user_partitions=[])
        mock_unit._class_tags = {}  # Needed for detached check in _has_access_descriptor

        # No start date, staff lock on
        mock_unit.visible_to_staff_only = True
        self.verify_access(mock_unit, False)

        # No start date, staff lock off.
        mock_unit.visible_to_staff_only = False
        self.verify_access(mock_unit, True)

        # Start date in the past, staff lock on.
        mock_unit.start = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1)
        mock_unit.visible_to_staff_only = True
        self.verify_access(mock_unit, False)

        # Start date in the past, staff lock off.
        mock_unit.visible_to_staff_only = False
        self.verify_access(mock_unit, True)

        # Start date in the future, staff lock on.
        mock_unit.start = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1)  # release date in the future
        mock_unit.visible_to_staff_only = True
        self.verify_access(mock_unit, False)

        # Start date in the future, staff lock off.
        mock_unit.visible_to_staff_only = False
        self.verify_access(mock_unit, False)
Example #2
0
def default_args():
    args = Mock()
    args.conf_file = ".lamvery.yml"
    args.follow = False
    args.interval = 1
    args.start = "-1h"
    return args
Example #3
0
    def test__has_access_descriptor_staff_lock(self):
        """
        Tests that "visible_to_staff_only" overrides start date.
        """
        mock_unit = Mock(user_partitions=[])
        mock_unit._class_tags = {}  # Needed for detached check in _has_access_descriptor
        mock_unit.category = "problem"

        def verify_access(student_should_have_access):
            """ Verify the expected result from _has_access_descriptor """
            self.assertEqual(
                student_should_have_access,
                access._has_access_descriptor(
                    self.anonymous_user, "load", mock_unit, course_key=self.course.course_key
                ),
            )
            # staff always has access
            self.assertTrue(
                access._has_access_descriptor(self.course_staff, "load", mock_unit, course_key=self.course.course_key)
            )

        # No start date, staff lock on
        mock_unit.visible_to_staff_only = True
        verify_access(False)

        # No start date, staff lock off.
        mock_unit.visible_to_staff_only = False
        verify_access(True)

        # Start date in the past, staff lock on.
        mock_unit.start = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1)
        mock_unit.visible_to_staff_only = True
        verify_access(False)

        # Start date in the past, staff lock off.
        mock_unit.visible_to_staff_only = False
        verify_access(True)

        # Start date in the future, staff lock on.
        mock_unit.start = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1)  # release date in the future
        mock_unit.visible_to_staff_only = True
        verify_access(False)

        # Start date in the future, staff lock off.
        mock_unit.visible_to_staff_only = False
        verify_access(False)
Example #4
0
 def test__has_access_descriptor_in_preview_mode(self, start):
     """
     Tests that descriptor has access in preview mode.
     """
     mock_unit = Mock(user_partitions=[])
     mock_unit._class_tags = {}  # Needed for detached check in _has_access_descriptor
     mock_unit.visible_to_staff_only = False
     mock_unit.start = start
     self.verify_access(mock_unit, True)
    def test__has_access_descriptor_when_not_in_preview_mode(self):
        """
        Tests that descriptor has no access when start date in future & without preview.
        """
        mock_unit = Mock(user_partitions=[])
        mock_unit._class_tags = {}  # Needed for detached check in _has_access_descriptor

        # No start date.
        mock_unit.visible_to_staff_only = False
        self.verify_access(mock_unit, True)

        # Start date in the past.
        mock_unit.start = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1)
        self.verify_access(mock_unit, True)

        # Start date in the future.
        mock_unit.start = datetime.datetime.now(pytz.utc) + datetime.timedelta(days=1)  # release date in the future
        self.verify_access(mock_unit, False)
Example #6
0
    def test__has_access_descriptor(self):
        # TODO: override DISABLE_START_DATES and test the start date branch of the method
        u = Mock()
        d = Mock()
        d.start = datetime.datetime.now(UTC()) - datetime.timedelta(days=1)  # make sure the start time is in the past

        # Always returns true because DISABLE_START_DATES is set in test.py
        self.assertTrue(access._has_access_descriptor(u, d, "load"))
        self.assertRaises(ValueError, access._has_access_descriptor, u, d, "not_load_or_staff")
Example #7
0
 def test__has_access_descriptor_when_not_in_preview_mode(self, start, expected_error_type):
     """
     Tests that descriptor has no access when start date in future & without preview.
     """
     expected_access = expected_error_type is None
     mock_unit = Mock(user_partitions=[])
     mock_unit._class_tags = {}  # Needed for detached check in _has_access_descriptor
     mock_unit.visible_to_staff_only = False
     mock_unit.start = start
     self.verify_access(mock_unit, expected_access, expected_error_type)
Example #8
0
    def test__has_access_descriptor_beta_user(self):
        mock_unit = Mock(user_partitions=[])
        mock_unit._class_tags = {}
        mock_unit.days_early_for_beta = 2
        mock_unit.start = self.TOMORROW
        mock_unit.visible_to_staff_only = False

        self.assertTrue(
            bool(access._has_access_descriptor(self.beta_user, "load", mock_unit, course_key=self.course.course_key))
        )
Example #9
0
 def test__has_access_descriptor_staff_lock(self, visible_to_staff_only, start, expected_error_type=None):
     """
     Tests that "visible_to_staff_only" overrides start date.
     """
     expected_access = expected_error_type is None
     mock_unit = Mock(user_partitions=[])
     mock_unit._class_tags = {}  # Needed for detached check in _has_access_descriptor
     mock_unit.visible_to_staff_only = visible_to_staff_only
     mock_unit.start = start
     self.verify_access(mock_unit, expected_access, expected_error_type)
Example #10
0
def get_contest():
    contest = Mock()
    contest.id = get_int()
    contest.name = get_string()
    start = get_int(2 ** 11)
    duration = get_int(2 ** 8)
    contest.start = make_datetime(start)
    contest.stop = make_datetime(start + duration)
    contest.score_precision = 2
    contest.description = get_string()
    return contest
Example #11
0
    def test__has_access_descriptor(self):
        # TODO: override DISABLE_START_DATES and test the start date branch of the method
        user = Mock()
        date = Mock()
        date.start = datetime.datetime.now(pytz.utc) - datetime.timedelta(
            days=1
        )  # make sure the start time is in the past

        # Always returns true because DISABLE_START_DATES is set in test.py
        self.assertTrue(access._has_access_descriptor(user, "load", date))
        with self.assertRaises(ValueError):
            access._has_access_descriptor(user, "not_load_or_staff", date)
Example #12
0
    def test_coverage(self, coverage_func):
        coverage_object = Mock()
        coverage_func.return_value = coverage_object
        coverage_object.start = Mock()
        coverage_object.stop = Mock()
        coverage_object.save = Mock()

        cov = Coverage("coverage", True, "coverage")
        self.assertFalse(coverage_func.called)
        self.assertFalse(coverage_object.start.called)
        self.assertFalse(coverage_object.stop.called)
        self.assertFalse(coverage_object.save.called)
        cov.setup()
        coverage_func.assert_called_once_with()
        coverage_object.start.assert_called_once_with()
        self.assertFalse(coverage_object.stop.called)
        self.assertFalse(coverage_object.save.called)
        cov.teardown()
        coverage_object.stop.assert_called_once_with()
        coverage_object.save.assert_called_once_with()