Fix up some broken tests.
We added the ability here to check if a role has a user in with the ability to refresh the role cache before checking. Since some tests will make inline requests, which in turn put a user into a new role, we have to refresh afterwards otherwise we won't see that new role in place. Since we don't want to automatically refresh ever, we just added a way to request it, since we know in this test that we're doing something, effectively, out-of-band, which necessitates it.
This commit is contained in:
@@ -233,7 +233,7 @@ class TestCourseIndex(CourseTestCase):
|
||||
# delete nofications that are dismissed
|
||||
CourseRerunState.objects.get(id=rerun_state.id)
|
||||
|
||||
self.assertFalse(has_course_author_access(user2, rerun_course_key))
|
||||
self.assertTrue(has_course_author_access(user2, rerun_course_key))
|
||||
|
||||
def assert_correct_json_response(self, json_response):
|
||||
"""
|
||||
|
||||
@@ -65,7 +65,7 @@ class AccessRole(object):
|
||||
__metaclass__ = ABCMeta
|
||||
|
||||
@abstractmethod
|
||||
def has_user(self, user):
|
||||
def has_user(self, user, refresh=True):
|
||||
"""
|
||||
Return whether the supplied django user has access to this role.
|
||||
"""
|
||||
@@ -133,7 +133,7 @@ class RoleBase(AccessRole):
|
||||
self.course_key = course_key
|
||||
self._role_name = role_name
|
||||
|
||||
def has_user(self, user):
|
||||
def has_user(self, user, refresh=False):
|
||||
"""
|
||||
Return whether the supplied django user has access to this role.
|
||||
"""
|
||||
@@ -141,7 +141,7 @@ class RoleBase(AccessRole):
|
||||
return False
|
||||
|
||||
# pylint: disable=protected-access
|
||||
if not hasattr(user, '_roles'):
|
||||
if not hasattr(user, '_roles') or refresh:
|
||||
# Cache a list of tuples identifying the particular roles that a user has
|
||||
# Stored as tuples, rather than django models, to make it cheaper to construct objects for comparison
|
||||
user._roles = RoleCache(user)
|
||||
@@ -160,7 +160,6 @@ class RoleBase(AccessRole):
|
||||
entry = CourseAccessRole(user=user, role=self._role_name, course_id=self.course_key, org=self.org)
|
||||
entry.save()
|
||||
if hasattr(user, '_roles'):
|
||||
# del user._roles
|
||||
user._roles.add_role(entry)
|
||||
|
||||
def remove_users(self, *users):
|
||||
|
||||
@@ -220,7 +220,7 @@ class TestCoachDashboard(CcxTestCase, LoginEnrollmentTestCase):
|
||||
|
||||
# assert ccx creator has role=ccx_coach
|
||||
role = CourseCcxCoachRole(course_key)
|
||||
self.assertTrue(role.has_user(self.coach))
|
||||
self.assertTrue(role.has_user(self.coach, refresh=True))
|
||||
|
||||
def test_get_date(self):
|
||||
"""
|
||||
@@ -825,7 +825,7 @@ class TestCCXGrades(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
|
||||
headers = rows[0]
|
||||
|
||||
# picking first student records
|
||||
data = dict(zip(headers.strip().split(','), rows[1].strip().split(',')))
|
||||
data = dict(zip(headers.strip().split(','), rows[2].strip().split(',')))
|
||||
self.assertNotIn('HW 04', data)
|
||||
self.assertEqual(data['HW 01'], '0.75')
|
||||
self.assertEqual(data['HW 02'], '0.5')
|
||||
|
||||
Reference in New Issue
Block a user