From 95ccc305946d2c9f80553570fd8d51821eaab7b3 Mon Sep 17 00:00:00 2001 From: Matthew Piatetsky Date: Thu, 21 Jun 2018 15:48:22 -0400 Subject: [PATCH] add forum roles to metadata --- .../tests/test_field_override_performance.py | 54 +++++++++---------- .../courseware/tests/test_course_info.py | 4 +- lms/djangoapps/courseware/tests/test_views.py | 12 ++--- lms/djangoapps/experiments/utils.py | 5 ++ lms/templates/user_metadata.html | 3 +- .../tests/views/test_course_home.py | 2 +- .../tests/views/test_course_updates.py | 2 +- 7 files changed, 44 insertions(+), 38 deletions(-) diff --git a/lms/djangoapps/ccx/tests/test_field_override_performance.py b/lms/djangoapps/ccx/tests/test_field_override_performance.py index af6c38494b..e9410a318d 100644 --- a/lms/djangoapps/ccx/tests/test_field_override_performance.py +++ b/lms/djangoapps/ccx/tests/test_field_override_performance.py @@ -236,18 +236,18 @@ class TestFieldOverrideMongoPerformance(FieldOverridePerformanceTestCase): # # of sql queries to default, # # of mongo queries, # ) - ('no_overrides', 1, True, False): (17, 1), - ('no_overrides', 2, True, False): (17, 1), - ('no_overrides', 3, True, False): (17, 1), - ('ccx', 1, True, False): (17, 1), - ('ccx', 2, True, False): (17, 1), - ('ccx', 3, True, False): (17, 1), - ('no_overrides', 1, False, False): (17, 1), - ('no_overrides', 2, False, False): (17, 1), - ('no_overrides', 3, False, False): (17, 1), - ('ccx', 1, False, False): (17, 1), - ('ccx', 2, False, False): (17, 1), - ('ccx', 3, False, False): (17, 1), + ('no_overrides', 1, True, False): (18, 1), + ('no_overrides', 2, True, False): (18, 1), + ('no_overrides', 3, True, False): (18, 1), + ('ccx', 1, True, False): (18, 1), + ('ccx', 2, True, False): (18, 1), + ('ccx', 3, True, False): (18, 1), + ('no_overrides', 1, False, False): (18, 1), + ('no_overrides', 2, False, False): (18, 1), + ('no_overrides', 3, False, False): (18, 1), + ('ccx', 1, False, False): (18, 1), + ('ccx', 2, False, False): (18, 1), + ('ccx', 3, False, False): (18, 1), } @@ -259,19 +259,19 @@ class TestFieldOverrideSplitPerformance(FieldOverridePerformanceTestCase): __test__ = True TEST_DATA = { - ('no_overrides', 1, True, False): (17, 3), - ('no_overrides', 2, True, False): (17, 3), - ('no_overrides', 3, True, False): (17, 3), - ('ccx', 1, True, False): (17, 3), - ('ccx', 2, True, False): (17, 3), - ('ccx', 3, True, False): (17, 3), - ('ccx', 1, True, True): (18, 3), - ('ccx', 2, True, True): (18, 3), - ('ccx', 3, True, True): (18, 3), - ('no_overrides', 1, False, False): (17, 3), - ('no_overrides', 2, False, False): (17, 3), - ('no_overrides', 3, False, False): (17, 3), - ('ccx', 1, False, False): (17, 3), - ('ccx', 2, False, False): (17, 3), - ('ccx', 3, False, False): (17, 3), + ('no_overrides', 1, True, False): (18, 3), + ('no_overrides', 2, True, False): (18, 3), + ('no_overrides', 3, True, False): (18, 3), + ('ccx', 1, True, False): (18, 3), + ('ccx', 2, True, False): (18, 3), + ('ccx', 3, True, False): (18, 3), + ('ccx', 1, True, True): (19, 3), + ('ccx', 2, True, True): (19, 3), + ('ccx', 3, True, True): (19, 3), + ('no_overrides', 1, False, False): (18, 3), + ('no_overrides', 2, False, False): (18, 3), + ('no_overrides', 3, False, False): (18, 3), + ('ccx', 1, False, False): (18, 3), + ('ccx', 2, False, False): (18, 3), + ('ccx', 3, False, False): (18, 3), } diff --git a/lms/djangoapps/courseware/tests/test_course_info.py b/lms/djangoapps/courseware/tests/test_course_info.py index 60fa76eef2..156a4c8119 100644 --- a/lms/djangoapps/courseware/tests/test_course_info.py +++ b/lms/djangoapps/courseware/tests/test_course_info.py @@ -431,7 +431,7 @@ class SelfPacedCourseInfoTestCase(LoginEnrollmentTestCase, SharedModuleStoreTest self.assertEqual(resp.status_code, 200) def test_num_queries_instructor_paced(self): - self.fetch_course_info_with_queries(self.instructor_paced_course, 27, 3) + self.fetch_course_info_with_queries(self.instructor_paced_course, 28, 3) def test_num_queries_self_paced(self): - self.fetch_course_info_with_queries(self.self_paced_course, 27, 3) + self.fetch_course_info_with_queries(self.self_paced_course, 28, 3) diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 1e3ecf2294..ec7ad6612d 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -202,8 +202,8 @@ class IndexQueryTestCase(ModuleStoreTestCase): NUM_PROBLEMS = 20 @ddt.data( - (ModuleStoreEnum.Type.mongo, 10, 146), - (ModuleStoreEnum.Type.split, 4, 146), + (ModuleStoreEnum.Type.mongo, 10, 147), + (ModuleStoreEnum.Type.split, 4, 147), ) @ddt.unpack def test_index_query_counts(self, store_type, expected_mongo_query_count, expected_mysql_query_count): @@ -1426,8 +1426,8 @@ class ProgressPageTests(ProgressPageBaseTests): self.assertContains(resp, u"Download Your Certificate") @ddt.data( - (True, 37), - (False, 36) + (True, 38), + (False, 37) ) @ddt.unpack def test_progress_queries_paced_courses(self, self_paced, query_count): @@ -1438,8 +1438,8 @@ class ProgressPageTests(ProgressPageBaseTests): @patch.dict(settings.FEATURES, {'ASSUME_ZERO_GRADE_IF_ABSENT_FOR_ALL_TESTS': False}) @ddt.data( - (False, 43, 27), - (True, 36, 23) + (False, 44, 28), + (True, 37, 24) ) @ddt.unpack def test_progress_queries(self, enable_waffle, initial, subsequent): diff --git a/lms/djangoapps/experiments/utils.py b/lms/djangoapps/experiments/utils.py index 9d09f0ea42..ff9ef1bee7 100644 --- a/lms/djangoapps/experiments/utils.py +++ b/lms/djangoapps/experiments/utils.py @@ -1,4 +1,5 @@ from student.models import CourseEnrollment +from django_comment_common.models import Role from courseware.access import has_staff_access_to_preview_mode from course_modes.models import ( get_cosmetic_verified_display_price @@ -60,6 +61,9 @@ def get_experiment_user_metadata_context(course, user): upgrade_link, upgrade_date = check_and_get_upgrade_link_and_date(user, enrollment, course) has_staff_access = has_staff_access_to_preview_mode(user, course) + forum_roles = [] + if user.is_authenticated: + forum_roles = list(Role.objects.filter(users=user, course_id=course.id).values_list('name').distinct()) return { 'upgrade_link': upgrade_link, @@ -72,4 +76,5 @@ def get_experiment_user_metadata_context(course, user): 'course_start': course.start, 'course_end': course.end, 'has_staff_access': has_staff_access, + 'forum_roles': forum_roles } diff --git a/lms/templates/user_metadata.html b/lms/templates/user_metadata.html index 681c8c66a6..88909da0ee 100644 --- a/lms/templates/user_metadata.html +++ b/lms/templates/user_metadata.html @@ -15,7 +15,8 @@ user_metadata = { 'upgrade_link', 'upgrade_price', 'pacing_type', - 'has_staff_access' + 'has_staff_access', + 'forum_roles' ) } diff --git a/openedx/features/course_experience/tests/views/test_course_home.py b/openedx/features/course_experience/tests/views/test_course_home.py index 4deaf83272..9598192f9b 100644 --- a/openedx/features/course_experience/tests/views/test_course_home.py +++ b/openedx/features/course_experience/tests/views/test_course_home.py @@ -175,7 +175,7 @@ class TestCourseHomePage(CourseHomePageTestCase): course_home_url(self.course) # Fetch the view and verify the query counts - with self.assertNumQueries(53, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST): + with self.assertNumQueries(54, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST): with check_mongo_calls(4): url = course_home_url(self.course) self.client.get(url) diff --git a/openedx/features/course_experience/tests/views/test_course_updates.py b/openedx/features/course_experience/tests/views/test_course_updates.py index 607cca19ed..30617d3a55 100644 --- a/openedx/features/course_experience/tests/views/test_course_updates.py +++ b/openedx/features/course_experience/tests/views/test_course_updates.py @@ -126,7 +126,7 @@ class TestCourseUpdatesPage(SharedModuleStoreTestCase): course_updates_url(self.course) # Fetch the view and verify that the query counts haven't changed - with self.assertNumQueries(33, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST): + with self.assertNumQueries(34, table_blacklist=QUERY_COUNT_TABLE_BLACKLIST): with check_mongo_calls(4): url = course_updates_url(self.course) self.client.get(url)