From 047a5f5f19db29a67c4626f3116dd01e6569e77a Mon Sep 17 00:00:00 2001 From: "M. Zulqarnain" Date: Mon, 8 Feb 2021 15:51:22 +0500 Subject: [PATCH] BOM-2319 : Pylint amnesty in openedx content apps (#26347) * pylint amnesty in openedx content apps Co-authored-by: Jawayria --- .../content/block_structure/admin.py | 2 +- .../content/block_structure/apps.py | 2 +- .../block_structure/block_structure.py | 20 +++---- .../content/block_structure/exceptions.py | 10 ++-- .../tests/test_generate_course_blocks.py | 2 +- .../content/block_structure/manager.py | 2 +- .../content/block_structure/models.py | 14 ++--- .../content/block_structure/store.py | 4 +- .../content/block_structure/tests/helpers.py | 8 +-- .../block_structure/tests/test_factory.py | 2 +- .../block_structure/tests/test_manager.py | 2 +- .../block_structure/tests/test_models.py | 6 +- .../block_structure/tests/test_signals.py | 2 +- .../block_structure/tests/test_store.py | 2 +- .../tests/test_transformer_registry.py | 8 +-- .../tests/test_transformers.py | 4 +- .../content/block_structure/transformer.py | 2 +- .../content/block_structure/transformers.py | 4 +- .../content/course_overviews/apps.py | 2 +- .../commands/generate_course_overview.py | 2 +- .../management/commands/simulate_publish.py | 14 ++--- .../tests/test_generate_course_overview.py | 2 +- .../commands/tests/test_simulate_publish.py | 4 +- .../content/course_overviews/models.py | 10 ++-- .../content/course_overviews/serializers.py | 2 +- .../content/course_overviews/signals.py | 2 +- .../content/course_overviews/tasks.py | 6 +- .../course_overviews/tests/factories.py | 4 +- .../course_overviews/tests/test_api.py | 2 +- .../tests/test_course_overviews.py | 2 +- .../tests/test_serializers.py | 2 +- .../course_overviews/tests/test_signals.py | 4 +- .../course_overviews/tests/test_tasks.py | 6 +- .../learning_sequences/api/__init__.py | 1 + .../learning_sequences/api/outlines.py | 12 ++-- .../learning_sequences/api/processors/base.py | 8 +-- .../api/processors/content_gating.py | 1 + .../api/processors/milestones.py | 3 +- .../api/processors/schedule.py | 7 ++- .../api/processors/special_exams.py | 2 +- .../learning_sequences/api/tests/test_data.py | 3 +- .../api/tests/test_outlines.py | 60 +++++++++---------- .../content/learning_sequences/apps.py | 3 +- .../content/learning_sequences/data.py | 8 +-- .../content/learning_sequences/models.py | 2 +- .../learning_sequences/tests/test_views.py | 8 +-- .../content/learning_sequences/urls.py | 1 + .../content/learning_sequences/views.py | 14 ++--- .../core/djangoapps/content_libraries/api.py | 6 +- .../content_libraries/library_bundle.py | 2 +- .../content_libraries/library_context.py | 4 +- .../commands/reindex_content_library.py | 2 +- .../djangoapps/content_libraries/models.py | 6 +- .../content_libraries/permissions.py | 2 +- .../content_libraries/serializers.py | 2 +- .../tests/test_content_libraries.py | 2 +- .../content_libraries/tests/test_runtime.py | 4 +- .../djangoapps/content_libraries/views.py | 32 +++++----- .../core/djangoapps/contentserver/__init__.py | 2 +- .../djangoapps/contentserver/middleware.py | 6 +- .../contentserver/test/test_contentserver.py | 14 ++--- .../djangoapps/cors_csrf/authentication.py | 2 +- .../core/djangoapps/cors_csrf/middleware.py | 6 +- .../cors_csrf/tests/test_authentication.py | 2 +- .../cors_csrf/tests/test_decorators.py | 2 +- .../cors_csrf/tests/test_middleware.py | 6 +- .../djangoapps/cors_csrf/tests/test_views.py | 2 +- 67 files changed, 202 insertions(+), 195 deletions(-) diff --git a/openedx/core/djangoapps/content/block_structure/admin.py b/openedx/core/djangoapps/content/block_structure/admin.py index e3279c4c76..48c328bce6 100644 --- a/openedx/core/djangoapps/content/block_structure/admin.py +++ b/openedx/core/djangoapps/content/block_structure/admin.py @@ -17,7 +17,7 @@ class BlockStructureAdmin(ConfigurationModelAdmin): """ Excludes unused 'enabled field from super's list. """ - displayable_field_names = super(BlockStructureAdmin, self).get_displayable_field_names() + displayable_field_names = super(BlockStructureAdmin, self).get_displayable_field_names() # lint-amnesty, pylint: disable=super-with-arguments displayable_field_names.remove('enabled') return displayable_field_names diff --git a/openedx/core/djangoapps/content/block_structure/apps.py b/openedx/core/djangoapps/content/block_structure/apps.py index 48338f0d5f..23116e1fc7 100644 --- a/openedx/core/djangoapps/content/block_structure/apps.py +++ b/openedx/core/djangoapps/content/block_structure/apps.py @@ -21,4 +21,4 @@ class BlockStructureConfig(AppConfig): These happen at import time. Hence the unused imports """ - from . import signals, tasks # pylint: disable=unused-variable + from . import signals, tasks # lint-amnesty, pylint: disable=unused-import, unused-variable diff --git a/openedx/core/djangoapps/content/block_structure/block_structure.py b/openedx/core/djangoapps/content/block_structure/block_structure.py index c3568d3563..af2f3474cb 100644 --- a/openedx/core/djangoapps/content/block_structure/block_structure.py +++ b/openedx/core/djangoapps/content/block_structure/block_structure.py @@ -299,21 +299,21 @@ class FieldData(object): def __getattr__(self, field_name): if self._is_own_field(field_name): - return super(FieldData, self).__getattr__(field_name) + return super(FieldData, self).__getattr__(field_name) # lint-amnesty, pylint: disable=no-member, super-with-arguments try: return self.fields[field_name] except KeyError: - raise AttributeError(u"Field {0} does not exist".format(field_name)) + raise AttributeError(u"Field {0} does not exist".format(field_name)) # lint-amnesty, pylint: disable=raise-missing-from def __setattr__(self, field_name, field_value): if self._is_own_field(field_name): - return super(FieldData, self).__setattr__(field_name, field_value) + return super(FieldData, self).__setattr__(field_name, field_value) # lint-amnesty, pylint: disable=super-with-arguments else: self.fields[field_name] = field_value def __delattr__(self, field_name): if self._is_own_field(field_name): - return super(FieldData, self).__delattr__(field_name) + return super(FieldData, self).__delattr__(field_name) # lint-amnesty, pylint: disable=super-with-arguments else: del self.fields[field_name] @@ -329,7 +329,7 @@ class TransformerData(FieldData): """ Data structure to encapsulate collected data for a transformer. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class TransformerDataMap(dict): @@ -383,10 +383,10 @@ class BlockData(FieldData): Data structure to encapsulate collected data for a single block. """ def class_field_names(self): - return super(BlockData, self).class_field_names() + ['location', 'transformer_data'] + return super(BlockData, self).class_field_names() + ['location', 'transformer_data'] # lint-amnesty, pylint: disable=super-with-arguments def __init__(self, usage_key): - super(BlockData, self).__init__() + super(BlockData, self).__init__() # lint-amnesty, pylint: disable=super-with-arguments # Location (or usage key) of the block. self.location = usage_key @@ -407,7 +407,7 @@ class BlockStructureBlockData(BlockStructure): VERSION = 2 def __init__(self, root_block_usage_key): - super(BlockStructureBlockData, self).__init__(root_block_usage_key) + super(BlockStructureBlockData, self).__init__(root_block_usage_key) # lint-amnesty, pylint: disable=super-with-arguments # Map of a block's usage key to its collected data, including # its xBlock fields and block-specific transformer data. @@ -750,7 +750,7 @@ class BlockStructureBlockData(BlockStructure): its current version number. """ if transformer.WRITE_VERSION == 0: - raise TransformerException(u'Version attributes are not set on transformer {0}.', transformer.name()) + raise TransformerException(u'Version attributes are not set on transformer {0}.', transformer.name()) # lint-amnesty, pylint: disable=raising-format-tuple self.set_transformer_data(transformer, TRANSFORMER_VERSION_KEY, transformer.WRITE_VERSION) def _get_or_create_block(self, usage_key): @@ -778,7 +778,7 @@ class BlockStructureModulestoreData(BlockStructureBlockData): interface and implementation of an xBlock. """ def __init__(self, root_block_usage_key): - super(BlockStructureModulestoreData, self).__init__(root_block_usage_key) + super(BlockStructureModulestoreData, self).__init__(root_block_usage_key) # lint-amnesty, pylint: disable=super-with-arguments # Map of a block's usage key to its instantiated xBlock. # dict {UsageKey: XBlock} diff --git a/openedx/core/djangoapps/content/block_structure/exceptions.py b/openedx/core/djangoapps/content/block_structure/exceptions.py index 750ac7a8f0..61e0356567 100644 --- a/openedx/core/djangoapps/content/block_structure/exceptions.py +++ b/openedx/core/djangoapps/content/block_structure/exceptions.py @@ -7,21 +7,21 @@ class BlockStructureException(Exception): """ Base class for all Block Structure framework exceptions. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class TransformerException(BlockStructureException): """ Exception class for Transformer related errors. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class UsageKeyNotInBlockStructure(BlockStructureException): """ Exception for when a usage key is not found within a block structure. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class TransformerDataIncompatible(BlockStructureException): @@ -29,7 +29,7 @@ class TransformerDataIncompatible(BlockStructureException): Exception for when the version of a Transformer's data is not compatible with the current version of the Transformer. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class BlockStructureNotFound(BlockStructureException): @@ -37,6 +37,6 @@ class BlockStructureNotFound(BlockStructureException): Exception for when a Block Structure is not found. """ def __init__(self, root_block_usage_key): - super(BlockStructureNotFound, self).__init__( + super(BlockStructureNotFound, self).__init__( # lint-amnesty, pylint: disable=super-with-arguments u'Block structure not found; data_usage_key: {}'.format(root_block_usage_key) ) diff --git a/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py b/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py index 150962713d..2c61c8f9b7 100644 --- a/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py +++ b/openedx/core/djangoapps/content/block_structure/management/commands/tests/test_generate_course_blocks.py @@ -32,7 +32,7 @@ class TestGenerateCourseBlocks(ModuleStoreTestCase): """ Create courses in modulestore. """ - super(TestGenerateCourseBlocks, self).setUp() + super(TestGenerateCourseBlocks, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.courses = [CourseFactory.create() for _ in range(self.num_courses)] self.course_keys = [course.id for course in self.courses] self.command = generate_course_blocks.Command() diff --git a/openedx/core/djangoapps/content/block_structure/manager.py b/openedx/core/djangoapps/content/block_structure/manager.py index 63aa2fe3a6..5e95129253 100644 --- a/openedx/core/djangoapps/content/block_structure/manager.py +++ b/openedx/core/djangoapps/content/block_structure/manager.py @@ -71,7 +71,7 @@ class BlockStructureManager(object): # requested location. The rest of the structure will be pruned # as part of the transformation. if starting_block_usage_key not in block_structure: - raise UsageKeyNotInBlockStructure( + raise UsageKeyNotInBlockStructure( # lint-amnesty, pylint: disable=raising-format-tuple u"The requested usage_key '{0}' is not found in the block_structure with root '{1}'", six.text_type(starting_block_usage_key), six.text_type(self.root_block_usage_key), diff --git a/openedx/core/djangoapps/content/block_structure/models.py b/openedx/core/djangoapps/content/block_structure/models.py index f04f97dba5..d92767e5c7 100644 --- a/openedx/core/djangoapps/content/block_structure/models.py +++ b/openedx/core/djangoapps/content/block_structure/models.py @@ -102,10 +102,10 @@ class CustomizableFileField(models.FileField): storage=_bs_model_storage(), max_length=500, # allocate enough for base path + prefix + usage_key + timestamp in filepath )) - super(CustomizableFileField, self).__init__(*args, **kwargs) + super(CustomizableFileField, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments - def deconstruct(self): - name, path, args, kwargs = super(CustomizableFileField, self).deconstruct() + def deconstruct(self): # lint-amnesty, pylint: disable=missing-function-docstring + name, path, args, kwargs = super(CustomizableFileField, self).deconstruct() # lint-amnesty, pylint: disable=super-with-arguments del kwargs['upload_to'] del kwargs['storage'] del kwargs['max_length'] @@ -136,13 +136,13 @@ def _storage_error_handling(bs_model, operation, is_read_operation=False): yield except Exception as error: # pylint: disable=broad-except log.exception(u'BlockStructure: Exception %s on store %s; %s.', error.__class__, operation, bs_model) - if isinstance(error, OSError) and error.errno in (errno.EACCES, errno.EPERM): # pylint: disable=no-member + if isinstance(error, OSError) and error.errno in (errno.EACCES, errno.EPERM): # lint-amnesty, pylint: disable=no-else-raise, no-member raise elif is_read_operation and isinstance(error, (IOError, SuspiciousOperation)): # May have been caused by one of the possible error # situations listed above. Raise BlockStructureNotFound # so the block structure can be regenerated and restored. - raise BlockStructureNotFound(bs_model.data_usage_key) + raise BlockStructureNotFound(bs_model.data_usage_key) # lint-amnesty, pylint: disable=raise-missing-from else: raise @@ -216,7 +216,7 @@ class BlockStructureModel(TimeStampedModel): return cls.objects.get(data_usage_key=data_usage_key) except cls.DoesNotExist: log.info(u'BlockStructure: Not found in table; %s.', data_usage_key) - raise BlockStructureNotFound(data_usage_key) + raise BlockStructureNotFound(data_usage_key) # lint-amnesty, pylint: disable=raise-missing-from @classmethod def update_or_create(cls, serialized_data, data_usage_key, **kwargs): @@ -263,7 +263,7 @@ class BlockStructureModel(TimeStampedModel): try: all_files_by_date = sorted(cls._get_all_files(data_usage_key)) - files_to_delete = all_files_by_date[:-num_to_keep] if num_to_keep > 0 else all_files_by_date + files_to_delete = all_files_by_date[:-num_to_keep] if num_to_keep > 0 else all_files_by_date # lint-amnesty, pylint: disable=invalid-unary-operand-type cls._delete_files(files_to_delete) log.info( u'BlockStructure: Deleted %d out of total %d files in store; data_usage_key: %s, num_to_keep: %d.', diff --git a/openedx/core/djangoapps/content/block_structure/store.py b/openedx/core/djangoapps/content/block_structure/store.py index df1a23144b..cd249c9179 100644 --- a/openedx/core/djangoapps/content/block_structure/store.py +++ b/openedx/core/djangoapps/content/block_structure/store.py @@ -39,7 +39,7 @@ class StubModel(object): """ Noop delete method. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class BlockStructureStore(object): @@ -216,7 +216,7 @@ class BlockStructureStore(object): # Somehow failed to de-serialized the data, assume it's corrupt. bs_model = self._get_model(root_block_usage_key) logger.exception(u"BlockStructure: Failed to load data from cache for %s", bs_model) - raise BlockStructureNotFound(bs_model.data_usage_key) + raise BlockStructureNotFound(bs_model.data_usage_key) # lint-amnesty, pylint: disable=raise-missing-from return BlockStructureFactory.create_new( root_block_usage_key, diff --git a/openedx/core/djangoapps/content/block_structure/tests/helpers.py b/openedx/core/djangoapps/content/block_structure/tests/helpers.py index d7750da7b8..effe8ef1ce 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/helpers.py +++ b/openedx/core/djangoapps/content/block_structure/tests/helpers.py @@ -63,7 +63,7 @@ class MockXBlock(object): try: return self.field_map[attr] except KeyError: - raise AttributeError + raise AttributeError # lint-amnesty, pylint: disable=raise-missing-from def get_children(self): """ @@ -211,7 +211,7 @@ def clear_registered_transformers_cache(): """ Test helper to clear out any cached values of registered transformers. """ - TransformerRegistry.get_write_version_hash.cache.clear() + TransformerRegistry.get_write_version_hash.cache.clear() # lint-amnesty, pylint: disable=no-member @contextmanager @@ -224,7 +224,7 @@ def mock_registered_transformers(transformers): 'openedx.core.djangoapps.content.block_structure.transformer_registry.' 'TransformerRegistry.get_registered_transformers' ) as mock_available_transforms: - mock_available_transforms.return_value = {transformer for transformer in transformers} + mock_available_transforms.return_value = {transformer for transformer in transformers} # lint-amnesty, pylint: disable=unnecessary-comprehension yield @@ -336,7 +336,7 @@ class UsageKeyFactoryMixin(object): ChildrenMapTestMixin use integers for block_ids. """ def setUp(self): - super(UsageKeyFactoryMixin, self).setUp() + super(UsageKeyFactoryMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_key = CourseLocator('org', 'course', six.text_type(uuid4())) def block_key_factory(self, block_id): diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_factory.py b/openedx/core/djangoapps/content/block_structure/tests/test_factory.py index a79171e180..d2a8db4fb1 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_factory.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_factory.py @@ -19,7 +19,7 @@ class TestBlockStructureFactory(TestCase, ChildrenMapTestMixin): """ def setUp(self): - super(TestBlockStructureFactory, self).setUp() + super(TestBlockStructureFactory, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.children_map = self.SIMPLE_CHILDREN_MAP self.modulestore = MockModulestoreFactory.create(self.children_map, self.block_key_factory) diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_manager.py b/openedx/core/djangoapps/content/block_structure/tests/test_manager.py index 1c0d921426..7fca176020 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_manager.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_manager.py @@ -102,7 +102,7 @@ class TestBlockStructureManager(UsageKeyFactoryMixin, ChildrenMapTestMixin, Test """ def setUp(self): - super(TestBlockStructureManager, self).setUp() + super(TestBlockStructureManager, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments TestTransformer1.collect_call_count = 0 self.registered_transformers = [TestTransformer1()] diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_models.py b/openedx/core/djangoapps/content/block_structure/tests/test_models.py index 6e614874ea..81b4dd4f65 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_models.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_models.py @@ -28,7 +28,7 @@ class BlockStructureModelTestCase(TestCase): Tests for BlockStructureModel. """ def setUp(self): - super(BlockStructureModelTestCase, self).setUp() + super(BlockStructureModelTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_key = CourseLocator('org', 'course', six.text_type(uuid4())) self.usage_key = BlockUsageLocator(course_key=self.course_key, block_type='course', block_id='course') @@ -36,7 +36,7 @@ class BlockStructureModelTestCase(TestCase): def tearDown(self): BlockStructureModel._prune_files(self.usage_key, num_to_keep=0) - super(BlockStructureModelTestCase, self).tearDown() + super(BlockStructureModelTestCase, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments def _assert_bsm_fields(self, bsm, expected_serialized_data): """ @@ -161,7 +161,7 @@ class BlockStructureModelTestCase(TestCase): bs_model, _ = BlockStructureModel.update_or_create('test data', **self.params) with self.assertRaises(expected_error_raised): with _storage_error_handling(bs_model, 'operation', is_read_operation): - if errno_raised is not None: + if errno_raised is not None: # lint-amnesty, pylint: disable=no-else-raise raise error_raised_in_operation(errno_raised, message_raised) else: raise error_raised_in_operation diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py index 99e3db6a61..33801db2da 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_signals.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_signals.py @@ -25,7 +25,7 @@ class CourseBlocksSignalTest(ModuleStoreTestCase): ENABLED_SIGNALS = ['course_deleted', 'course_published'] def setUp(self): - super(CourseBlocksSignalTest, self).setUp() + super(CourseBlocksSignalTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course = CourseFactory.create() self.course_usage_key = self.store.make_course_usage_key(self.course.id) diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_store.py b/openedx/core/djangoapps/content/block_structure/tests/test_store.py index ef35a70139..7f1869bf02 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_store.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_store.py @@ -23,7 +23,7 @@ class TestBlockStructureStore(UsageKeyFactoryMixin, ChildrenMapTestMixin, CacheI ENABLED_CACHES = ['default'] def setUp(self): - super(TestBlockStructureStore, self).setUp() + super(TestBlockStructureStore, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.children_map = self.SIMPLE_CHILDREN_MAP self.block_structure = self.create_block_structure(self.children_map) diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_transformer_registry.py b/openedx/core/djangoapps/content/block_structure/tests/test_transformer_registry.py index 2f46bb34b9..214e95e51d 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_transformer_registry.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_transformer_registry.py @@ -15,21 +15,21 @@ class TestTransformer1(MockTransformer): """ 1st test instance of the MockTransformer that is registered. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class TestTransformer2(MockTransformer): """ 2nd test instance of the MockTransformer that is registered. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass class UnregisteredTestTransformer3(MockTransformer): """ 3rd test instance of the MockTransformer that is not registered. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass @ddt.ddt @@ -39,7 +39,7 @@ class TransformerRegistryTestCase(TestCase): """ def tearDown(self): - super(TransformerRegistryTestCase, self).tearDown() + super(TransformerRegistryTestCase, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments clear_registered_transformers_cache() @ddt.data( diff --git a/openedx/core/djangoapps/content/block_structure/tests/test_transformers.py b/openedx/core/djangoapps/content/block_structure/tests/test_transformers.py index 7cfbbdc2e2..48e3a0d670 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/test_transformers.py +++ b/openedx/core/djangoapps/content/block_structure/tests/test_transformers.py @@ -22,10 +22,10 @@ class TestBlockStructureTransformers(ChildrenMapTestMixin, TestCase): """ Mock transformer that is not registered. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass def setUp(self): - super(TestBlockStructureTransformers, self).setUp() + super(TestBlockStructureTransformers, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.transformers = BlockStructureTransformers(usage_info=MagicMock()) self.registered_transformers = [MockTransformer(), MockFilteringTransformer()] diff --git a/openedx/core/djangoapps/content/block_structure/transformer.py b/openedx/core/djangoapps/content/block_structure/transformer.py index 31099a4a41..c63f2b082c 100644 --- a/openedx/core/djangoapps/content/block_structure/transformer.py +++ b/openedx/core/djangoapps/content/block_structure/transformer.py @@ -106,7 +106,7 @@ class BlockStructureTransformer(object): block structure that is to be modified with collected data to be cached for the transformer. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass @abstractmethod def transform(self, usage_info, block_structure): diff --git a/openedx/core/djangoapps/content/block_structure/transformers.py b/openedx/core/djangoapps/content/block_structure/transformers.py index 4c535e8e5e..a8ad687123 100644 --- a/openedx/core/djangoapps/content/block_structure/transformers.py +++ b/openedx/core/djangoapps/content/block_structure/transformers.py @@ -3,7 +3,7 @@ Module for a collection of BlockStructureTransformers. """ -import functools +import functools # lint-amnesty, pylint: disable=unused-import from logging import getLogger from .exceptions import TransformerDataIncompatible, TransformerException @@ -100,7 +100,7 @@ class BlockStructureTransformers(object): outdated_transformers.append(transformer) if outdated_transformers: - raise TransformerDataIncompatible( + raise TransformerDataIncompatible( # lint-amnesty, pylint: disable=raising-format-tuple u"Collected Block Structure data for the following transformers is outdated: '%s'.", [(transformer.name(), transformer.READ_VERSION) for transformer in outdated_transformers], ) diff --git a/openedx/core/djangoapps/content/course_overviews/apps.py b/openedx/core/djangoapps/content/course_overviews/apps.py index 82c04a0d19..d7976cf219 100644 --- a/openedx/core/djangoapps/content/course_overviews/apps.py +++ b/openedx/core/djangoapps/content/course_overviews/apps.py @@ -16,4 +16,4 @@ class CourseOverviewsConfig(AppConfig): def ready(self): # Import signals to activate signal handler which invalidates # the CourseOverview cache every time a course is published. - from . import signals # pylint: disable=unused-variable + from . import signals # lint-amnesty, pylint: disable=unused-import, unused-variable diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/generate_course_overview.py b/openedx/core/djangoapps/content/course_overviews/management/commands/generate_course_overview.py index aa42b5c11b..d235a07c85 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/generate_course_overview.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/generate_course_overview.py @@ -73,4 +73,4 @@ class Command(BaseCommand): **kwargs ) except InvalidKeyError as exc: - raise CommandError(u'Invalid Course Key: ' + six.text_type(exc)) + raise CommandError(u'Invalid Course Key: ' + six.text_type(exc)) # lint-amnesty, pylint: disable=raise-missing-from diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/simulate_publish.py b/openedx/core/djangoapps/content/course_overviews/management/commands/simulate_publish.py index 5250ef5ca8..d132cc74c7 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/simulate_publish.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/simulate_publish.py @@ -86,7 +86,7 @@ class Command(BaseCommand): dest='show_receivers', action='store_true', help=(u'Display the list of possible receiver functions and exit.') - ), + ), # lint-amnesty, pylint: disable=trailing-comma-tuple parser.add_argument( '--dry-run', dest='dry_run', @@ -96,7 +96,7 @@ class Command(BaseCommand): u"expensive modulestore query to find courses, but it will " u"not emit any signals." ) - ), + ), # lint-amnesty, pylint: disable=trailing-comma-tuple parser.add_argument( '--receivers', dest='receivers', @@ -142,7 +142,7 @@ class Command(BaseCommand): u"process. However, if you know what you're doing and need to " u"override that behavior, use this flag." ) - ), + ), # lint-amnesty, pylint: disable=trailing-comma-tuple parser.add_argument( '--skip-ccx', dest='skip_ccx', @@ -156,12 +156,12 @@ class Command(BaseCommand): u"if you know what you're doing, you can disable this behavior " u"with this flag, so that CCX receivers are omitted." ) - ), + ), # lint-amnesty, pylint: disable=trailing-comma-tuple parser.add_argument( '--args-from-database', action='store_true', help='Use arguments from the SimulateCoursePublishConfig model instead of the command line.', - ), + ), # lint-amnesty, pylint: disable=trailing-comma-tuple def get_args_from_database(self): """ Returns an options dictionary from the current SimulateCoursePublishConfig model. """ @@ -194,7 +194,7 @@ class Command(BaseCommand): if options['force_lms']: log.info("Forcing simulate_publish to run in LMS process.") else: - log.fatal( + log.fatal( # lint-amnesty, pylint: disable=logging-not-lazy u"simulate_publish should be run as a CMS (Studio) " + u"command, not %s (override with --force-lms).", os.environ.get('SERVICE_VARIANT') @@ -245,7 +245,7 @@ class Command(BaseCommand): log.info(u"%d receivers specified: %s", len(receiver_names), ", ".join(receiver_names)) receiver_names_set = set(receiver_names) for receiver_fn in get_receiver_fns(): - if receiver_fn == ccx_receiver_fn and not skip_ccx: + if receiver_fn == ccx_receiver_fn and not skip_ccx: # lint-amnesty, pylint: disable=comparison-with-callable continue fn_name = name_from_fn(receiver_fn) if fn_name not in receiver_names_set: diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py b/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py index 6caab5297a..7c15e158e5 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_generate_course_overview.py @@ -22,7 +22,7 @@ class TestGenerateCourseOverview(ModuleStoreTestCase): """ Create courses in modulestore. """ - super(TestGenerateCourseOverview, self).setUp() + super(TestGenerateCourseOverview, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_key_1 = CourseFactory.create().id self.course_key_2 = CourseFactory.create().id self.command = generate_course_overview.Command() diff --git a/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_simulate_publish.py b/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_simulate_publish.py index 103201fded..1be962f1a1 100644 --- a/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_simulate_publish.py +++ b/openedx/core/djangoapps/content/course_overviews/management/commands/tests/test_simulate_publish.py @@ -47,7 +47,7 @@ class TestSimulatePublish(SharedModuleStoreTestCase): might look like you can move this to setUpClass, but be very careful if doing so, to make sure side-effects don't leak out between tests. """ - super(TestSimulatePublish, self).setUp() + super(TestSimulatePublish, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # Instead of using the process global SignalHandler.course_published, we # create our own SwitchedSignal to manually send to. @@ -79,7 +79,7 @@ class TestSimulatePublish(SharedModuleStoreTestCase): ) Command.course_published_signal.disconnect(self.sample_receiver_1) Command.course_published_signal.disconnect(self.sample_receiver_2) - super(TestSimulatePublish, self).tearDown() + super(TestSimulatePublish, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments def options(self, **kwargs): """ diff --git a/openedx/core/djangoapps/content/course_overviews/models.py b/openedx/core/djangoapps/content/course_overviews/models.py index 61eb0cd3b9..bab37b1e9e 100644 --- a/openedx/core/djangoapps/content/course_overviews/models.py +++ b/openedx/core/djangoapps/content/course_overviews/models.py @@ -131,7 +131,7 @@ class CourseOverview(TimeStampedModel): history = HistoricalRecords() @classmethod - def _create_or_update(cls, course): + def _create_or_update(cls, course): # lint-amnesty, pylint: disable=too-many-statements """ Creates or updates a CourseOverview object from a CourseDescriptor. @@ -184,7 +184,7 @@ class CourseOverview(TimeStampedModel): course_overview.version = cls.VERSION course_overview.id = course.id - course_overview._location = course.location + course_overview._location = course.location # lint-amnesty, pylint: disable=protected-access course_overview.org = course.location.org course_overview.display_name = display_name course_overview.display_number_with_default = course.display_number_with_default @@ -215,7 +215,7 @@ class CourseOverview(TimeStampedModel): course_overview.days_early_for_beta = course.days_early_for_beta course_overview.mobile_available = course.mobile_available course_overview.visible_to_staff_only = course.visible_to_staff_only - course_overview._pre_requisite_courses_json = json.dumps(course.pre_requisite_courses) + course_overview._pre_requisite_courses_json = json.dumps(course.pre_requisite_courses) # lint-amnesty, pylint: disable=protected-access course_overview.enrollment_start = course.enrollment_start course_overview.enrollment_end = course.enrollment_end @@ -306,7 +306,7 @@ class CourseOverview(TimeStampedModel): return course_overview elif course is not None: - raise IOError( + raise IOError( # lint-amnesty, pylint: disable=raising-format-tuple "Error while loading CourseOverview for course {} " "from the module store: {}", six.text_type(course_id), @@ -592,7 +592,7 @@ class CourseOverview(TimeStampedModel): cause a lot of issues. These should not be mutable after construction, so for now we just eat this. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass @classmethod def update_select_courses(cls, course_keys, force_update=False): diff --git a/openedx/core/djangoapps/content/course_overviews/serializers.py b/openedx/core/djangoapps/content/course_overviews/serializers.py index 8e79d25e68..4559de94e9 100644 --- a/openedx/core/djangoapps/content/course_overviews/serializers.py +++ b/openedx/core/djangoapps/content/course_overviews/serializers.py @@ -17,7 +17,7 @@ class CourseOverviewBaseSerializer(serializers.ModelSerializer): fields = '__all__' def to_representation(self, instance): - representation = super(CourseOverviewBaseSerializer, self).to_representation(instance) + representation = super(CourseOverviewBaseSerializer, self).to_representation(instance) # lint-amnesty, pylint: disable=super-with-arguments representation['display_name_with_default'] = instance.display_name_with_default representation['has_started'] = instance.has_started() representation['has_ended'] = instance.has_ended() diff --git a/openedx/core/djangoapps/content/course_overviews/signals.py b/openedx/core/djangoapps/content/course_overviews/signals.py index 1ce66e3b0d..474391c4eb 100644 --- a/openedx/core/djangoapps/content/course_overviews/signals.py +++ b/openedx/core/djangoapps/content/course_overviews/signals.py @@ -62,7 +62,7 @@ def _check_for_course_date_changes(previous_course_overview, updated_course_over ) -def _log_start_date_change(previous_course_overview, updated_course_overview): +def _log_start_date_change(previous_course_overview, updated_course_overview): # lint-amnesty, pylint: disable=missing-function-docstring previous_start_str = 'None' if previous_course_overview.start is not None: previous_start_str = previous_course_overview.start.isoformat() diff --git a/openedx/core/djangoapps/content/course_overviews/tasks.py b/openedx/core/djangoapps/content/course_overviews/tasks.py index fd9e0e9387..0516078923 100644 --- a/openedx/core/djangoapps/content/course_overviews/tasks.py +++ b/openedx/core/djangoapps/content/course_overviews/tasks.py @@ -1,4 +1,4 @@ - +# lint-amnesty, pylint: disable=missing-module-docstring import logging @@ -27,7 +27,7 @@ def chunks(sequence, chunk_size): return (sequence[index: index + chunk_size] for index in range(0, len(sequence), chunk_size)) -def _task_options(routing_key): +def _task_options(routing_key): # lint-amnesty, pylint: disable=missing-function-docstring task_options = {} if getattr(settings, 'HIGH_MEM_QUEUE', None): task_options['routing_key'] = settings.HIGH_MEM_QUEUE @@ -36,7 +36,7 @@ def _task_options(routing_key): return task_options -def enqueue_async_course_overview_update_tasks( +def enqueue_async_course_overview_update_tasks( # lint-amnesty, pylint: disable=missing-function-docstring course_ids, all_courses=False, force_update=False, diff --git a/openedx/core/djangoapps/content/course_overviews/tests/factories.py b/openedx/core/djangoapps/content/course_overviews/tests/factories.py index 8ade26bb10..5e6a758b78 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/factories.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/factories.py @@ -1,4 +1,4 @@ - +# lint-amnesty, pylint: disable=missing-module-docstring from datetime import timedelta import json @@ -11,7 +11,7 @@ from opaque_keys.edx.locator import CourseLocator from ..models import CourseOverview -class CourseOverviewFactory(DjangoModelFactory): +class CourseOverviewFactory(DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring class Meta(object): model = CourseOverview django_get_or_create = ('id', ) diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_api.py b/openedx/core/djangoapps/content/course_overviews/tests/test_api.py index 0735151fb2..452c263c4e 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_api.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_api.py @@ -16,7 +16,7 @@ class TestCourseOverviewsApi(TestCase): """ def setUp(self): - super(TestCourseOverviewsApi, self).setUp() + super(TestCourseOverviewsApi, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments for _ in range(3): CourseOverviewFactory.create() diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py b/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py index 96eb908749..86709ebe54 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_course_overviews.py @@ -605,7 +605,7 @@ class CourseOverviewImageSetTestCase(ModuleStoreTestCase): def setUp(self): """Create an active CourseOverviewImageConfig with non-default values.""" self.set_config(True) - super(CourseOverviewImageSetTestCase, self).setUp() + super(CourseOverviewImageSetTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments def _create_course_image(self, course, image_name): """ diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_serializers.py b/openedx/core/djangoapps/content/course_overviews/tests/test_serializers.py index 7dc5d6c1d0..87347038c9 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_serializers.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_serializers.py @@ -16,7 +16,7 @@ class TestCourseOverviewSerializer(TestCase): """ def setUp(self): - super(TestCourseOverviewSerializer, self).setUp() + super(TestCourseOverviewSerializer, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments CourseOverviewFactory.create() def test_get_course_overview_serializer(self): diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py b/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py index 7849a9d36f..37e9763ea9 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_signals.py @@ -1,4 +1,4 @@ - +# lint-amnesty, pylint: disable=missing-module-docstring import datetime @@ -70,7 +70,7 @@ class CourseOverviewSignalsTestCase(ModuleStoreTestCase): self.store.delete_course(course.id, ModuleStoreEnum.UserID.test) CourseOverview.get_from_id(course.id) - def assert_changed_signal_sent(self, field_name, initial_value, changed_value, mock_signal): + def assert_changed_signal_sent(self, field_name, initial_value, changed_value, mock_signal): # lint-amnesty, pylint: disable=missing-function-docstring course = CourseFactory.create(emit_signals=True, **{field_name: initial_value}) # changing display name doesn't fire the signal diff --git a/openedx/core/djangoapps/content/course_overviews/tests/test_tasks.py b/openedx/core/djangoapps/content/course_overviews/tests/test_tasks.py index 336ad2dcfe..ebb3f27914 100644 --- a/openedx/core/djangoapps/content/course_overviews/tests/test_tasks.py +++ b/openedx/core/djangoapps/content/course_overviews/tests/test_tasks.py @@ -1,4 +1,4 @@ - +# lint-amnesty, pylint: disable=missing-module-docstring import mock import six @@ -10,9 +10,9 @@ from xmodule.modulestore.tests.factories import CourseFactory from ..tasks import enqueue_async_course_overview_update_tasks -class BatchedAsyncCourseOverviewUpdateTests(ModuleStoreTestCase): +class BatchedAsyncCourseOverviewUpdateTests(ModuleStoreTestCase): # lint-amnesty, pylint: disable=missing-class-docstring def setUp(self): - super(BatchedAsyncCourseOverviewUpdateTests, self).setUp() + super(BatchedAsyncCourseOverviewUpdateTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.course_1 = CourseFactory.create(default_store=ModuleStoreEnum.Type.mongo) self.course_2 = CourseFactory.create(default_store=ModuleStoreEnum.Type.mongo) self.course_3 = CourseFactory.create(default_store=ModuleStoreEnum.Type.mongo) diff --git a/openedx/core/djangoapps/content/learning_sequences/api/__init__.py b/openedx/core/djangoapps/content/learning_sequences/api/__init__.py index 9436136139..e64f8bc293 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/__init__.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/__init__.py @@ -1,3 +1,4 @@ +# lint-amnesty, pylint: disable=missing-module-docstring from .outlines import ( get_course_outline, get_user_course_outline, diff --git a/openedx/core/djangoapps/content/learning_sequences/api/outlines.py b/openedx/core/djangoapps/content/learning_sequences/api/outlines.py index 71c1ed49f6..764a000af1 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/outlines.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/outlines.py @@ -6,14 +6,14 @@ __init__.py imports from here, and is a more stable place to import from. import logging from collections import defaultdict from datetime import datetime -from typing import Optional +from typing import Optional # lint-amnesty, pylint: disable=unused-import -import attr +import attr # lint-amnesty, pylint: disable=unused-import from django.contrib.auth import get_user_model from django.db import transaction -from edx_django_utils.cache import TieredCache, get_cache_key +from edx_django_utils.cache import TieredCache, get_cache_key # lint-amnesty, pylint: disable=unused-import from edx_django_utils.monitoring import function_trace -from opaque_keys.edx.keys import CourseKey, UsageKey +from opaque_keys.edx.keys import CourseKey, UsageKey # lint-amnesty, pylint: disable=unused-import from ..data import ( CourseLearningSequenceData, @@ -153,7 +153,7 @@ def _get_course_context_for_outline(course_key: CourseKey) -> CourseContext: ) except LearningContext.DoesNotExist: # Could happen if it hasn't been published. - raise CourseOutlineData.DoesNotExist( + raise CourseOutlineData.DoesNotExist( # lint-amnesty, pylint: disable=raise-missing-from "No CourseOutlineData for {}".format(course_key) ) return course_context @@ -197,7 +197,7 @@ def get_user_course_outline_details(course_key: CourseKey, ) -def _get_user_course_outline_and_processors(course_key: CourseKey, +def _get_user_course_outline_and_processors(course_key: CourseKey, # lint-amnesty, pylint: disable=missing-function-docstring user: User, at_time: datetime): full_course_outline = get_course_outline(course_key) diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/base.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/base.py index af98cb984c..773e8b0ed4 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/base.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/base.py @@ -6,7 +6,7 @@ import logging from datetime import datetime from django.contrib.auth import get_user_model -from opaque_keys.edx.keys import CourseKey, UsageKey +from opaque_keys.edx.keys import CourseKey, UsageKey # lint-amnesty, pylint: disable=unused-import User = get_user_model() log = logging.getLogger(__name__) @@ -57,9 +57,9 @@ class OutlineProcessor: tens of milliseconds, even on courses with hundreds of learning sequences. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass - def inaccessible_sequences(self, full_course_outline): + def inaccessible_sequences(self, full_course_outline): # lint-amnesty, pylint: disable=unused-argument """ Return a set/frozenset of Sequence UsageKeys that are not accessible. @@ -68,7 +68,7 @@ class OutlineProcessor: """ return frozenset() - def usage_keys_to_remove(self, full_course_outline): + def usage_keys_to_remove(self, full_course_outline): # lint-amnesty, pylint: disable=unused-argument """ Return a set/frozenset of UsageKeys to remove altogether. diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/content_gating.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/content_gating.py index e327856230..0d779161d5 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/content_gating.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/content_gating.py @@ -1,3 +1,4 @@ +# lint-amnesty, pylint: disable=missing-module-docstring import logging from datetime import datetime diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/milestones.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/milestones.py index d99398a102..03f8763faa 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/milestones.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/milestones.py @@ -1,7 +1,8 @@ +# lint-amnesty, pylint: disable=missing-module-docstring import logging from django.contrib.auth import get_user_model -from opaque_keys.edx.keys import CourseKey +from opaque_keys.edx.keys import CourseKey # lint-amnesty, pylint: disable=unused-import from common.djangoapps.util import milestones_helpers from .base import OutlineProcessor diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/schedule.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/schedule.py index 5d2a437383..156202a68a 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/schedule.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/schedule.py @@ -1,10 +1,11 @@ +# lint-amnesty, pylint: disable=missing-module-docstring import logging -from collections import defaultdict, OrderedDict +from collections import defaultdict, OrderedDict # lint-amnesty, pylint: disable=unused-import from datetime import datetime, timedelta from django.contrib.auth import get_user_model from edx_when.api import get_dates_for_course -from opaque_keys.edx.keys import CourseKey, UsageKey +from opaque_keys.edx.keys import CourseKey, UsageKey # lint-amnesty, pylint: disable=unused-import from common.djangoapps.student.auth import user_has_role from common.djangoapps.student.roles import CourseBetaTesterRole @@ -119,7 +120,7 @@ class ScheduleOutlineProcessor(OutlineProcessor): specified_dates = [date for date in dates if date is not None] return max(specified_dates) if specified_dates else None - pruned_section_keys = {section.usage_key for section in pruned_course_outline.sections} + pruned_section_keys = {section.usage_key for section in pruned_course_outline.sections} # lint-amnesty, pylint: disable=unused-variable course_usage_key = self.course_key.make_usage_key('course', 'course') course_start = self.keys_to_schedule_fields[course_usage_key].get('start') course_end = self.keys_to_schedule_fields[course_usage_key].get('end') diff --git a/openedx/core/djangoapps/content/learning_sequences/api/processors/special_exams.py b/openedx/core/djangoapps/content/learning_sequences/api/processors/special_exams.py index ee656ab24c..67d4ad8350 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/processors/special_exams.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/processors/special_exams.py @@ -32,7 +32,7 @@ class SpecialExamsOutlineProcessor(OutlineProcessor): """ Check if special exams are enabled """ - self.special_exams_enabled = settings.FEATURES.get('ENABLE_SPECIAL_EXAMS', False) + self.special_exams_enabled = settings.FEATURES.get('ENABLE_SPECIAL_EXAMS', False) # lint-amnesty, pylint: disable=attribute-defined-outside-init def exam_data(self, pruned_course_outline: UserCourseOutlineData) -> SpecialExamAttemptData: """ diff --git a/openedx/core/djangoapps/content/learning_sequences/api/tests/test_data.py b/openedx/core/djangoapps/content/learning_sequences/api/tests/test_data.py index 47ed7d2579..d242a061cc 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/tests/test_data.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/tests/test_data.py @@ -1,3 +1,4 @@ +# lint-amnesty, pylint: disable=missing-module-docstring from datetime import datetime, timezone from unittest import TestCase @@ -22,7 +23,7 @@ class TestCourseOutlineData(TestCase): test as needed. """ super().setUpClass() - normal_visibility = VisibilityData( + normal_visibility = VisibilityData( # lint-amnesty, pylint: disable=unused-variable hide_from_toc=False, visible_to_staff_only=False ) diff --git a/openedx/core/djangoapps/content/learning_sequences/api/tests/test_outlines.py b/openedx/core/djangoapps/content/learning_sequences/api/tests/test_outlines.py index d30a4e2af4..b4a0209ec7 100644 --- a/openedx/core/djangoapps/content/learning_sequences/api/tests/test_outlines.py +++ b/openedx/core/djangoapps/content/learning_sequences/api/tests/test_outlines.py @@ -7,18 +7,18 @@ from mock import patch import attr from django.conf import settings -from django.contrib.auth.models import AnonymousUser, User +from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user from edx_proctoring.exceptions import ProctoredExamNotFoundException from edx_when.api import set_dates_for_course -from opaque_keys.edx.keys import CourseKey, UsageKey -from opaque_keys.edx.locator import BlockUsageLocator +from opaque_keys.edx.keys import CourseKey, UsageKey # lint-amnesty, pylint: disable=unused-import +from opaque_keys.edx.locator import BlockUsageLocator # lint-amnesty, pylint: disable=unused-import from edx_toggles.toggles.testutils import override_waffle_flag from lms.djangoapps.courseware.tests.factories import BetaTesterFactory from openedx.core.djangolib.testing.utils import CacheIsolationTestCase from openedx.features.course_experience import COURSE_ENABLE_UNENROLLED_ACCESS_FLAG from common.djangoapps.student.auth import user_has_role -from common.djangoapps.student.models import CourseEnrollment +from common.djangoapps.student.models import CourseEnrollment # lint-amnesty, pylint: disable=unused-import from common.djangoapps.student.roles import CourseBetaTesterRole from ...data import ( @@ -43,9 +43,9 @@ class CourseOutlineTestCase(CacheIsolationTestCase): Simple tests around reading and writing CourseOutlineData. No user info. """ @classmethod - def setUpTestData(cls): + def setUpTestData(cls): # lint-amnesty, pylint: disable=super-method-not-called cls.course_key = CourseKey.from_string("course-v1:OpenEdX+Learn+Roundtrip") - normal_visibility = VisibilityData( + normal_visibility = VisibilityData( # lint-amnesty, pylint: disable=unused-variable hide_from_toc=False, visible_to_staff_only=False ) @@ -65,12 +65,12 @@ class CourseOutlineTestCase(CacheIsolationTestCase): """Don't allow Old Mongo Courses at all.""" old_course_key = CourseKey.from_string("Org/Course/Run") with self.assertRaises(ValueError): - outline = get_course_outline(old_course_key) + outline = get_course_outline(old_course_key) # lint-amnesty, pylint: disable=unused-variable def test_simple_roundtrip(self): """Happy path for writing/reading-back a course outline.""" with self.assertRaises(CourseOutlineData.DoesNotExist): - course_outline = get_course_outline(self.course_key) + course_outline = get_course_outline(self.course_key) # lint-amnesty, pylint: disable=unused-variable replace_course_outline(self.course_outline) outline = get_course_outline(self.course_key) @@ -120,8 +120,8 @@ class CourseOutlineTestCase(CacheIsolationTestCase): # Make sure this new outline is returned instead of the previously # cached one. with self.assertNumQueries(3): - uncached_new_version_outline = get_course_outline(self.course_key) - assert new_version_outline == new_version_outline + uncached_new_version_outline = get_course_outline(self.course_key) # lint-amnesty, pylint: disable=unused-variable + assert new_version_outline == new_version_outline # lint-amnesty, pylint: disable=comparison-with-itself class UserCourseOutlineTestCase(CacheIsolationTestCase): @@ -130,7 +130,7 @@ class UserCourseOutlineTestCase(CacheIsolationTestCase): """ @classmethod - def setUpTestData(cls): + def setUpTestData(cls): # lint-amnesty, pylint: disable=super-method-not-called course_key = CourseKey.from_string("course-v1:OpenEdX+Outline+T1") # Users... cls.global_staff = User.objects.create_user( @@ -194,9 +194,9 @@ class UserCourseOutlineTestCase(CacheIsolationTestCase): assert global_staff_outline_details.outline == global_staff_outline -class OutlineProcessorTestCase(CacheIsolationTestCase): +class OutlineProcessorTestCase(CacheIsolationTestCase): # lint-amnesty, pylint: disable=missing-class-docstring @classmethod - def setUpTestData(cls): + def setUpTestData(cls): # lint-amnesty, pylint: disable=super-method-not-called cls.course_key = CourseKey.from_string("course-v1:OpenEdX+Outline+T1") # Users... @@ -221,7 +221,7 @@ class OutlineProcessorTestCase(CacheIsolationTestCase): def set_sequence_keys(cls, keys): cls.all_seq_keys = keys - def get_sequence_keys(self, exclude=None): + def get_sequence_keys(self, exclude=None): # lint-amnesty, pylint: disable=missing-function-docstring if exclude is None: exclude = [] if not isinstance(exclude, list): @@ -346,10 +346,10 @@ class ContentGatingTestCase(OutlineProcessorTestCase): """ Currently returns all, and only, sequences in required content, not just the first. This logic matches the existing transformer. Is this right? - """ + """ # lint-amnesty, pylint: disable=pointless-string-statement - @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.content_gating.EntranceExamConfiguration.user_can_skip_entrance_exam') - @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.content_gating.milestones_helpers.get_required_content') + @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.content_gating.EntranceExamConfiguration.user_can_skip_entrance_exam') # lint-amnesty, pylint: disable=line-too-long + @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.content_gating.milestones_helpers.get_required_content') # lint-amnesty, pylint: disable=line-too-long def test_user_can_skip_entrance_exam(self, required_content_mock, user_can_skip_entrance_exam_mock): required_content_mock.return_value = [str(self.entrance_exam_section_key)] user_can_skip_entrance_exam_mock.return_value = True @@ -363,8 +363,8 @@ class ContentGatingTestCase(OutlineProcessorTestCase): # Student can access all sequences assert len(student_details.outline.accessible_sequences) == 3 - @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.content_gating.EntranceExamConfiguration.user_can_skip_entrance_exam') - @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.content_gating.milestones_helpers.get_required_content') + @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.content_gating.EntranceExamConfiguration.user_can_skip_entrance_exam') # lint-amnesty, pylint: disable=line-too-long + @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.content_gating.milestones_helpers.get_required_content') # lint-amnesty, pylint: disable=line-too-long def test_user_can_not_skip_entrance_exam(self, required_content_mock, user_can_skip_entrance_exam_mock): required_content_mock.return_value = [str(self.entrance_exam_section_key)] user_can_skip_entrance_exam_mock.return_value = False @@ -460,7 +460,7 @@ class MilestonesTestCase(OutlineProcessorTestCase): # Enroll student in the course cls.student.courseenrollment_set.create(course_id=cls.course_key, is_active=True, mode="audit") - @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.milestones.milestones_helpers.get_course_content_milestones') + @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.milestones.milestones_helpers.get_course_content_milestones') # lint-amnesty, pylint: disable=line-too-long def test_user_can_skip_entrance_exam(self, get_course_content_milestones_mock): # Only return that there are milestones required for the # milestones_required_seq_key usage key @@ -763,7 +763,7 @@ class ScheduleTestCase(OutlineProcessorTestCase): assert len(beta_tester_details.outline.accessible_sequences) == 4 -class SelfPacedTestCase(OutlineProcessorTestCase): +class SelfPacedTestCase(OutlineProcessorTestCase): # lint-amnesty, pylint: disable=missing-class-docstring @classmethod def setUpTestData(cls): @@ -844,7 +844,7 @@ class SelfPacedTestCase(OutlineProcessorTestCase): cls.student.courseenrollment_set.create(course_id=cls.course_key, is_active=True, mode="audit") def test_sequences_accessible_after_due(self): - at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) + at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) # lint-amnesty, pylint: disable=unused-variable staff_details, student_details, _ = self.get_details( datetime(2020, 5, 25, tzinfo=timezone.utc) @@ -859,7 +859,7 @@ class SelfPacedTestCase(OutlineProcessorTestCase): assert len(student_details.outline.accessible_sequences) == 2 -class SpecialExamsTestCase(OutlineProcessorTestCase): +class SpecialExamsTestCase(OutlineProcessorTestCase): # lint-amnesty, pylint: disable=missing-class-docstring @classmethod def setUpTestData(cls): @@ -964,7 +964,7 @@ class SpecialExamsTestCase(OutlineProcessorTestCase): @patch.dict(settings.FEATURES, {'ENABLE_SPECIAL_EXAMS': True}) def test_special_exams_enabled_all_sequences_visible(self): - at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) + at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) # lint-amnesty, pylint: disable=unused-variable staff_details, student_details, _ = self.get_details( datetime(2020, 5, 25, tzinfo=timezone.utc) @@ -980,7 +980,7 @@ class SpecialExamsTestCase(OutlineProcessorTestCase): @patch.dict(settings.FEATURES, {'ENABLE_SPECIAL_EXAMS': False}) def test_special_exams_disabled_preserves_exam_sequences(self): - at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) + at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) # lint-amnesty, pylint: disable=unused-variable staff_details, student_details, _ = self.get_details( datetime(2020, 5, 25, tzinfo=timezone.utc) @@ -1000,7 +1000,7 @@ class SpecialExamsTestCase(OutlineProcessorTestCase): @patch.dict(settings.FEATURES, {'ENABLE_SPECIAL_EXAMS': True}) @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.special_exams.get_attempt_status_summary') def test_special_exam_attempt_data_in_details(self, mock_get_attempt_status_summary): - at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) + at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) # lint-amnesty, pylint: disable=unused-variable def get_attempt_status_side_effect(user_id, _course_key, usage_key): """ @@ -1011,7 +1011,7 @@ class SpecialExamsTestCase(OutlineProcessorTestCase): for sequence_key in self.get_sequence_keys(exclude=[self.seq_normal_key]): if usage_key == str(sequence_key): - num_fake_attempts = mock_get_attempt_status_summary.call_count % len(self.all_seq_keys) + num_fake_attempts = mock_get_attempt_status_summary.call_count % len(self.all_seq_keys) # lint-amnesty, pylint: disable=unused-variable return { "summary": { "usage_key": usage_key @@ -1028,13 +1028,13 @@ class SpecialExamsTestCase(OutlineProcessorTestCase): for sequence_key in self.get_sequence_keys(exclude=[self.seq_normal_key]): assert sequence_key in student_details.special_exam_attempts.sequences attempt_summary = student_details.special_exam_attempts.sequences[sequence_key] - assert type(attempt_summary) == dict + assert type(attempt_summary) == dict # lint-amnesty, pylint: disable=unidiomatic-typecheck assert attempt_summary["summary"]["usage_key"] == str(sequence_key) @patch.dict(settings.FEATURES, {'ENABLE_SPECIAL_EXAMS': False}) @patch('openedx.core.djangoapps.content.learning_sequences.api.processors.special_exams.get_attempt_status_summary') def test_special_exam_attempt_data_empty_when_disabled(self, mock_get_attempt_status_summary): - at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) + at_time = datetime(2020, 5, 22, tzinfo=timezone.utc) # lint-amnesty, pylint: disable=unused-variable _, student_details, _ = self.get_details( datetime(2020, 5, 25, tzinfo=timezone.utc) @@ -1130,7 +1130,7 @@ class VisbilityTestCase(OutlineProcessorTestCase): cls.student.courseenrollment_set.create(course_id=cls.course_key, is_active=True, mode="audit") def test_visibility(self): - at_time = datetime(2020, 5, 21, tzinfo=timezone.utc) # Exact value doesn't matter + at_time = datetime(2020, 5, 21, tzinfo=timezone.utc) # Exact value doesn't matter # lint-amnesty, pylint: disable=unused-variable staff_details, student_details, _ = self.get_details( datetime(2020, 5, 25, tzinfo=timezone.utc) diff --git a/openedx/core/djangoapps/content/learning_sequences/apps.py b/openedx/core/djangoapps/content/learning_sequences/apps.py index 0cddb30949..580e39f6ec 100644 --- a/openedx/core/djangoapps/content/learning_sequences/apps.py +++ b/openedx/core/djangoapps/content/learning_sequences/apps.py @@ -1,8 +1,9 @@ +# lint-amnesty, pylint: disable=missing-module-docstring from django.apps import AppConfig from django.utils.translation import ugettext_lazy as _ -class LearningSequencesConfig(AppConfig): +class LearningSequencesConfig(AppConfig): # lint-amnesty, pylint: disable=missing-class-docstring name = 'openedx.core.djangoapps.content.learning_sequences' verbose_name = _('Learning Sequences') diff --git a/openedx/core/djangoapps/content/learning_sequences/data.py b/openedx/core/djangoapps/content/learning_sequences/data.py index 4e37a5c0df..d82e7707a7 100644 --- a/openedx/core/djangoapps/content/learning_sequences/data.py +++ b/openedx/core/djangoapps/content/learning_sequences/data.py @@ -24,7 +24,7 @@ Note: we're using old-style syntax for attrs because we need to support Python TODO: Validate all datetimes to be UTC. """ import logging -from datetime import datetime, timezone +from datetime import datetime, timezone # lint-amnesty, pylint: disable=unused-import from enum import Enum from typing import Dict, List, Optional, Set @@ -47,7 +47,7 @@ class ObjectDoesNotExist(Exception): Imitating Django model conventions, we put a subclass of this in some of our data classes to indicate when something is not found. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass @attr.s(frozen=True) @@ -168,7 +168,7 @@ class CourseOutlineData: sequences = {} for section in self.sections: for seq in section.sequences: - if seq.usage_key in sequences: + if seq.usage_key in sequences: # lint-amnesty, pylint: disable=no-else-raise raise ValueError( "Sequence {} appears in more than one Section." .format(seq.usage_key) @@ -220,7 +220,7 @@ class CourseOutlineData: ) @days_early_for_beta.validator - def validate_days_early_for_beta(self, attribute, value): + def validate_days_early_for_beta(self, attribute, value): # lint-amnesty, pylint: disable=unused-argument """ Ensure that days_early_for_beta isn't negative. """ diff --git a/openedx/core/djangoapps/content/learning_sequences/models.py b/openedx/core/djangoapps/content/learning_sequences/models.py index e5e37dc151..1bad6a2757 100644 --- a/openedx/core/djangoapps/content/learning_sequences/models.py +++ b/openedx/core/djangoapps/content/learning_sequences/models.py @@ -40,7 +40,7 @@ not guaranteed to stick around, and values may be deleted unexpectedly. from django.db import models from model_utils.models import TimeStampedModel -from opaque_keys.edx.django.models import ( +from opaque_keys.edx.django.models import ( # lint-amnesty, pylint: disable=unused-import CourseKeyField, LearningContextKeyField, UsageKeyField ) from .data import CourseVisibility diff --git a/openedx/core/djangoapps/content/learning_sequences/tests/test_views.py b/openedx/core/djangoapps/content/learning_sequences/tests/test_views.py index 7bac8f10f4..24b95ba927 100644 --- a/openedx/core/djangoapps/content/learning_sequences/tests/test_views.py +++ b/openedx/core/djangoapps/content/learning_sequences/tests/test_views.py @@ -15,8 +15,8 @@ from this app, edx-when's set_dates_for_course). """ from datetime import datetime, timezone -from django.contrib.auth.models import User -from opaque_keys.edx.keys import CourseKey, UsageKey +from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user, unused-import +from opaque_keys.edx.keys import CourseKey, UsageKey # lint-amnesty, pylint: disable=unused-import from rest_framework.test import APITestCase, APIClient from openedx.core.djangolib.testing.utils import CacheIsolationTestCase @@ -27,10 +27,10 @@ from ..data import CourseOutlineData, CourseVisibility from ..api.tests.test_data import generate_sections -class CourseOutlineViewTest(CacheIsolationTestCase, APITestCase): +class CourseOutlineViewTest(CacheIsolationTestCase, APITestCase): # lint-amnesty, pylint: disable=missing-class-docstring @classmethod - def setUpTestData(cls): + def setUpTestData(cls): # lint-amnesty, pylint: disable=super-method-not-called cls.staff = UserFactory.create( username='staff', email='staff@example.com', is_staff=True, password='staff_pass' ) diff --git a/openedx/core/djangoapps/content/learning_sequences/urls.py b/openedx/core/djangoapps/content/learning_sequences/urls.py index 7681ecbbbb..c4c00ce51e 100644 --- a/openedx/core/djangoapps/content/learning_sequences/urls.py +++ b/openedx/core/djangoapps/content/learning_sequences/urls.py @@ -1,3 +1,4 @@ +# lint-amnesty, pylint: disable=missing-module-docstring from django.conf.urls import url from .views import CourseOutlineView diff --git a/openedx/core/djangoapps/content/learning_sequences/views.py b/openedx/core/djangoapps/content/learning_sequences/views.py index f39d8764d2..aab74427bb 100644 --- a/openedx/core/djangoapps/content/learning_sequences/views.py +++ b/openedx/core/djangoapps/content/learning_sequences/views.py @@ -3,7 +3,7 @@ The views.py for this app is intentionally thin, and only exists to translate user input/output to and from the business logic in the `api` package. """ from datetime import datetime, timezone -import json +import json # lint-amnesty, pylint: disable=unused-import import logging from django.conf import settings @@ -15,7 +15,7 @@ from opaque_keys.edx.keys import CourseKey from rest_framework.views import APIView from rest_framework.response import Response from rest_framework import serializers -import attr +import attr # lint-amnesty, pylint: disable=unused-import from openedx.core.lib.api.permissions import IsStaff from .api import get_user_course_outline_details @@ -34,7 +34,7 @@ class CourseOutlineView(APIView): # For early testing, restrict this to only global staff... permission_classes = (IsStaff,) - class UserCourseOutlineDataSerializer(serializers.BaseSerializer): + class UserCourseOutlineDataSerializer(serializers.BaseSerializer): # lint-amnesty, pylint: disable=abstract-method """ Read-only serializer for CourseOutlineData for this endpoint. @@ -54,7 +54,7 @@ class CourseOutlineView(APIView): are a critical part of the internals of edx-platform, so the in-process API uses them, but we translate them to "ids" for REST API clients. """ - def to_representation(self, user_course_outline_details): + def to_representation(self, user_course_outline_details): # lint-amnesty, pylint: disable=arguments-differ """ Convert to something DRF knows how to serialize (so no custom types) @@ -150,7 +150,7 @@ class CourseOutlineView(APIView): **schedule_item_dict, } - def get(self, request, course_key_str, format=None): + def get(self, request, course_key_str, format=None): # lint-amnesty, pylint: disable=redefined-builtin, unused-argument """ The CourseOutline, customized for a given user. @@ -169,11 +169,11 @@ class CourseOutlineView(APIView): serializer = self.UserCourseOutlineDataSerializer(user_course_outline_details) return Response(serializer.data) - def _validate_course_key(self, course_key_str): + def _validate_course_key(self, course_key_str): # lint-amnesty, pylint: disable=missing-function-docstring try: course_key = CourseKey.from_string(course_key_str) except InvalidKeyError: - raise serializers.ValidationError( + raise serializers.ValidationError( # lint-amnesty, pylint: disable=raise-missing-from "{} is not a valid CourseKey".format(course_key_str) ) if course_key.deprecated: diff --git a/openedx/core/djangoapps/content_libraries/api.py b/openedx/core/djangoapps/content_libraries/api.py index 728432f0c1..75f0510fe2 100644 --- a/openedx/core/djangoapps/content_libraries/api.py +++ b/openedx/core/djangoapps/content_libraries/api.py @@ -222,7 +222,7 @@ class LibraryBundleLink: opaque_key = attr.ib(type=LearningContextKey, default=None) -class AccessLevel: +class AccessLevel: # lint-amnesty, pylint: disable=function-redefined """ Enum defining library access levels/permissions """ ADMIN_LEVEL = ContentLibraryPermission.ADMIN_LEVEL AUTHOR_LEVEL = ContentLibraryPermission.AUTHOR_LEVEL @@ -407,7 +407,7 @@ def create_library( ) except IntegrityError: delete_bundle(bundle.uuid) - raise LibraryAlreadyExists(slug) + raise LibraryAlreadyExists(slug) # lint-amnesty, pylint: disable=raise-missing-from CONTENT_LIBRARY_CREATED.send(sender=None, library_key=ref.library_key) return ContentLibraryMetadata( key=ref.library_key, @@ -1015,7 +1015,7 @@ def update_bundle_link(library_key, link_id, version=None, delete=False): try: link = links[link_id] except KeyError: - raise InvalidNameError("That link does not exist.") + raise InvalidNameError("That link does not exist.") # lint-amnesty, pylint: disable=raise-missing-from if version is None: version = get_bundle(link.bundle_uuid).latest_version set_draft_link(draft.uuid, link_id, link.bundle_uuid, version) diff --git a/openedx/core/djangoapps/content_libraries/library_bundle.py b/openedx/core/djangoapps/content_libraries/library_bundle.py index 9a566652a9..98716a3615 100644 --- a/openedx/core/djangoapps/content_libraries/library_bundle.py +++ b/openedx/core/djangoapps/content_libraries/library_bundle.py @@ -3,7 +3,7 @@ Helper code for working with Blockstore bundles that contain OLX """ import dateutil.parser -import logging +import logging # lint-amnesty, pylint: disable=wrong-import-order from django.utils.lru_cache import lru_cache from opaque_keys.edx.locator import BundleDefinitionLocator, LibraryUsageLocatorV2 diff --git a/openedx/core/djangoapps/content_libraries/library_context.py b/openedx/core/djangoapps/content_libraries/library_context.py index f7d6ac010a..b65aa12f16 100644 --- a/openedx/core/djangoapps/content_libraries/library_context.py +++ b/openedx/core/djangoapps/content_libraries/library_context.py @@ -27,7 +27,7 @@ class LibraryContextImpl(LearningContext): """ def __init__(self, **kwargs): - super(LibraryContextImpl, self).__init__(**kwargs) + super(LibraryContextImpl, self).__init__(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments self.use_draft = kwargs.get('use_draft', None) def can_edit_block(self, user, usage_key): @@ -88,7 +88,7 @@ class LibraryContextImpl(LearningContext): bundle_uuid = bundle_uuid_for_library_key(library_key) except ContentLibrary.DoesNotExist: return None - if 'force_draft' in kwargs: + if 'force_draft' in kwargs: # lint-amnesty, pylint: disable=consider-using-get use_draft = kwargs['force_draft'] else: use_draft = self.use_draft diff --git a/openedx/core/djangoapps/content_libraries/management/commands/reindex_content_library.py b/openedx/core/djangoapps/content_libraries/management/commands/reindex_content_library.py index 8a3f3fa2c4..a316729d6c 100644 --- a/openedx/core/djangoapps/content_libraries/management/commands/reindex_content_library.py +++ b/openedx/core/djangoapps/content_libraries/management/commands/reindex_content_library.py @@ -1,4 +1,4 @@ -""" Management command to update content libraries' search index """ +""" Management command to update content libraries' search index """ # lint-amnesty, pylint: disable=cyclic-import import logging diff --git a/openedx/core/djangoapps/content_libraries/models.py b/openedx/core/djangoapps/content_libraries/models.py index 94b23189f2..11dd330745 100644 --- a/openedx/core/djangoapps/content_libraries/models.py +++ b/openedx/core/djangoapps/content_libraries/models.py @@ -11,8 +11,8 @@ from openedx.core.djangoapps.content_libraries.constants import ( LIBRARY_TYPES, COMPLEX, LICENSE_OPTIONS, ALL_RIGHTS_RESERVED, ) -from organizations.models import Organization -import six +from organizations.models import Organization # lint-amnesty, pylint: disable=wrong-import-order +import six # lint-amnesty, pylint: disable=wrong-import-order User = get_user_model() @@ -113,7 +113,7 @@ class ContentLibraryPermission(models.Model): ('library', 'group'), ] - def save(self, *args, **kwargs): # pylint: disable=arguments-differ + def save(self, *args, **kwargs): # lint-amnesty, pylint: disable=arguments-differ, signature-differs """ Validate any constraints on the model. diff --git a/openedx/core/djangoapps/content_libraries/permissions.py b/openedx/core/djangoapps/content_libraries/permissions.py index e8d3261ee6..6e3ea45a08 100644 --- a/openedx/core/djangoapps/content_libraries/permissions.py +++ b/openedx/core/djangoapps/content_libraries/permissions.py @@ -3,7 +3,7 @@ Permissions for Content Libraries (v2, Blockstore-based) """ from bridgekeeper import perms, rules from bridgekeeper.rules import Attribute, ManyRelation, Relation, in_current_groups -from django.contrib.auth.models import Group +from django.contrib.auth.models import Group # lint-amnesty, pylint: disable=unused-import from openedx.core.djangoapps.content_libraries.models import ContentLibraryPermission diff --git a/openedx/core/djangoapps/content_libraries/serializers.py b/openedx/core/djangoapps/content_libraries/serializers.py index 52978eeb8b..83bc207551 100644 --- a/openedx/core/djangoapps/content_libraries/serializers.py +++ b/openedx/core/djangoapps/content_libraries/serializers.py @@ -176,7 +176,7 @@ class LibraryXBlockStaticFileSerializer(serializers.Serializer): """ Generate the serialized representation of this static asset file. """ - result = super(LibraryXBlockStaticFileSerializer, self).to_representation(instance) + result = super(LibraryXBlockStaticFileSerializer, self).to_representation(instance) # lint-amnesty, pylint: disable=super-with-arguments # Make sure the URL is one that will work from the user's browser, # not one that only works from within a docker container: result['url'] = blockstore_api.force_browser_url(result['url']) diff --git a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py index f01d531b09..970793d8bb 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py @@ -728,7 +728,7 @@ class ContentLibrariesTest(ContentLibrariesRestApiTest): Test that libraries don't allow more than specified blocks """ with self.settings(MAX_BLOCKS_PER_CONTENT_LIBRARY=1): - lib = self._create_library(slug="test_lib_limits", title="Limits Test Library", description="Testing XBlocks limits in a library") + lib = self._create_library(slug="test_lib_limits", title="Limits Test Library", description="Testing XBlocks limits in a library") # lint-amnesty, pylint: disable=line-too-long lib_id = lib["id"] block_data = self._add_block_to_library(lib_id, "unit", "unit1") # Second block should throw error diff --git a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py index 534c287380..a5f4b060c7 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_runtime.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_runtime.py @@ -184,7 +184,7 @@ class ContentLibraryXBlockUserStateTest(ContentLibraryContentTestMixin, TestCase if the library allows direct learning. """ - databases = {alias for alias in connections} + databases = {alias for alias in connections} # lint-amnesty, pylint: disable=unnecessary-comprehension @XBlock.register_temp_plugin(UserStateTestBlock, UserStateTestBlock.BLOCK_TYPE) def test_default_values(self): @@ -488,7 +488,7 @@ class ContentLibraryXBlockCompletionTest(ContentLibraryContentTestMixin, Complet """ def setUp(self): - super(ContentLibraryXBlockCompletionTest, self).setUp() + super(ContentLibraryXBlockCompletionTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments # Enable the completion waffle flag for these tests self.override_waffle_switch(True) diff --git a/openedx/core/djangoapps/content_libraries/views.py b/openedx/core/djangoapps/content_libraries/views.py index bf94dc2dd1..b1a596a228 100644 --- a/openedx/core/djangoapps/content_libraries/views.py +++ b/openedx/core/djangoapps/content_libraries/views.py @@ -55,19 +55,19 @@ def convert_exceptions(fn): return fn(*args, **kwargs) except api.ContentLibraryNotFound: log.exception("Content library not found") - raise NotFound + raise NotFound # lint-amnesty, pylint: disable=raise-missing-from except api.ContentLibraryBlockNotFound: log.exception("XBlock not found in content library") - raise NotFound + raise NotFound # lint-amnesty, pylint: disable=raise-missing-from except api.LibraryBlockAlreadyExists as exc: log.exception(str(exc)) - raise ValidationError(str(exc)) + raise ValidationError(str(exc)) # lint-amnesty, pylint: disable=raise-missing-from except api.InvalidNameError as exc: log.exception(str(exc)) - raise ValidationError(str(exc)) + raise ValidationError(str(exc)) # lint-amnesty, pylint: disable=raise-missing-from except api.BlockLimitReachedError as exc: log.exception(str(exc)) - raise ValidationError(str(exc)) + raise ValidationError(str(exc)) # lint-amnesty, pylint: disable=raise-missing-from return wrapped_fn @@ -166,14 +166,14 @@ class LibraryRootView(APIView): try: ensure_organization(org_name) except InvalidOrganizationException: - raise ValidationError( + raise ValidationError( # lint-amnesty, pylint: disable=raise-missing-from detail={"org": "No such organization '{}' found.".format(org_name)} ) org = Organization.objects.get(short_name=org_name) try: result = api.create_library(org=org, **data) except api.LibraryAlreadyExists: - raise ValidationError(detail={"slug": "A library with that ID already exists."}) + raise ValidationError(detail={"slug": "A library with that ID already exists."}) # lint-amnesty, pylint: disable=raise-missing-from # Grant the current user admin permissions on the library: api.set_library_user_permissions(result.key, request.user, api.AccessLevel.ADMIN_LEVEL) return Response(ContentLibraryMetadataSerializer(result).data) @@ -212,7 +212,7 @@ class LibraryDetailsView(APIView): try: api.update_library(key, **data) except api.IncompatibleTypesError as err: - raise ValidationError({'type': str(err)}) + raise ValidationError({'type': str(err)}) # lint-amnesty, pylint: disable=raise-missing-from result = api.get_library(key) return Response(ContentLibraryMetadataSerializer(result).data) @@ -249,7 +249,7 @@ class LibraryTeamView(APIView): try: user = User.objects.get(email=serializer.validated_data.get('email')) except User.DoesNotExist: - raise ValidationError({'email': _('We could not find a user with that email address.')}) + raise ValidationError({'email': _('We could not find a user with that email address.')}) # lint-amnesty, pylint: disable=raise-missing-from grant = api.get_library_user_permissions(key, user) if grant: return Response( @@ -259,7 +259,7 @@ class LibraryTeamView(APIView): try: api.set_library_user_permissions(key, user, access_level=serializer.validated_data["access_level"]) except api.LibraryPermissionIntegrityError as err: - raise ValidationError(detail=str(err)) + raise ValidationError(detail=str(err)) # lint-amnesty, pylint: disable=raise-missing-from grant = api.get_library_user_permissions(key, user) return Response(ContentLibraryPermissionSerializer(grant).data) @@ -295,7 +295,7 @@ class LibraryTeamUserView(APIView): try: api.set_library_user_permissions(key, user, access_level=serializer.validated_data["access_level"]) except api.LibraryPermissionIntegrityError as err: - raise ValidationError(detail=str(err)) + raise ValidationError(detail=str(err)) # lint-amnesty, pylint: disable=raise-missing-from grant = api.get_library_user_permissions(key, user) return Response(ContentLibraryPermissionSerializer(grant).data) @@ -324,7 +324,7 @@ class LibraryTeamUserView(APIView): try: api.set_library_user_permissions(key, user, access_level=None) except api.LibraryPermissionIntegrityError as err: - raise ValidationError(detail=str(err)) + raise ValidationError(detail=str(err)) # lint-amnesty, pylint: disable=raise-missing-from return Response({}) @@ -542,7 +542,7 @@ class LibraryBlocksView(APIView): try: result = api.create_library_block(library_key, **serializer.validated_data) except api.IncompatibleTypesError as err: - raise ValidationError( + raise ValidationError( # lint-amnesty, pylint: disable=raise-missing-from detail={'block_type': str(err)}, ) return Response(LibraryXBlockMetadataSerializer(result).data) @@ -613,7 +613,7 @@ class LibraryBlockOlxView(APIView): try: api.set_library_block_olx(key, new_olx_str) except ValueError as err: - raise ValidationError(detail=str(err)) + raise ValidationError(detail=str(err)) # lint-amnesty, pylint: disable=raise-missing-from return Response(LibraryXBlockOlxSerializer({"olx": new_olx_str}).data) @@ -672,7 +672,7 @@ class LibraryBlockAssetView(APIView): try: result = api.add_library_block_static_asset_file(usage_key, file_path, file_content) except ValueError: - raise ValidationError("Invalid file path") + raise ValidationError("Invalid file path") # lint-amnesty, pylint: disable=raise-missing-from return Response(LibraryXBlockStaticFileSerializer(result).data) @convert_exceptions @@ -687,5 +687,5 @@ class LibraryBlockAssetView(APIView): try: api.delete_library_block_static_asset_file(usage_key, file_path) except ValueError: - raise ValidationError("Invalid file path") + raise ValidationError("Invalid file path") # lint-amnesty, pylint: disable=raise-missing-from return Response(status=status.HTTP_204_NO_CONTENT) diff --git a/openedx/core/djangoapps/contentserver/__init__.py b/openedx/core/djangoapps/contentserver/__init__.py index 63136758e8..6433e6479f 100644 --- a/openedx/core/djangoapps/contentserver/__init__.py +++ b/openedx/core/djangoapps/contentserver/__init__.py @@ -1,3 +1,3 @@ -""" +""" # lint-amnesty, pylint: disable=django-not-configured Serves course assets to end users. """ diff --git a/openedx/core/djangoapps/contentserver/middleware.py b/openedx/core/djangoapps/contentserver/middleware.py index 21ab1d68d0..937e2a8226 100644 --- a/openedx/core/djangoapps/contentserver/middleware.py +++ b/openedx/core/djangoapps/contentserver/middleware.py @@ -63,7 +63,7 @@ class StaticContentServer(MiddlewareMixin): """Process the given request""" asset_path = request.path - if self.is_asset_request(request): + if self.is_asset_request(request): # lint-amnesty, pylint: disable=too-many-nested-blocks # Make sure we can convert this request into a location. if AssetLocator.CANONICAL_NAMESPACE in asset_path: asset_path = asset_path.replace('block/', 'block@', 1) @@ -292,7 +292,7 @@ class StaticContentServer(MiddlewareMixin): # Not in cache, so just try and load it from the asset manager. try: content = AssetManager.find(location, as_stream=True) - except (ItemNotFoundError, NotFoundError): + except (ItemNotFoundError, NotFoundError): # lint-amnesty, pylint: disable=try-except-raise raise # Now that we fetched it, let's go ahead and try to cache it. We cap this at 1MB @@ -324,7 +324,7 @@ def parse_range_header(header_value, content_length): for byte_range_string in byte_ranges_string.split(','): byte_range_string = byte_range_string.strip() # Case 0: - if '-' not in byte_range_string: # Invalid syntax of header value. + if '-' not in byte_range_string: # Invalid syntax of header value. # lint-amnesty, pylint: disable=no-else-raise raise ValueError('Invalid syntax.') # Case 1: -500 elif byte_range_string.startswith('-'): diff --git a/openedx/core/djangoapps/contentserver/test/test_contentserver.py b/openedx/core/djangoapps/contentserver/test/test_contentserver.py index 80987ec227..f5c242bfe8 100644 --- a/openedx/core/djangoapps/contentserver/test/test_contentserver.py +++ b/openedx/core/djangoapps/contentserver/test/test_contentserver.py @@ -7,10 +7,10 @@ import copy import datetime import ddt -import logging +import logging # lint-amnesty, pylint: disable=wrong-import-order import six -import unittest -from uuid import uuid4 +import unittest # lint-amnesty, pylint: disable=wrong-import-order +from uuid import uuid4 # lint-amnesty, pylint: disable=wrong-import-order from django.conf import settings from django.test import RequestFactory @@ -24,7 +24,7 @@ from xmodule.modulestore.django import modulestore from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase from xmodule.modulestore.xml_importer import import_course_from_xml from xmodule.assetstore.assetmgr import AssetManager -from opaque_keys import InvalidKeyError +from opaque_keys import InvalidKeyError # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.exceptions import ItemNotFoundError from common.djangoapps.student.models import CourseEnrollment @@ -108,7 +108,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): """ Create user and login. """ - super(ContentStoreToyCourseTest, self).setUp() + super(ContentStoreToyCourseTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.staff_usr = AdminFactory.create() self.non_staff_usr = UserFactory.create() @@ -244,7 +244,7 @@ class ContentStoreToyCourseTest(SharedModuleStoreTestCase): """ first_byte = self.length_unlocked / 4 last_byte = self.length_unlocked / 2 - # pylint: disable=unicode-format-string + # lint-amnesty, pylint: disable=bad-option-value, unicode-format-string resp = self.client.get(self.url_unlocked, HTTP_RANGE='bytes={first}-{last}, -100'.format( first=first_byte, last=last_byte)) @@ -409,7 +409,7 @@ class ParseRangeHeaderTestCase(unittest.TestCase): """ def setUp(self): - super(ParseRangeHeaderTestCase, self).setUp() + super(ParseRangeHeaderTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.content_length = 10000 def test_bytes_unit(self): diff --git a/openedx/core/djangoapps/cors_csrf/authentication.py b/openedx/core/djangoapps/cors_csrf/authentication.py index 9bedb94353..5d4d39695d 100644 --- a/openedx/core/djangoapps/cors_csrf/authentication.py +++ b/openedx/core/djangoapps/cors_csrf/authentication.py @@ -27,7 +27,7 @@ class SessionAuthenticationCrossDomainCsrf(authentication.SessionAuthentication) """ def _process_enforce_csrf(self, request): CsrfViewMiddleware().process_request(request) - return super(SessionAuthenticationCrossDomainCsrf, self).enforce_csrf(request) + return super(SessionAuthenticationCrossDomainCsrf, self).enforce_csrf(request) # lint-amnesty, pylint: disable=super-with-arguments def enforce_csrf(self, request): """ diff --git a/openedx/core/djangoapps/cors_csrf/middleware.py b/openedx/core/djangoapps/cors_csrf/middleware.py index 0367b5f269..a1b4175879 100644 --- a/openedx/core/djangoapps/cors_csrf/middleware.py +++ b/openedx/core/djangoapps/cors_csrf/middleware.py @@ -65,7 +65,7 @@ class CorsCSRFMiddleware(CsrfViewMiddleware, MiddlewareMixin): """Disable the middleware if the feature flag is disabled. """ if not settings.FEATURES.get('ENABLE_CORS_HEADERS'): raise MiddlewareNotUsed() - super(CorsCSRFMiddleware, self).__init__(*args, **kwargs) + super(CorsCSRFMiddleware, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments def process_view(self, request, callback, callback_args, callback_kwargs): """Skip the usual CSRF referer check if this is an allowed cross-domain request. """ @@ -74,7 +74,7 @@ class CorsCSRFMiddleware(CsrfViewMiddleware, MiddlewareMixin): return with skip_cross_domain_referer_check(request): - return super(CorsCSRFMiddleware, self).process_view(request, callback, callback_args, callback_kwargs) + return super(CorsCSRFMiddleware, self).process_view(request, callback, callback_args, callback_kwargs) # lint-amnesty, pylint: disable=super-with-arguments class CsrfCrossDomainCookieMiddleware(MiddlewareMixin): @@ -110,7 +110,7 @@ class CsrfCrossDomainCookieMiddleware(MiddlewareMixin): "You must set `CROSS_DOMAIN_CSRF_COOKIE_DOMAIN` when " "`FEATURES['ENABLE_CROSS_DOMAIN_CSRF_COOKIE']` is True." ) - super(CsrfCrossDomainCookieMiddleware, self).__init__(*args, **kwargs) + super(CsrfCrossDomainCookieMiddleware, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments def process_response(self, request, response): """Set the cross-domain CSRF cookie. """ diff --git a/openedx/core/djangoapps/cors_csrf/tests/test_authentication.py b/openedx/core/djangoapps/cors_csrf/tests/test_authentication.py index 6deff4d1fd..e6d1f75826 100644 --- a/openedx/core/djangoapps/cors_csrf/tests/test_authentication.py +++ b/openedx/core/djangoapps/cors_csrf/tests/test_authentication.py @@ -26,7 +26,7 @@ class CrossDomainAuthTest(TestCase): REFERER = "https://www.edx.org" def setUp(self): - super(CrossDomainAuthTest, self).setUp() + super(CrossDomainAuthTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.auth = SessionAuthenticationCrossDomainCsrf() self.csrf_token = get_token(FakeRequest()) diff --git a/openedx/core/djangoapps/cors_csrf/tests/test_decorators.py b/openedx/core/djangoapps/cors_csrf/tests/test_decorators.py index 6153a8bf3c..ccf88d6c23 100644 --- a/openedx/core/djangoapps/cors_csrf/tests/test_decorators.py +++ b/openedx/core/djangoapps/cors_csrf/tests/test_decorators.py @@ -11,7 +11,7 @@ from ..decorators import ensure_csrf_cookie_cross_domain def fake_view(request): """Fake view that returns the request META as a JSON-encoded string. """ - return HttpResponse(json.dumps(request.META)) + return HttpResponse(json.dumps(request.META)) # lint-amnesty, pylint: disable=http-response-with-json-dumps class TestEnsureCsrfCookieCrossDomain(TestCase): diff --git a/openedx/core/djangoapps/cors_csrf/tests/test_middleware.py b/openedx/core/djangoapps/cors_csrf/tests/test_middleware.py index 5158f854b8..64b61ff91c 100644 --- a/openedx/core/djangoapps/cors_csrf/tests/test_middleware.py +++ b/openedx/core/djangoapps/cors_csrf/tests/test_middleware.py @@ -34,7 +34,7 @@ class TestCorsMiddlewareProcessRequest(TestCase): @override_settings(FEATURES={'ENABLE_CORS_HEADERS': True}) def setUp(self): - super(TestCorsMiddlewareProcessRequest, self).setUp() + super(TestCorsMiddlewareProcessRequest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.middleware = CorsCSRFMiddleware() def check_not_enabled(self, request): @@ -114,7 +114,7 @@ class TestCsrfCrossDomainCookieMiddleware(TestCase): CROSS_DOMAIN_CSRF_COOKIE_DOMAIN=COOKIE_DOMAIN ) def setUp(self): - super(TestCsrfCrossDomainCookieMiddleware, self).setUp() + super(TestCsrfCrossDomainCookieMiddleware, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments self.middleware = CsrfCrossDomainCookieMiddleware() @override_settings(FEATURES={'ENABLE_CROSS_DOMAIN_CSRF_COOKIE': False}) @@ -264,7 +264,7 @@ class TestCsrfCrossDomainCookieMiddleware(TestCase): if is_set: self.assertIn(self.COOKIE_NAME, response.cookies) cookie_header = six.text_type(response.cookies[self.COOKIE_NAME]) - # pylint: disable=unicode-format-string + # lint-amnesty, pylint: disable=bad-option-value, unicode-format-string expected = six.u('Set-Cookie: {name}={value}; Domain={domain};').format( name=self.COOKIE_NAME, value=self.COOKIE_VALUE, diff --git a/openedx/core/djangoapps/cors_csrf/tests/test_views.py b/openedx/core/djangoapps/cors_csrf/tests/test_views.py index 6ab7e5d833..bec88dfdc2 100644 --- a/openedx/core/djangoapps/cors_csrf/tests/test_views.py +++ b/openedx/core/djangoapps/cors_csrf/tests/test_views.py @@ -23,7 +23,7 @@ class XDomainProxyTest(TestCase): def setUp(self): """Clear model-based config cache. """ - super(XDomainProxyTest, self).setUp() + super(XDomainProxyTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments try: self.url = reverse('xdomain_proxy') except NoReverseMatch: