fix: fixed pylint warnings
This commit is contained in:
committed by
Kyle McCormick
parent
470be08a83
commit
95427251dc
@@ -87,7 +87,7 @@ class ProctoringExamSettingsTestMixin():
|
||||
class ProctoringExamSettingsGetTests(ProctoringExamSettingsTestMixin, ModuleStoreTestCase, APITestCase):
|
||||
""" Tests for proctored exam settings GETs """
|
||||
@classmethod
|
||||
def get_expected_response_data(cls, course, user):
|
||||
def get_expected_response_data(cls, course, user): # pylint: disable=unused-argument
|
||||
return {
|
||||
'proctored_exam_settings': {
|
||||
'enable_proctored_exams': course.enable_proctored_exams,
|
||||
|
||||
@@ -107,10 +107,13 @@ class ProctoredExamSettingsView(APIView):
|
||||
|
||||
def post(self, request, course_id):
|
||||
""" POST handler """
|
||||
serializer = ProctoredExamSettingsSerializer if request.user.is_staff else LimitedProctoredExamSettingsSerializer
|
||||
serializer = ProctoredExamSettingsSerializer if request.user.is_staff \
|
||||
else LimitedProctoredExamSettingsSerializer
|
||||
exam_config = serializer(data=request.data.get('proctored_exam_settings', {}))
|
||||
valid_request = exam_config.is_valid()
|
||||
if not request.user.is_staff and valid_request and ProctoredExamSettingsSerializer(data=request.data.get('proctored_exam_settings', {})).is_valid():
|
||||
if not request.user.is_staff and valid_request and ProctoredExamSettingsSerializer(
|
||||
data=request.data.get('proctored_exam_settings', {})
|
||||
).is_valid():
|
||||
return Response(status=status.HTTP_403_FORBIDDEN)
|
||||
|
||||
with modulestore().bulk_operations(CourseKey.from_string(course_id)):
|
||||
|
||||
@@ -5,7 +5,6 @@ import copy
|
||||
from uuid import uuid4
|
||||
from django.urls import reverse
|
||||
from django.contrib.sites.models import Site
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.http import urlencode
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APITestCase
|
||||
@@ -69,7 +68,7 @@ class SAMLProviderConfigTests(APITestCase):
|
||||
slug='edxSideTest',
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self): # pylint: disable=super-method-not-called
|
||||
set_jwt_cookie(self.client, self.user, [(ENTERPRISE_ADMIN_ROLE, ENTERPRISE_ID)])
|
||||
self.client.force_authenticate(user=self.user)
|
||||
|
||||
@@ -147,7 +146,9 @@ class SAMLProviderConfigTests(APITestCase):
|
||||
assert provider_config.country == SINGLE_PROVIDER_CONFIG_2['country']
|
||||
|
||||
# check association has also been created
|
||||
assert EnterpriseCustomerIdentityProvider.objects.filter(provider_id=convert_saml_slug_provider_id(provider_config.slug)).exists(), 'Cannot find EnterpriseCustomer-->SAMLProviderConfig association'
|
||||
assert EnterpriseCustomerIdentityProvider.objects.filter(
|
||||
provider_id=convert_saml_slug_provider_id(provider_config.slug)
|
||||
).exists(), 'Cannot find EnterpriseCustomer-->SAMLProviderConfig association'
|
||||
|
||||
def test_create_one_config_fail_non_existent_enterprise_uuid(self):
|
||||
"""
|
||||
@@ -164,7 +165,9 @@ class SAMLProviderConfigTests(APITestCase):
|
||||
assert SAMLProviderConfig.objects.count() == orig_count
|
||||
|
||||
# check association has NOT been created
|
||||
assert not EnterpriseCustomerIdentityProvider.objects.filter(provider_id=convert_saml_slug_provider_id(SINGLE_PROVIDER_CONFIG_2['slug'])).exists(), 'Did not expect to find EnterpriseCustomer-->SAMLProviderConfig association'
|
||||
assert not EnterpriseCustomerIdentityProvider.objects.filter(
|
||||
provider_id=convert_saml_slug_provider_id(SINGLE_PROVIDER_CONFIG_2['slug'])
|
||||
).exists(), 'Did not expect to find EnterpriseCustomer-->SAMLProviderConfig association'
|
||||
|
||||
def test_create_one_config_with_absent_enterprise_uuid(self):
|
||||
"""
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# pylint: disable=missing-module-docstring
|
||||
import copy
|
||||
import pytz
|
||||
from uuid import uuid4
|
||||
from datetime import datetime
|
||||
from django.contrib.sites.models import Site
|
||||
from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
from django.utils.http import urlencode
|
||||
from rest_framework import status
|
||||
@@ -72,7 +72,7 @@ class SAMLProviderDataTests(APITestCase):
|
||||
enterprise_customer_id=ENTERPRISE_ID
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self): # pylint: disable=super-method-not-called
|
||||
# a cookie with roles: [{enterprise_admin_role: ent_id}] will be
|
||||
# needed to rbac to authorize access for this view
|
||||
set_jwt_cookie(self.client, self.user, [(ENTERPRISE_ADMIN_ROLE, ENTERPRISE_ID)])
|
||||
@@ -102,7 +102,9 @@ class SAMLProviderDataTests(APITestCase):
|
||||
|
||||
assert response.status_code == status.HTTP_201_CREATED
|
||||
assert SAMLProviderData.objects.count() == (orig_count + 1)
|
||||
assert SAMLProviderData.objects.get(entity_id=SINGLE_PROVIDER_DATA_2['entity_id']).sso_url == SINGLE_PROVIDER_DATA_2['sso_url']
|
||||
assert SAMLProviderData.objects.get(
|
||||
entity_id=SINGLE_PROVIDER_DATA_2['entity_id']
|
||||
).sso_url == SINGLE_PROVIDER_DATA_2['sso_url']
|
||||
|
||||
def test_create_one_data_with_absent_enterprise_uuid(self):
|
||||
"""
|
||||
|
||||
@@ -16,7 +16,7 @@ class CourseBlockSerializer(serializers.Serializer):
|
||||
"""
|
||||
blocks = serializers.SerializerMethodField()
|
||||
|
||||
def get_blocks(self, block):
|
||||
def get_blocks(self, block): # pylint: disable=missing-function-docstring
|
||||
block_key = block['id']
|
||||
block_type = block['type']
|
||||
children = block.get('children', []) if block_type != 'sequential' else [] # Don't descend past sequential
|
||||
|
||||
@@ -17,7 +17,6 @@ from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
from lms.djangoapps.course_goals.models import CourseGoal
|
||||
from lms.djangoapps.course_goals.toggles import COURSE_GOALS_NUMBER_OF_DAYS_GOALS
|
||||
from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests
|
||||
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
|
||||
from openedx.features.course_experience import ENABLE_COURSE_GOALS
|
||||
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
@@ -189,7 +189,7 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
user=self.user,
|
||||
course_id=self.course.id,
|
||||
key='view-welcome-message',
|
||||
value=False if welcome_message_is_dismissed else True
|
||||
value=not welcome_message_is_dismissed
|
||||
)
|
||||
welcome_message_html = self.client.get(self.url).data['welcome_message_html']
|
||||
assert welcome_message_html == (None if welcome_message_is_dismissed else '<p>Welcome</p>')
|
||||
@@ -354,7 +354,9 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
self.course.course_visibility = course_visibility
|
||||
self.course = self.update_course(self.course, self.user.id)
|
||||
|
||||
self.store.create_item(self.user.id, self.course.id, 'course_info', 'handouts', fields={'data': '<p>Handouts</p>'})
|
||||
self.store.create_item(
|
||||
self.user.id, self.course.id, 'course_info', 'handouts', fields={'data': '<p>Handouts</p>'}
|
||||
)
|
||||
self.store.create_item(self.user.id, self.course.id, 'course_info', 'updates', fields={
|
||||
'items': [{
|
||||
'content': '<p>Welcome</p>',
|
||||
@@ -386,7 +388,14 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
CourseDurationLimitConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
|
||||
response = self.client.get(self.url)
|
||||
assert response.data['verified_mode'] == {'access_expiration_date': (enrollment.created + MIN_DURATION), 'currency': 'USD', 'currency_symbol': '$', 'price': 149, 'sku': 'ABCD1234', 'upgrade_url': '/dashboard'}
|
||||
assert response.data['verified_mode'] == {
|
||||
'access_expiration_date': (enrollment.created + MIN_DURATION),
|
||||
'currency': 'USD',
|
||||
'currency_symbol': '$',
|
||||
'price': 149,
|
||||
'sku': 'ABCD1234',
|
||||
'upgrade_url': '/dashboard'
|
||||
}
|
||||
|
||||
def test_hide_learning_sequences(self):
|
||||
"""
|
||||
@@ -416,7 +425,7 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
days_early_for_beta=None,
|
||||
sections=[],
|
||||
self_paced=False,
|
||||
course_visibility=CourseVisibility.PRIVATE
|
||||
course_visibility=CourseVisibility.PRIVATE # pylint: disable=protected-access
|
||||
)
|
||||
replace_course_outline(new_learning_seq_outline)
|
||||
response = self.client.get(self.url)
|
||||
@@ -425,7 +434,7 @@ class OutlineTabTestViews(BaseCourseHomeTests):
|
||||
|
||||
def test_user_has_passing_grade(self):
|
||||
CourseEnrollment.enroll(self.user, self.course.id)
|
||||
self.course._grading_policy['GRADE_CUTOFFS']['Pass'] = 0
|
||||
self.course._grading_policy['GRADE_CUTOFFS']['Pass'] = 0 # pylint: disable=protected-access
|
||||
self.update_course(self.course, self.user.id)
|
||||
CourseGradeFactory().update(self.user, self.course)
|
||||
response = self.client.get(self.url)
|
||||
|
||||
@@ -169,10 +169,10 @@ class OutlineTabView(RetrieveAPIView):
|
||||
|
||||
serializer_class = OutlineTabSerializer
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
def get(self, request, *args, **kwargs): # pylint: disable=too-many-statements
|
||||
course_key_string = kwargs.get('course_key_string')
|
||||
course_key = CourseKey.from_string(course_key_string)
|
||||
course_usage_key = modulestore().make_course_usage_key(course_key)
|
||||
course_usage_key = modulestore().make_course_usage_key(course_key) # pylint: disable=unused-variable
|
||||
|
||||
if course_home_legacy_is_active(course_key):
|
||||
raise Http404
|
||||
@@ -385,7 +385,7 @@ class OutlineTabView(RetrieveAPIView):
|
||||
@api_view(['POST'])
|
||||
@authentication_classes((JwtAuthentication,))
|
||||
@permission_classes((IsAuthenticated,))
|
||||
def dismiss_welcome_message(request):
|
||||
def dismiss_welcome_message(request): # pylint: disable=missing-function-docstring
|
||||
course_id = request.data.get('course_id', None)
|
||||
|
||||
# If body doesn't contain 'course_id', return 400 to client.
|
||||
@@ -402,14 +402,14 @@ def dismiss_welcome_message(request):
|
||||
dismiss_current_update_for_user(request, course)
|
||||
return Response({'message': _('Welcome message successfully dismissed.')})
|
||||
except Exception:
|
||||
raise UnableToDismissWelcomeMessage
|
||||
raise UnableToDismissWelcomeMessage # pylint: disable=raise-missing-from
|
||||
|
||||
|
||||
# Another version of this endpoint exists in ../course_goals/views.py
|
||||
@api_view(['POST'])
|
||||
@authentication_classes((JwtAuthentication, SessionAuthenticationAllowInactiveUser,))
|
||||
@permission_classes((IsAuthenticated,))
|
||||
def save_course_goal(request):
|
||||
def save_course_goal(request): # pylint: disable=missing-function-docstring
|
||||
course_id = request.data.get('course_id')
|
||||
goal_key = request.data.get('goal_key')
|
||||
days_per_week = request.data.get('days_per_week')
|
||||
@@ -431,7 +431,7 @@ def save_course_goal(request):
|
||||
'message': _('Course goal updated successfully.'),
|
||||
})
|
||||
except Exception:
|
||||
raise UnableToSaveCourseGoal
|
||||
raise UnableToSaveCourseGoal # pylint: disable=raise-missing-from
|
||||
|
||||
else:
|
||||
# If body doesn't contain 'goal', return 400 to client.
|
||||
@@ -445,7 +445,7 @@ def save_course_goal(request):
|
||||
'message': _('Course goal updated successfully.'),
|
||||
})
|
||||
except Exception:
|
||||
raise UnableToSaveCourseGoal
|
||||
raise UnableToSaveCourseGoal # pylint: disable=raise-missing-from
|
||||
|
||||
|
||||
@api_view(['POST'])
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# pylint: disable=missing-module-docstring
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# pylint: disable=missing-module-docstring
|
||||
import logging
|
||||
from typing import Dict
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from django.test.client import RequestFactory, Client
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth import get_user_model
|
||||
from unittest.mock import patch, Mock
|
||||
from pyquery import PyQuery as pq
|
||||
|
||||
@@ -51,6 +51,7 @@ METADATA = {
|
||||
CONTENT_GATING_PARTITION_ID: [CONTENT_TYPE_GATE_GROUP_IDS['full_access']]
|
||||
}
|
||||
}
|
||||
User = get_user_model()
|
||||
|
||||
|
||||
@patch("crum.get_current_request")
|
||||
@@ -113,7 +114,7 @@ def _assert_block_is_gated(block, is_gated, user, course, request_factory, has_u
|
||||
checkout_link = '#' if has_upgrade_link else None
|
||||
for content_getter in (_get_content_from_fragment, _get_content_from_lms_index):
|
||||
with patch.object(ContentTypeGatingPartition, '_get_checkout_link', return_value=checkout_link):
|
||||
content = content_getter(block, user.id, course, request_factory)
|
||||
content = content_getter(block, user.id, course, request_factory) # pylint: disable=no-value-for-parameter
|
||||
if is_gated:
|
||||
assert 'content-paywall' in content
|
||||
if has_upgrade_link:
|
||||
@@ -160,7 +161,7 @@ def _assert_block_is_empty(block, user_id, course, request_factory):
|
||||
@override_settings(FIELD_OVERRIDE_PROVIDERS=(
|
||||
'openedx.features.content_type_gating.field_override.ContentTypeGatingFieldOverride',
|
||||
))
|
||||
class TestProblemTypeAccess(SharedModuleStoreTestCase, MasqueradeMixin):
|
||||
class TestProblemTypeAccess(SharedModuleStoreTestCase, MasqueradeMixin): # pylint: disable=missing-class-docstring
|
||||
|
||||
PROBLEM_TYPES = ['problem', 'openassessment', 'drag-and-drop-v2', 'done', 'edx_sga']
|
||||
# 'html' is a component that just displays html, in these tests it is used to test that users who do not have access
|
||||
@@ -800,9 +801,13 @@ class TestConditionalContentAccess(TestConditionalContent):
|
||||
self.student_audit_b = self.student_b
|
||||
|
||||
# Create verified students
|
||||
self.student_verified_a = UserFactory.create(username='student_verified_a', email='student_verified_a@example.com')
|
||||
self.student_verified_a = UserFactory.create(
|
||||
username='student_verified_a', email='student_verified_a@example.com'
|
||||
)
|
||||
CourseEnrollmentFactory.create(user=self.student_verified_a, course_id=self.course.id, mode='verified')
|
||||
self.student_verified_b = UserFactory.create(username='student_verified_b', email='student_verified_b@example.com')
|
||||
self.student_verified_b = UserFactory.create(
|
||||
username='student_verified_b', email='student_verified_b@example.com'
|
||||
)
|
||||
CourseEnrollmentFactory.create(user=self.student_verified_b, course_id=self.course.id, mode='verified')
|
||||
|
||||
# Put students into content gating groups
|
||||
@@ -832,7 +837,8 @@ class TestConditionalContentAccess(TestConditionalContent):
|
||||
|
||||
def test_access_based_on_conditional_content(self):
|
||||
"""
|
||||
If a user is enrolled as an audit user they should not have access to graded problems, including conditional content.
|
||||
If a user is enrolled as an audit user they should not have access to graded problems,
|
||||
including conditional content.
|
||||
All paid type tracks should have access graded problems including conditional content.
|
||||
"""
|
||||
|
||||
@@ -892,7 +898,7 @@ class TestMessageDeduplication(ModuleStoreTestCase):
|
||||
self.request_factory = RequestFactory()
|
||||
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
|
||||
def _create_course(self):
|
||||
def _create_course(self): # pylint: disable=missing-function-docstring
|
||||
course = CourseFactory.create(run='test', display_name='test')
|
||||
CourseModeFactory.create(course_id=course.id, mode_slug='audit')
|
||||
CourseModeFactory.create(course_id=course.id, mode_slug='verified')
|
||||
@@ -1101,7 +1107,7 @@ class TestContentTypeGatingService(ModuleStoreTestCase):
|
||||
self.request_factory = RequestFactory()
|
||||
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
|
||||
def _create_course(self):
|
||||
def _create_course(self): # pylint: disable=missing-function-docstring
|
||||
course = CourseFactory.create(run='test', display_name='test')
|
||||
CourseModeFactory.create(course_id=course.id, mode_slug='audit')
|
||||
CourseModeFactory.create(course_id=course.id, mode_slug='verified')
|
||||
@@ -1150,10 +1156,14 @@ class TestContentTypeGatingService(ModuleStoreTestCase):
|
||||
)
|
||||
|
||||
# The method returns a content type gate for blocks that should be gated
|
||||
assert 'content-paywall' in ContentTypeGatingService()._content_type_gate_for_block(self.user, blocks_dict['graded_1'], course['course'].id).content
|
||||
assert 'content-paywall' in ContentTypeGatingService()._content_type_gate_for_block( # pylint: disable=protected-access
|
||||
self.user, blocks_dict['graded_1'], course['course'].id
|
||||
).content
|
||||
|
||||
# The method returns None for blocks that should not be gated
|
||||
assert ContentTypeGatingService()._content_type_gate_for_block(self.user, blocks_dict['not_graded_1'], course['course'].id) is None
|
||||
assert ContentTypeGatingService()._content_type_gate_for_block( # pylint: disable=protected-access
|
||||
self.user, blocks_dict['not_graded_1'], course['course'].id
|
||||
) is None
|
||||
|
||||
@patch.object(ContentTypeGatingService, '_get_user', return_value=UserFactory.build())
|
||||
def test_check_children_for_content_type_gating_paywall(self, mocked_user): # pylint: disable=unused-argument
|
||||
@@ -1173,7 +1183,9 @@ class TestContentTypeGatingService(ModuleStoreTestCase):
|
||||
)
|
||||
|
||||
# The method returns a content type gate for blocks that should be gated
|
||||
assert ContentTypeGatingService().check_children_for_content_type_gating_paywall(blocks_dict['vertical'], course['course'].id) is None
|
||||
assert ContentTypeGatingService().check_children_for_content_type_gating_paywall(
|
||||
blocks_dict['vertical'], course['course'].id
|
||||
) is None
|
||||
|
||||
blocks_dict['graded_1'] = ItemFactory.create(
|
||||
parent=blocks_dict['vertical'],
|
||||
@@ -1183,4 +1195,6 @@ class TestContentTypeGatingService(ModuleStoreTestCase):
|
||||
)
|
||||
|
||||
# The method returns None for blocks that should not be gated
|
||||
assert 'content-paywall' in ContentTypeGatingService().check_children_for_content_type_gating_paywall(blocks_dict['vertical'], course['course'].id)
|
||||
assert 'content-paywall' in ContentTypeGatingService().check_children_for_content_type_gating_paywall(
|
||||
blocks_dict['vertical'], course['course'].id
|
||||
)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# pylint: disable=missing-module-docstring
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -21,7 +22,7 @@ from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, U
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestContentTypeGatingConfig(CacheIsolationTestCase):
|
||||
class TestContentTypeGatingConfig(CacheIsolationTestCase): # pylint: disable=missing-class-docstring
|
||||
|
||||
ENABLED_CACHES = ['default']
|
||||
|
||||
@@ -107,7 +108,9 @@ class TestContentTypeGatingConfig(CacheIsolationTestCase):
|
||||
|
||||
course_key = self.course_overview.id
|
||||
|
||||
assert (not before_enabled) == ContentTypeGatingConfig.enabled_for_course(course_key=course_key, target_datetime=target_datetime)
|
||||
assert (not before_enabled) == ContentTypeGatingConfig.enabled_for_course(
|
||||
course_key=course_key, target_datetime=target_datetime
|
||||
)
|
||||
|
||||
@ddt.data(
|
||||
# Generate all combinations of setting each configuration level to True/False/None
|
||||
@@ -132,11 +135,17 @@ class TestContentTypeGatingConfig(CacheIsolationTestCase):
|
||||
site_values={'course_org_filter': non_test_course_disabled.org}
|
||||
)
|
||||
|
||||
ContentTypeGatingConfig.objects.create(course=non_test_course_enabled, enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
course=non_test_course_enabled, enabled=True, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
ContentTypeGatingConfig.objects.create(course=non_test_course_disabled, enabled=False)
|
||||
ContentTypeGatingConfig.objects.create(org=non_test_course_enabled.org, enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
org=non_test_course_enabled.org, enabled=True, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
ContentTypeGatingConfig.objects.create(org=non_test_course_disabled.org, enabled=False)
|
||||
ContentTypeGatingConfig.objects.create(site=non_test_site_cfg_enabled.site, enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
site=non_test_site_cfg_enabled.site, enabled=True, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
ContentTypeGatingConfig.objects.create(site=non_test_site_cfg_disabled.site, enabled=False)
|
||||
|
||||
# Set up test objects
|
||||
@@ -146,9 +155,15 @@ class TestContentTypeGatingConfig(CacheIsolationTestCase):
|
||||
)
|
||||
|
||||
ContentTypeGatingConfig.objects.create(enabled=global_setting, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(org=test_course.org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
org=test_course.org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
|
||||
all_settings = [global_setting, site_setting, org_setting, course_setting]
|
||||
expected_global_setting = self._resolve_settings([global_setting])
|
||||
@@ -169,21 +184,27 @@ class TestContentTypeGatingConfig(CacheIsolationTestCase):
|
||||
test_site_cfg = SiteConfigurationFactory.create(
|
||||
site_values={'course_org_filter': []}
|
||||
)
|
||||
ContentTypeGatingConfig.objects.create(site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
site=test_site_cfg.site, enabled=site_setting, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
|
||||
for org_setting in (True, False, None):
|
||||
test_org = f"{test_site_cfg.id}-{org_setting}"
|
||||
test_site_cfg.site_values['course_org_filter'].append(test_org)
|
||||
test_site_cfg.save()
|
||||
|
||||
ContentTypeGatingConfig.objects.create(org=test_org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
org=test_org, enabled=org_setting, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
|
||||
for course_setting in (True, False, None):
|
||||
test_course = CourseOverviewFactory.create(
|
||||
org=test_org,
|
||||
id=CourseLocator(test_org, 'test_course', f'run-{course_setting}')
|
||||
)
|
||||
ContentTypeGatingConfig.objects.create(course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1))
|
||||
ContentTypeGatingConfig.objects.create(
|
||||
course=test_course, enabled=course_setting, enabled_as_of=datetime(2018, 1, 1)
|
||||
)
|
||||
|
||||
with self.assertNumQueries(4):
|
||||
all_configs = ContentTypeGatingConfig.all_current_course_configs()
|
||||
@@ -194,9 +215,21 @@ class TestContentTypeGatingConfig(CacheIsolationTestCase):
|
||||
assert len(all_configs) == ((3 ** 4) + 1)
|
||||
|
||||
# Point-test some of the final configurations
|
||||
assert all_configs[CourseLocator('7-True', 'test_course', 'run-None')] == {'enabled': (True, Provenance.org), 'enabled_as_of': (datetime(2018, 1, 1, 0, tzinfo=pytz.UTC), Provenance.run), 'studio_override_enabled': (None, Provenance.default)}
|
||||
assert all_configs[CourseLocator('7-True', 'test_course', 'run-False')] == {'enabled': (False, Provenance.run), 'enabled_as_of': (datetime(2018, 1, 1, 0, tzinfo=pytz.UTC), Provenance.run), 'studio_override_enabled': (None, Provenance.default)}
|
||||
assert all_configs[CourseLocator('7-None', 'test_course', 'run-None')] == {'enabled': (True, Provenance.site), 'enabled_as_of': (datetime(2018, 1, 1, 0, tzinfo=pytz.UTC), Provenance.run), 'studio_override_enabled': (None, Provenance.default)}
|
||||
assert all_configs[CourseLocator('7-True', 'test_course', 'run-None')] == {
|
||||
'enabled': (True, Provenance.org),
|
||||
'enabled_as_of': (datetime(2018, 1, 1, 0, tzinfo=pytz.UTC), Provenance.run),
|
||||
'studio_override_enabled': (None, Provenance.default)
|
||||
}
|
||||
assert all_configs[CourseLocator('7-True', 'test_course', 'run-False')] == {
|
||||
'enabled': (False, Provenance.run),
|
||||
'enabled_as_of': (datetime(2018, 1, 1, 0, tzinfo=pytz.UTC), Provenance.run),
|
||||
'studio_override_enabled': (None, Provenance.default)
|
||||
}
|
||||
assert all_configs[CourseLocator('7-None', 'test_course', 'run-None')] == {
|
||||
'enabled': (True, Provenance.site),
|
||||
'enabled_as_of': (datetime(2018, 1, 1, 0, tzinfo=pytz.UTC), Provenance.run),
|
||||
'studio_override_enabled': (None, Provenance.default)
|
||||
}
|
||||
|
||||
def test_caching_global(self):
|
||||
global_config = ContentTypeGatingConfig(enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
# pylint: disable=missing-module-docstring
|
||||
from datetime import datetime
|
||||
from django.test import RequestFactory
|
||||
from unittest.mock import Mock, patch
|
||||
@@ -13,8 +14,8 @@ from openedx.core.djangoapps.content.course_overviews.tests.factories import Cou
|
||||
from xmodule.partitions.partitions import UserPartitionError
|
||||
|
||||
|
||||
class TestContentTypeGatingPartition(CacheIsolationTestCase):
|
||||
def setUp(self):
|
||||
class TestContentTypeGatingPartition(CacheIsolationTestCase): # pylint: disable=missing-class-docstring
|
||||
def setUp(self): # pylint: disable=super-method-not-called
|
||||
self.course_key = CourseKey.from_string('course-v1:test+course+key')
|
||||
CourseOverviewFactory.create(id=self.course_key)
|
||||
|
||||
@@ -25,7 +26,9 @@ class TestContentTypeGatingPartition(CacheIsolationTestCase):
|
||||
CourseModeFactory.create(course_id=mock_course.id, mode_slug='verified')
|
||||
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
|
||||
with patch('openedx.features.content_type_gating.partitions.ContentTypeGatingPartitionScheme.create_user_partition') as mock_create:
|
||||
with patch(
|
||||
'openedx.features.content_type_gating.partitions.ContentTypeGatingPartitionScheme.create_user_partition'
|
||||
) as mock_create:
|
||||
partition = create_content_gating_partition(mock_course)
|
||||
assert partition == mock_create.return_value
|
||||
|
||||
@@ -47,13 +50,17 @@ class TestContentTypeGatingPartition(CacheIsolationTestCase):
|
||||
mock_course = Mock(id=self.course_key, user_partitions={})
|
||||
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
|
||||
with patch('openedx.features.content_type_gating.partitions.UserPartition.get_scheme', side_effect=UserPartitionError):
|
||||
with patch(
|
||||
'openedx.features.content_type_gating.partitions.UserPartition.get_scheme', side_effect=UserPartitionError
|
||||
):
|
||||
partition = create_content_gating_partition(mock_course)
|
||||
|
||||
assert partition is None
|
||||
|
||||
def test_create_content_gating_partition_partition_id_used(self):
|
||||
mock_course = Mock(id=self.course_key, user_partitions={Mock(name='partition', id=CONTENT_GATING_PARTITION_ID): object()})
|
||||
mock_course = Mock(
|
||||
id=self.course_key, user_partitions={Mock(name='partition', id=CONTENT_GATING_PARTITION_ID): object()}
|
||||
)
|
||||
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
|
||||
with patch('openedx.features.content_type_gating.partitions.LOG') as mock_log:
|
||||
@@ -111,7 +118,9 @@ class TestContentTypeGatingPartition(CacheIsolationTestCase):
|
||||
):
|
||||
fragment = partition.access_denied_fragment(mock_block, global_staff, FULL_ACCESS, 'test_allowed_group')
|
||||
assert fragment is None
|
||||
message = partition.access_denied_message(mock_block.scope_ids.usage_id, global_staff, FULL_ACCESS, 'test_allowed_group')
|
||||
message = partition.access_denied_message(
|
||||
mock_block.scope_ids.usage_id, global_staff, FULL_ACCESS, 'test_allowed_group'
|
||||
)
|
||||
assert message is None
|
||||
|
||||
def test_access_denied_fragment_for_null_request(self):
|
||||
|
||||
@@ -6,7 +6,6 @@ import ddt
|
||||
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from unittest.mock import patch
|
||||
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
@@ -14,7 +13,6 @@ from common.djangoapps.util.testing import EventTestMixin
|
||||
from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin
|
||||
from lms.djangoapps.course_home_api.tests.utils import BaseCourseHomeTests
|
||||
from openedx.core.djangoapps.schedules.models import Schedule
|
||||
from openedx.core.djangoapps.schedules.tests.factories import ScheduleFactory
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
|
||||
@@ -23,7 +21,7 @@ class ResetCourseDeadlinesViewTests(EventTestMixin, BaseCourseHomeTests, Masquer
|
||||
"""
|
||||
Tests for reset deadlines endpoint.
|
||||
"""
|
||||
def setUp(self):
|
||||
def setUp(self): # pylint: disable=arguments-differ
|
||||
# Need to supply tracker name for the EventTestMixin. Also, EventTestMixin needs to come
|
||||
# first in class inheritance so the setUp call here appropriately works
|
||||
super().setUp('openedx.features.course_experience.api.v1.views.tracker')
|
||||
|
||||
51
pylintrc
51
pylintrc
@@ -72,10 +72,10 @@ persistent = yes
|
||||
load-plugins = edx_lint.pylint,pylint_django_settings,pylint_django,pylint_celery,pylint_pytest
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
enable =
|
||||
enable =
|
||||
blacklisted-name,
|
||||
line-too-long,
|
||||
|
||||
|
||||
abstract-class-instantiated,
|
||||
abstract-method,
|
||||
access-member-before-definition,
|
||||
@@ -212,7 +212,7 @@ enable =
|
||||
using-constant-test,
|
||||
yield-outside-function,
|
||||
zip-builtin-not-iterating,
|
||||
|
||||
|
||||
astroid-error,
|
||||
django-not-available-placeholder,
|
||||
django-not-available,
|
||||
@@ -220,20 +220,20 @@ enable =
|
||||
method-check-failed,
|
||||
parse-error,
|
||||
raw-checker-failed,
|
||||
|
||||
|
||||
empty-docstring,
|
||||
invalid-characters-in-docstring,
|
||||
missing-docstring,
|
||||
wrong-spelling-in-comment,
|
||||
wrong-spelling-in-docstring,
|
||||
|
||||
|
||||
unused-argument,
|
||||
unused-import,
|
||||
unused-variable,
|
||||
|
||||
|
||||
eval-used,
|
||||
exec-used,
|
||||
|
||||
|
||||
bad-classmethod-argument,
|
||||
bad-mcs-classmethod-argument,
|
||||
bad-mcs-method-argument,
|
||||
@@ -271,31 +271,31 @@ enable =
|
||||
unneeded-not,
|
||||
useless-else-on-loop,
|
||||
wrong-assert-type,
|
||||
|
||||
|
||||
deprecated-method,
|
||||
deprecated-module,
|
||||
|
||||
|
||||
too-many-boolean-expressions,
|
||||
too-many-nested-blocks,
|
||||
too-many-statements,
|
||||
|
||||
|
||||
wildcard-import,
|
||||
wrong-import-order,
|
||||
wrong-import-position,
|
||||
|
||||
|
||||
missing-final-newline,
|
||||
mixed-indentation,
|
||||
mixed-line-endings,
|
||||
trailing-newlines,
|
||||
trailing-whitespace,
|
||||
unexpected-line-ending-format,
|
||||
|
||||
|
||||
bad-inline-option,
|
||||
bad-option-value,
|
||||
deprecated-pragma,
|
||||
unrecognized-inline-option,
|
||||
useless-suppression,
|
||||
|
||||
|
||||
cmp-method,
|
||||
coerce-method,
|
||||
delslice-method,
|
||||
@@ -312,7 +312,7 @@ enable =
|
||||
rdiv-method,
|
||||
setslice-method,
|
||||
using-cmp-argument,
|
||||
disable =
|
||||
disable =
|
||||
bad-continuation,
|
||||
bad-indentation,
|
||||
consider-using-f-string,
|
||||
@@ -342,10 +342,10 @@ disable =
|
||||
unspecified-encoding,
|
||||
unused-wildcard-import,
|
||||
use-maxsplit-arg,
|
||||
|
||||
|
||||
feature-toggle-needs-doc,
|
||||
illegal-waffle-usage,
|
||||
|
||||
|
||||
apply-builtin,
|
||||
backtick,
|
||||
bad-python3-import,
|
||||
@@ -383,7 +383,7 @@ disable =
|
||||
unicode-builtin,
|
||||
unpacking-in-except,
|
||||
xrange-builtin,
|
||||
|
||||
|
||||
logging-fstring-interpolation,
|
||||
native-string,
|
||||
import-outside-toplevel,
|
||||
@@ -402,6 +402,11 @@ disable =
|
||||
consider-using-enumerate,
|
||||
no-member,
|
||||
consider-using-with,
|
||||
unspecified-encoding,
|
||||
unused-variable,
|
||||
unused-argument,
|
||||
unsubscriptable-object,
|
||||
abstract-method,
|
||||
|
||||
[REPORTS]
|
||||
output-format = text
|
||||
@@ -447,7 +452,7 @@ ignore-imports = no
|
||||
ignore-mixin-members = yes
|
||||
ignored-classes = SQLObject
|
||||
unsafe-load-any-extension = yes
|
||||
generated-members =
|
||||
generated-members =
|
||||
REQUEST,
|
||||
acl_users,
|
||||
aq_parent,
|
||||
@@ -473,7 +478,7 @@ generated-members =
|
||||
[VARIABLES]
|
||||
init-import = no
|
||||
dummy-variables-rgx = _|dummy|unused|.*_unused
|
||||
additional-builtins =
|
||||
additional-builtins =
|
||||
|
||||
[CLASSES]
|
||||
defining-attr-methods = __init__,__new__,setUp
|
||||
@@ -494,11 +499,11 @@ max-public-methods = 20
|
||||
|
||||
[IMPORTS]
|
||||
deprecated-modules = regsub,TERMIOS,Bastion,rexec
|
||||
import-graph =
|
||||
ext-import-graph =
|
||||
int-import-graph =
|
||||
import-graph =
|
||||
ext-import-graph =
|
||||
int-import-graph =
|
||||
|
||||
[EXCEPTIONS]
|
||||
overgeneral-exceptions = Exception
|
||||
|
||||
# 2fed80f910c79d220c5d11096f45b6038a989882
|
||||
# 045e411ce43073160332d49d161ef210bcf2329f
|
||||
|
||||
@@ -26,7 +26,9 @@ disable+ =
|
||||
consider-using-with,
|
||||
unspecified-encoding,
|
||||
unused-variable,
|
||||
unused-argument,
|
||||
unsubscriptable-object,
|
||||
abstract-method,
|
||||
|
||||
[BASIC]
|
||||
attr-rgx = [a-z_][a-z0-9_]{2,40}$
|
||||
|
||||
Reference in New Issue
Block a user