Commit 19d9920b by David Ormsbee

Revert "Merge pull request #11523 from edx/perf/speed-up-slow-user-role-ops"

This reverts commit acf6c1d6, reversing
changes made to c59db6e5.
parent a7a1affb
...@@ -233,7 +233,7 @@ class TestCourseIndex(CourseTestCase): ...@@ -233,7 +233,7 @@ class TestCourseIndex(CourseTestCase):
# delete nofications that are dismissed # delete nofications that are dismissed
CourseRerunState.objects.get(id=rerun_state.id) CourseRerunState.objects.get(id=rerun_state.id)
self.assertTrue(has_course_author_access(user2, rerun_course_key)) self.assertFalse(has_course_author_access(user2, rerun_course_key))
def assert_correct_json_response(self, json_response): def assert_correct_json_response(self, json_response):
""" """
......
...@@ -54,10 +54,6 @@ class RoleCache(object): ...@@ -54,10 +54,6 @@ class RoleCache(object):
for access_role in self._roles for access_role in self._roles
) )
def add_role(self, role):
"""Adds a role to the cache."""
self._roles.add(role)
class AccessRole(object): class AccessRole(object):
""" """
...@@ -66,7 +62,7 @@ class AccessRole(object): ...@@ -66,7 +62,7 @@ class AccessRole(object):
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def has_user(self, user, refresh=True): def has_user(self, user):
""" """
Return whether the supplied django user has access to this role. Return whether the supplied django user has access to this role.
""" """
...@@ -134,7 +130,7 @@ class RoleBase(AccessRole): ...@@ -134,7 +130,7 @@ class RoleBase(AccessRole):
self.course_key = course_key self.course_key = course_key
self._role_name = role_name self._role_name = role_name
def has_user(self, user, refresh=False): def has_user(self, user):
""" """
Return whether the supplied django user has access to this role. Return whether the supplied django user has access to this role.
""" """
...@@ -142,7 +138,7 @@ class RoleBase(AccessRole): ...@@ -142,7 +138,7 @@ class RoleBase(AccessRole):
return False return False
# pylint: disable=protected-access # pylint: disable=protected-access
if not hasattr(user, '_roles') or refresh: if not hasattr(user, '_roles'):
# Cache a list of tuples identifying the particular roles that a user has # 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 # Stored as tuples, rather than django models, to make it cheaper to construct objects for comparison
user._roles = RoleCache(user) user._roles = RoleCache(user)
...@@ -161,8 +157,7 @@ class RoleBase(AccessRole): ...@@ -161,8 +157,7 @@ class RoleBase(AccessRole):
entry = CourseAccessRole(user=user, role=self._role_name, course_id=self.course_key, org=self.org) entry = CourseAccessRole(user=user, role=self._role_name, course_id=self.course_key, org=self.org)
entry.save() entry.save()
if hasattr(user, '_roles'): if hasattr(user, '_roles'):
# pylint: disable=protected-access del user._roles
user._roles.add_role(entry)
def remove_users(self, *users): def remove_users(self, *users):
""" """
......
...@@ -36,6 +36,7 @@ from student.tests.factories import ( ...@@ -36,6 +36,7 @@ from student.tests.factories import (
from xmodule.x_module import XModuleMixin from xmodule.x_module import XModuleMixin
from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.tests.django_utils import ( from xmodule.modulestore.tests.django_utils import (
ModuleStoreTestCase, ModuleStoreTestCase,
SharedModuleStoreTestCase, SharedModuleStoreTestCase,
...@@ -219,7 +220,7 @@ class TestCoachDashboard(CcxTestCase, LoginEnrollmentTestCase): ...@@ -219,7 +220,7 @@ class TestCoachDashboard(CcxTestCase, LoginEnrollmentTestCase):
# assert ccx creator has role=ccx_coach # assert ccx creator has role=ccx_coach
role = CourseCcxCoachRole(course_key) role = CourseCcxCoachRole(course_key)
self.assertTrue(role.has_user(self.coach, refresh=True)) self.assertTrue(role.has_user(self.coach))
@ddt.data("CCX demo 1", "CCX demo 2", "CCX demo 3") @ddt.data("CCX demo 1", "CCX demo 2", "CCX demo 3")
def test_create_multiple_ccx(self, ccx_name): def test_create_multiple_ccx(self, ccx_name):
...@@ -712,28 +713,25 @@ def patched_get_children(self, usage_key_filter=None): ...@@ -712,28 +713,25 @@ def patched_get_children(self, usage_key_filter=None):
@override_settings(FIELD_OVERRIDE_PROVIDERS=( @override_settings(FIELD_OVERRIDE_PROVIDERS=(
'ccx.overrides.CustomCoursesForEdxOverrideProvider',)) 'ccx.overrides.CustomCoursesForEdxOverrideProvider',))
@patch('xmodule.x_module.XModuleMixin.get_children', patched_get_children, spec=True) @patch('xmodule.x_module.XModuleMixin.get_children', patched_get_children, spec=True)
class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase): class TestCCXGrades(SharedModuleStoreTestCase, LoginEnrollmentTestCase):
""" """
Tests for Custom Courses views. Tests for Custom Courses views.
""" """
MODULESTORE = TEST_DATA_SPLIT_MODULESTORE MODULESTORE = TEST_DATA_SPLIT_MODULESTORE
def setUp(self): @classmethod
""" def setUpClass(cls):
Set up tests super(TestCCXGrades, cls).setUpClass()
""" cls._course = course = CourseFactory.create(enable_ccx=True)
super(TestCCXGrades, self).setUp()
self._course = CourseFactory.create(enable_ccx=True)
# Create a course outline # Create a course outline
self.start = datetime.datetime( cls.mooc_start = start = datetime.datetime(
2010, 5, 12, 2, 42, tzinfo=pytz.UTC 2010, 5, 12, 2, 42, tzinfo=pytz.UTC
) )
chapter = ItemFactory.create( chapter = ItemFactory.create(
start=self.start, parent=self._course, category='sequential' start=start, parent=course, category='sequential'
) )
self.sections = [ cls.sections = sections = [
ItemFactory.create( ItemFactory.create(
parent=chapter, parent=chapter,
category="sequential", category="sequential",
...@@ -741,7 +739,7 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -741,7 +739,7 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
for _ in xrange(4) for _ in xrange(4)
] ]
# making problems available at class level for possible future use in tests # making problems available at class level for possible future use in tests
self.problems = [ cls.problems = [
[ [
ItemFactory.create( ItemFactory.create(
parent=section, parent=section,
...@@ -749,9 +747,15 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -749,9 +747,15 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
data=StringResponseXMLFactory().build_xml(answer='foo'), data=StringResponseXMLFactory().build_xml(answer='foo'),
metadata={'rerandomize': 'always'} metadata={'rerandomize': 'always'}
) for _ in xrange(4) ) for _ in xrange(4)
] for section in self.sections ] for section in sections
] ]
def setUp(self):
"""
Set up tests
"""
super(TestCCXGrades, self).setUp()
# Create instructor account # Create instructor account
self.coach = coach = AdminFactory.create() self.coach = coach = AdminFactory.create()
self.client.login(username=coach.username, password="test") self.client.login(username=coach.username, password="test")
...@@ -824,18 +828,13 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase): ...@@ -824,18 +828,13 @@ class TestCCXGrades(ModuleStoreTestCase, LoginEnrollmentTestCase):
rows = response.content.strip().split('\r') rows = response.content.strip().split('\r')
headers = rows[0] headers = rows[0]
records = dict() # picking first student records
for i in range(1, len(rows)): data = dict(zip(headers.strip().split(','), rows[1].strip().split(',')))
data = dict(zip(headers.strip().split(','), rows[i].strip().split(','))) self.assertNotIn('HW 04', data)
records[data['username']] = data self.assertEqual(data['HW 01'], '0.75')
self.assertEqual(data['HW 02'], '0.5')
student_data = records[self.student.username] # pylint: disable=no-member self.assertEqual(data['HW 03'], '0.25')
self.assertEqual(data['HW Avg'], '0.5')
self.assertNotIn('HW 04', student_data)
self.assertEqual(student_data['HW 01'], '0.75')
self.assertEqual(student_data['HW 02'], '0.5')
self.assertEqual(student_data['HW 03'], '0.25')
self.assertEqual(student_data['HW Avg'], '0.5')
@patch('courseware.views.render_to_response', intercept_renderer) @patch('courseware.views.render_to_response', intercept_renderer)
def test_student_progress(self): def test_student_progress(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment