def verify_access(self, mock_unit, student_should_have_access, expected_error_type=None): """ Verify the expected result from _has_access_descriptor """ response = access._has_access_descriptor(self.anonymous_user, 'load', mock_unit, course_key=self.course.id) assert student_should_have_access == bool(response) if expected_error_type is not None: assert isinstance(response, expected_error_type) assert response.to_json()['error_code'] is not None assert access._has_access_descriptor(self.course_staff, 'load', mock_unit, course_key=self.course.id)
def test__has_access_descriptor(self): # TODO: override DISABLE_START_DATES and test the start date branch of the method user = Mock() descriptor = Mock(user_partitions=[]) descriptor._class_tags = {} descriptor.merged_group_access = {} # Always returns true because DISABLE_START_DATES is set in test.py self.assertTrue(access._has_access_descriptor(user, 'load', descriptor)) self.assertTrue(access._has_access_descriptor(user, 'instructor', descriptor)) with self.assertRaises(ValueError): access._has_access_descriptor(user, 'not_load_or_staff', descriptor)
def verify_access(self, mock_unit, student_should_have_access, expected_error_type=None): """ Verify the expected result from _has_access_descriptor """ response = access._has_access_descriptor(self.anonymous_user, 'load', mock_unit, course_key=self.course.id) self.assertEqual(student_should_have_access, bool(response)) if expected_error_type is not None: self.assertIsInstance(response, expected_error_type) self.assertIsNotNone(response.to_json()['error_code']) self.assertTrue( access._has_access_descriptor(self.course_staff, 'load', mock_unit, course_key=self.course.id) )
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.DATES[self.TOMORROW] mock_unit.visible_to_staff_only = False mock_unit.merged_group_access = {} assert bool(access._has_access_descriptor(self.beta_user, 'load', mock_unit, course_key=self.course.id))