Applied pylint-amnesty to util
This commit is contained in:
@@ -10,7 +10,7 @@ not migrating so as not to inconvenience users by logging them all out.
|
||||
from functools import wraps
|
||||
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.conf import settings # lint-amnesty, pylint: disable=unused-import
|
||||
from django.core import cache
|
||||
# If we can't find a 'general' CACHE defined in settings.py, we simply fall back
|
||||
# to returning the default cache. This will happen with dev machines.
|
||||
@@ -18,7 +18,7 @@ from django.utils.translation import get_language
|
||||
|
||||
try:
|
||||
cache = cache.caches['general'] # pylint: disable=invalid-name
|
||||
except Exception:
|
||||
except Exception: # lint-amnesty, pylint: disable=broad-except
|
||||
cache = cache.cache
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ def cache_if_anonymous(*get_parameters):
|
||||
|
||||
if response:
|
||||
# A hack to ensure that the response data is a valid text type for both Python 2 and 3.
|
||||
response_content = list(response._container) # pylint: disable=protected-member
|
||||
response_content = list(response._container) # lint-amnesty, pylint: disable=bad-option-value, protected-access, protected-member
|
||||
response.content = b''
|
||||
for item in response_content:
|
||||
response.write(item)
|
||||
|
||||
@@ -29,7 +29,7 @@ def get_default_time_display(dtime):
|
||||
return u""
|
||||
if dtime.tzinfo is not None:
|
||||
try:
|
||||
timezone = u" " + dtime.tzinfo.tzname(dtime)
|
||||
timezone = u" " + dtime.tzinfo.tzname(dtime) # lint-amnesty, pylint: disable=redefined-outer-name
|
||||
except NotImplementedError:
|
||||
timezone = dtime.strftime('%z')
|
||||
else:
|
||||
@@ -137,7 +137,7 @@ def strftime_localized(dtime, format): # pylint: disable=redefined-builtin
|
||||
|
||||
if format == "SHORT_DATE":
|
||||
format = "%x"
|
||||
elif format == "LONG_DATE":
|
||||
elif format == "LONG_DATE": # lint-amnesty, pylint: disable=comparison-with-callable
|
||||
# Translators: the translation for "LONG_DATE_FORMAT" must be a format
|
||||
# string for formatting dates in a long form. For example, the
|
||||
# American English form is "%A, %B %d %Y".
|
||||
@@ -145,7 +145,7 @@ def strftime_localized(dtime, format): # pylint: disable=redefined-builtin
|
||||
format = ugettext("LONG_DATE_FORMAT")
|
||||
if format == "LONG_DATE_FORMAT":
|
||||
format = DEFAULT_LONG_DATE_FORMAT
|
||||
elif format == "DATE_TIME":
|
||||
elif format == "DATE_TIME": # lint-amnesty, pylint: disable=comparison-with-callable
|
||||
# Translators: the translation for "DATE_TIME_FORMAT" must be a format
|
||||
# string for formatting dates with times. For example, the American
|
||||
# English form is "%b %d, %Y at %H:%M".
|
||||
@@ -153,9 +153,9 @@ def strftime_localized(dtime, format): # pylint: disable=redefined-builtin
|
||||
format = ugettext("DATE_TIME_FORMAT")
|
||||
if format == "DATE_TIME_FORMAT":
|
||||
format = DEFAULT_DATE_TIME_FORMAT
|
||||
elif format == "DAY_AND_TIME":
|
||||
elif format == "DAY_AND_TIME": # lint-amnesty, pylint: disable=comparison-with-callable
|
||||
format = DEFAULT_DAY_AND_TIME_FORMAT
|
||||
elif format == "TIME":
|
||||
elif format == "TIME": # lint-amnesty, pylint: disable=comparison-with-callable
|
||||
format = "%X"
|
||||
|
||||
def process_percent_code(match):
|
||||
|
||||
@@ -5,11 +5,11 @@ Utility functions related to databases.
|
||||
|
||||
import random
|
||||
# TransactionManagementError used below actually *does* derive from the standard "Exception" class.
|
||||
# pylint: disable=nonstandard-exception
|
||||
# lint-amnesty, pylint: disable=bad-option-value, nonstandard-exception
|
||||
from contextlib import contextmanager
|
||||
from functools import wraps
|
||||
from functools import wraps # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
from django.db import DEFAULT_DB_ALIAS, DatabaseError, Error, transaction
|
||||
from django.db import DEFAULT_DB_ALIAS, DatabaseError, Error, transaction # lint-amnesty, pylint: disable=unused-import
|
||||
|
||||
from openedx.core.lib.cache_utils import get_cache
|
||||
|
||||
@@ -55,7 +55,7 @@ class OuterAtomic(transaction.Atomic):
|
||||
def __init__(self, using, savepoint, read_committed=False, name=None):
|
||||
self.read_committed = read_committed
|
||||
self.name = name
|
||||
super(OuterAtomic, self).__init__(using, savepoint)
|
||||
super(OuterAtomic, self).__init__(using, savepoint) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
def __enter__(self):
|
||||
|
||||
@@ -75,7 +75,7 @@ class OuterAtomic(transaction.Atomic):
|
||||
# The inner atomic starts a savepoint around the test.
|
||||
# So, for tests only, there should be exactly one savepoint_id and two atomic_for_testcase_calls.
|
||||
# atomic_for_testcase_calls below is added in a monkey-patch for tests only.
|
||||
if self.ALLOW_NESTED and (self.atomic_for_testcase_calls - len(connection.savepoint_ids)) < 1:
|
||||
if self.ALLOW_NESTED and (self.atomic_for_testcase_calls - len(connection.savepoint_ids)) < 1: # lint-amnesty, pylint: disable=no-member
|
||||
raise transaction.TransactionManagementError('Cannot be inside an atomic block.')
|
||||
|
||||
# Otherwise, this shouldn't be nested in any atomic block.
|
||||
@@ -88,7 +88,7 @@ class OuterAtomic(transaction.Atomic):
|
||||
cursor = connection.cursor()
|
||||
cursor.execute("SET TRANSACTION ISOLATION LEVEL READ COMMITTED")
|
||||
|
||||
super(OuterAtomic, self).__enter__()
|
||||
super(OuterAtomic, self).__enter__() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
def outer_atomic(using=None, savepoint=True, read_committed=False, name=None):
|
||||
|
||||
@@ -18,7 +18,7 @@ class FileValidationException(Exception):
|
||||
"""
|
||||
An exception thrown during file validation.
|
||||
"""
|
||||
pass
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
|
||||
def store_uploaded_file(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
# lint-amnesty, pylint: disable=missing-module-docstring
|
||||
|
||||
import decimal
|
||||
import json
|
||||
@@ -31,7 +31,7 @@ class EDXJSONEncoder(DjangoJSONEncoder):
|
||||
return int(o)
|
||||
return float(o)
|
||||
else:
|
||||
return super(EDXJSONEncoder, self).default(o)
|
||||
return super(EDXJSONEncoder, self).default(o) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
def expect_json(view_function):
|
||||
@@ -61,7 +61,7 @@ class JsonResponse(HttpResponse):
|
||||
"""
|
||||
Django HttpResponse subclass that has sensible defaults for outputting JSON.
|
||||
"""
|
||||
def __init__(self, resp_obj=None, status=None, encoder=EDXJSONEncoder,
|
||||
def __init__(self, resp_obj=None, status=None, encoder=EDXJSONEncoder, # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
*args, **kwargs):
|
||||
if resp_obj in (None, ""):
|
||||
content = ""
|
||||
@@ -73,7 +73,7 @@ class JsonResponse(HttpResponse):
|
||||
kwargs.setdefault("content_type", "application/json")
|
||||
if status:
|
||||
kwargs["status"] = status
|
||||
super(JsonResponse, self).__init__(content, *args, **kwargs)
|
||||
super(JsonResponse, self).__init__(content, *args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
|
||||
class JsonResponseBadRequest(HttpResponseBadRequest):
|
||||
@@ -86,11 +86,11 @@ class JsonResponseBadRequest(HttpResponseBadRequest):
|
||||
status: 400
|
||||
encoder: DjangoJSONEncoder
|
||||
"""
|
||||
def __init__(self, obj=None, status=400, encoder=DjangoJSONEncoder, *args, **kwargs):
|
||||
def __init__(self, obj=None, status=400, encoder=DjangoJSONEncoder, *args, **kwargs): # lint-amnesty, pylint: disable=keyword-arg-before-vararg
|
||||
if obj in (None, ""):
|
||||
content = ""
|
||||
else:
|
||||
content = json.dumps(obj, cls=encoder, indent=2, ensure_ascii=False)
|
||||
kwargs.setdefault("content_type", "application/json")
|
||||
kwargs["status"] = status
|
||||
super(JsonResponseBadRequest, self).__init__(content, *args, **kwargs)
|
||||
super(JsonResponseBadRequest, self).__init__(content, *args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
@@ -19,7 +19,7 @@ Usage:
|
||||
"""
|
||||
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
|
||||
from common.djangoapps.student.models import anonymous_id_for_user
|
||||
|
||||
@@ -50,7 +50,7 @@ def substitute_keywords(string, user_id, context):
|
||||
'%%COURSE_END_DATE%%': lambda: context.get('course_end_date'),
|
||||
}
|
||||
|
||||
for key in KEYWORD_FUNCTION_MAP.keys():
|
||||
for key in KEYWORD_FUNCTION_MAP.keys(): # lint-amnesty, pylint: disable=consider-iterating-dictionary
|
||||
if key in string:
|
||||
substitutor = KEYWORD_FUNCTION_MAP[key]
|
||||
string = string.replace(key, substitutor())
|
||||
|
||||
@@ -238,7 +238,7 @@ def get_required_content(course_key, user):
|
||||
# For each outstanding milestone, see if this content is one of its fulfillment paths
|
||||
for path_key in milestone_paths:
|
||||
milestone_path = milestone_paths[path_key]
|
||||
if milestone_path.get('content') and len(milestone_path['content']):
|
||||
if milestone_path.get('content') and len(milestone_path['content']): # lint-amnesty, pylint: disable=len-as-condition
|
||||
for content in milestone_path['content']:
|
||||
required_content.append(content)
|
||||
else:
|
||||
|
||||
@@ -41,7 +41,7 @@ def decompress_string(value):
|
||||
zfile = gzip.GzipFile(fileobj=zbuf)
|
||||
ret = zfile.read()
|
||||
zfile.close()
|
||||
except Exception as e:
|
||||
except Exception as e: # lint-amnesty, pylint: disable=broad-except
|
||||
logger.error('String decompression failed. There may be corrupted data in the database: %s', e)
|
||||
ret = value
|
||||
return ret
|
||||
|
||||
@@ -23,7 +23,7 @@ log = logging.getLogger(__name__)
|
||||
DEFAULT_MAX_PASSWORD_LENGTH = 5000
|
||||
|
||||
|
||||
def create_validator_config(name, options={}):
|
||||
def create_validator_config(name, options={}): # lint-amnesty, pylint: disable=dangerous-default-value
|
||||
"""
|
||||
This function is meant to be used for testing purposes to create validators
|
||||
easily. It returns a validator config of the form:
|
||||
@@ -71,7 +71,7 @@ def password_validators_instruction_texts():
|
||||
complexity_instructions=' & '.join(complexity_instructions)
|
||||
)
|
||||
else:
|
||||
return _('Your password must contain {length_instruction}.'.format(length_instruction=length_instruction))
|
||||
return _('Your password must contain {length_instruction}.'.format(length_instruction=length_instruction)) # lint-amnesty, pylint: disable=translation-of-non-string
|
||||
|
||||
|
||||
def password_validators_restrictions():
|
||||
@@ -99,7 +99,7 @@ def normalize_password(password):
|
||||
password = text_type(password, encoding='utf8')
|
||||
except UnicodeDecodeError:
|
||||
# no reason to get into weeds
|
||||
raise ValidationError([_('Invalid password.')])
|
||||
raise ValidationError([_('Invalid password.')]) # lint-amnesty, pylint: disable=raise-missing-from
|
||||
return unicodedata.normalize('NFKC', password)
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ def _validate_condition(password, fn, min_count):
|
||||
return valid_count >= min_count
|
||||
|
||||
|
||||
class MinimumLengthValidator(DjangoMinimumLengthValidator):
|
||||
class MinimumLengthValidator(DjangoMinimumLengthValidator): # lint-amnesty, pylint: disable=missing-class-docstring
|
||||
def get_instruction_text(self):
|
||||
return ungettext(
|
||||
'at least %(min_length)d character',
|
||||
@@ -169,7 +169,7 @@ class MaximumLengthValidator(object):
|
||||
def __init__(self, max_length=75):
|
||||
self.max_length = max_length
|
||||
|
||||
def validate(self, password, user=None):
|
||||
def validate(self, password, user=None): # lint-amnesty, pylint: disable=unused-argument
|
||||
if len(password) > self.max_length:
|
||||
raise ValidationError(
|
||||
ungettext(
|
||||
@@ -206,7 +206,7 @@ class AlphabeticValidator(object):
|
||||
def __init__(self, min_alphabetic=0):
|
||||
self.min_alphabetic = min_alphabetic
|
||||
|
||||
def validate(self, password, user=None):
|
||||
def validate(self, password, user=None): # lint-amnesty, pylint: disable=unused-argument
|
||||
if _validate_condition(password, lambda c: c.isalpha(), self.min_alphabetic):
|
||||
return
|
||||
raise ValidationError(
|
||||
@@ -226,7 +226,7 @@ class AlphabeticValidator(object):
|
||||
self.min_alphabetic
|
||||
) % {'min_alphabetic': self.min_alphabetic}
|
||||
|
||||
def get_instruction_text(self):
|
||||
def get_instruction_text(self): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if self.min_alphabetic > 0:
|
||||
return ungettext(
|
||||
'%(num)d letter',
|
||||
@@ -254,7 +254,7 @@ class NumericValidator(object):
|
||||
def __init__(self, min_numeric=0):
|
||||
self.min_numeric = min_numeric
|
||||
|
||||
def validate(self, password, user=None):
|
||||
def validate(self, password, user=None): # lint-amnesty, pylint: disable=unused-argument
|
||||
if _validate_condition(password, lambda c: c.isnumeric(), self.min_numeric):
|
||||
return
|
||||
raise ValidationError(
|
||||
@@ -274,7 +274,7 @@ class NumericValidator(object):
|
||||
self.min_numeric
|
||||
) % {'min_numeric': self.min_numeric}
|
||||
|
||||
def get_instruction_text(self):
|
||||
def get_instruction_text(self): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if self.min_numeric > 0:
|
||||
return ungettext(
|
||||
'%(num)d number',
|
||||
@@ -302,7 +302,7 @@ class UppercaseValidator(object):
|
||||
def __init__(self, min_upper=0):
|
||||
self.min_upper = min_upper
|
||||
|
||||
def validate(self, password, user=None):
|
||||
def validate(self, password, user=None): # lint-amnesty, pylint: disable=unused-argument
|
||||
if _validate_condition(password, lambda c: c.isupper(), self.min_upper):
|
||||
return
|
||||
raise ValidationError(
|
||||
@@ -322,7 +322,7 @@ class UppercaseValidator(object):
|
||||
self.min_upper
|
||||
) % {'min_upper': self.min_upper}
|
||||
|
||||
def get_instruction_text(self):
|
||||
def get_instruction_text(self): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if self.min_upper > 0:
|
||||
return ungettext(
|
||||
'%(num)d uppercase letter',
|
||||
@@ -350,7 +350,7 @@ class LowercaseValidator(object):
|
||||
def __init__(self, min_lower=0):
|
||||
self.min_lower = min_lower
|
||||
|
||||
def validate(self, password, user=None):
|
||||
def validate(self, password, user=None): # lint-amnesty, pylint: disable=unused-argument
|
||||
if _validate_condition(password, lambda c: c.islower(), self.min_lower):
|
||||
return
|
||||
raise ValidationError(
|
||||
@@ -370,7 +370,7 @@ class LowercaseValidator(object):
|
||||
self.min_lower
|
||||
) % {'min_lower': self.min_lower}
|
||||
|
||||
def get_instruction_text(self):
|
||||
def get_instruction_text(self): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if self.min_lower > 0:
|
||||
return ungettext(
|
||||
'%(num)d lowercase letter',
|
||||
@@ -399,7 +399,7 @@ class PunctuationValidator(object):
|
||||
def __init__(self, min_punctuation=0):
|
||||
self.min_punctuation = min_punctuation
|
||||
|
||||
def validate(self, password, user=None):
|
||||
def validate(self, password, user=None): # lint-amnesty, pylint: disable=unused-argument
|
||||
if _validate_condition(password, lambda c: 'P' in unicodedata.category(c), self.min_punctuation):
|
||||
return
|
||||
raise ValidationError(
|
||||
@@ -419,7 +419,7 @@ class PunctuationValidator(object):
|
||||
self.min_punctuation
|
||||
) % {'min_punctuation': self.min_punctuation}
|
||||
|
||||
def get_instruction_text(self):
|
||||
def get_instruction_text(self): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if self.min_punctuation > 0:
|
||||
return ungettext(
|
||||
'%(num)d punctuation mark',
|
||||
@@ -447,7 +447,7 @@ class SymbolValidator(object):
|
||||
def __init__(self, min_symbol=0):
|
||||
self.min_symbol = min_symbol
|
||||
|
||||
def validate(self, password, user=None):
|
||||
def validate(self, password, user=None): # lint-amnesty, pylint: disable=unused-argument
|
||||
if _validate_condition(password, lambda c: 'S' in unicodedata.category(c), self.min_symbol):
|
||||
return
|
||||
raise ValidationError(
|
||||
@@ -467,7 +467,7 @@ class SymbolValidator(object):
|
||||
self.min_symbol
|
||||
) % {'min_symbol': self.min_symbol}
|
||||
|
||||
def get_instruction_text(self):
|
||||
def get_instruction_text(self): # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
if self.min_symbol > 0:
|
||||
return ungettext(
|
||||
'%(num)d symbol',
|
||||
|
||||
@@ -28,4 +28,4 @@ class BadRequestRateLimiter(RequestRateLimiter):
|
||||
"""
|
||||
Default rate limit is 30 requests for every 5 minutes.
|
||||
"""
|
||||
pass
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
@@ -3,7 +3,7 @@ Utilities for string manipulation.
|
||||
"""
|
||||
|
||||
|
||||
def str_to_bool(str):
|
||||
def str_to_bool(str): # lint-amnesty, pylint: disable=redefined-builtin
|
||||
"""
|
||||
Converts "true" (case-insensitive) to the boolean True.
|
||||
Everything else will return False (including None).
|
||||
|
||||
@@ -69,7 +69,7 @@ class UrlResetMixin(object):
|
||||
URLCONF_MODULES = ['myapp.url', 'another_app.urls']
|
||||
|
||||
"""
|
||||
super(UrlResetMixin, self).setUp()
|
||||
super(UrlResetMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
self.reset_urls()
|
||||
self.addCleanup(self.reset_urls)
|
||||
@@ -80,7 +80,7 @@ class EventTestMixin(object):
|
||||
Generic mixin for verifying that events were emitted during a test.
|
||||
"""
|
||||
def setUp(self, tracker):
|
||||
super(EventTestMixin, self).setUp()
|
||||
super(EventTestMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
patcher = patch(tracker)
|
||||
self.mock_tracker = patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
@@ -19,7 +19,7 @@ class CourseCatalogServiceMockMixin(object):
|
||||
)
|
||||
|
||||
def setUp(self):
|
||||
super(CourseCatalogServiceMockMixin, self).setUp()
|
||||
super(CourseCatalogServiceMockMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
cache.clear()
|
||||
|
||||
def mock_course_discovery_api_for_catalog_contains(self, catalog_id=1, course_run_ids=None):
|
||||
|
||||
@@ -20,7 +20,7 @@ class TestCourseSharingLinks(ModuleStoreTestCase):
|
||||
Tests for course sharing links.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(TestCourseSharingLinks, self).setUp()
|
||||
super(TestCourseSharingLinks, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
# create test mongo course
|
||||
self.course = CourseFactory.create(
|
||||
|
||||
@@ -60,7 +60,7 @@ def test_get_time_display_coerce():
|
||||
assert get_time_display(test_time_daylight, '%b %d %H:%M', coerce_tz="US/Pacific") == "Jul 12 08:03"
|
||||
|
||||
|
||||
class NamelessTZ(tzinfo):
|
||||
class NamelessTZ(tzinfo): # lint-amnesty, pylint: disable=abstract-method
|
||||
"""Static timezone for testing"""
|
||||
|
||||
def utcoffset(self, _dt):
|
||||
|
||||
@@ -6,7 +6,7 @@ import time
|
||||
import unittest
|
||||
|
||||
import ddt
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.core.management import call_command
|
||||
from django.db import IntegrityError, connection
|
||||
from django.db.transaction import TransactionManagementError, atomic
|
||||
@@ -54,7 +54,7 @@ class TransactionManagersTestCase(TransactionTestCase):
|
||||
class RequestThread(threading.Thread):
|
||||
""" A thread which runs a dummy view."""
|
||||
def __init__(self, delay, **kwargs):
|
||||
super(RequestThread, self).__init__(**kwargs)
|
||||
super(RequestThread, self).__init__(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.delay = delay
|
||||
self.status = {}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class DisableRateLimitTest(TestCase):
|
||||
"""Check that we can disable rate limiting for perf testing. """
|
||||
|
||||
def setUp(self):
|
||||
super(DisableRateLimitTest, self).setUp()
|
||||
super(DisableRateLimitTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
cache.clear()
|
||||
self.view = FakeApiView()
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class FilenameGeneratorTestCase(TestCase):
|
||||
NOW = datetime.strptime('1974-06-22T01:02:03', '%Y-%m-%dT%H:%M:%S').replace(tzinfo=UTC)
|
||||
|
||||
def setUp(self):
|
||||
super(FilenameGeneratorTestCase, self).setUp()
|
||||
super(FilenameGeneratorTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
datetime_patcher = patch.object(
|
||||
common.djangoapps.util.file, 'datetime',
|
||||
Mock(wraps=datetime)
|
||||
@@ -83,7 +83,7 @@ class StoreUploadedFileTestCase(TestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(StoreUploadedFileTestCase, self).setUp()
|
||||
super(StoreUploadedFileTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.request = Mock(spec=HttpRequest)
|
||||
self.file_content = b"test file content"
|
||||
self.stored_file_name = None
|
||||
@@ -91,7 +91,7 @@ class StoreUploadedFileTestCase(TestCase):
|
||||
self.default_max_size = 2000000
|
||||
|
||||
def tearDown(self):
|
||||
super(StoreUploadedFileTestCase, self).tearDown()
|
||||
super(StoreUploadedFileTestCase, self).tearDown() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
if self.file_storage and self.stored_file_name:
|
||||
self.file_storage.delete(self.stored_file_name)
|
||||
|
||||
@@ -232,28 +232,28 @@ class TestUniversalNewlineIterator(TestCase):
|
||||
@ddt.data(1, 2, 999)
|
||||
def test_line_feeds(self, buffer_size):
|
||||
self.assertEqual(
|
||||
[thing.decode('utf-8') for thing in UniversalNewlineIterator(StringIO(u'foo\nbar\n'), buffer_size=buffer_size)],
|
||||
[thing.decode('utf-8') for thing in UniversalNewlineIterator(StringIO(u'foo\nbar\n'), buffer_size=buffer_size)], # lint-amnesty, pylint: disable=line-too-long
|
||||
['foo\n', 'bar\n']
|
||||
)
|
||||
|
||||
@ddt.data(1, 2, 999)
|
||||
def test_carriage_returns(self, buffer_size):
|
||||
self.assertEqual(
|
||||
[thing.decode('utf-8') for thing in UniversalNewlineIterator(StringIO(u'foo\rbar\r'), buffer_size=buffer_size)],
|
||||
[thing.decode('utf-8') for thing in UniversalNewlineIterator(StringIO(u'foo\rbar\r'), buffer_size=buffer_size)], # lint-amnesty, pylint: disable=line-too-long
|
||||
['foo\n', 'bar\n']
|
||||
)
|
||||
|
||||
@ddt.data(1, 2, 999)
|
||||
def test_carriage_returns_and_line_feeds(self, buffer_size):
|
||||
self.assertEqual(
|
||||
[thing.decode('utf-8') for thing in UniversalNewlineIterator(StringIO(u'foo\r\nbar\r\n'), buffer_size=buffer_size)],
|
||||
[thing.decode('utf-8') for thing in UniversalNewlineIterator(StringIO(u'foo\r\nbar\r\n'), buffer_size=buffer_size)], # lint-amnesty, pylint: disable=line-too-long
|
||||
['foo\n', 'bar\n']
|
||||
)
|
||||
|
||||
@ddt.data(1, 2, 999)
|
||||
def test_no_trailing_newline(self, buffer_size):
|
||||
self.assertEqual(
|
||||
[thing.decode('utf-8') for thing in UniversalNewlineIterator(StringIO(u'foo\nbar'), buffer_size=buffer_size)],
|
||||
[thing.decode('utf-8') for thing in UniversalNewlineIterator(StringIO(u'foo\nbar'), buffer_size=buffer_size)], # lint-amnesty, pylint: disable=line-too-long
|
||||
['foo\n', 'bar']
|
||||
)
|
||||
|
||||
@@ -281,4 +281,4 @@ class TestUniversalNewlineIterator(TestCase):
|
||||
@ddt.data(1, 2, 999)
|
||||
def test_unicode_data(self, buffer_size):
|
||||
self.assertEqual([thing.decode('utf-8') if six.PY3 else thing for thing in
|
||||
UniversalNewlineIterator(StringIO(u'héllø wo®ld'), buffer_size=buffer_size)], [u'héllø wo®ld'])
|
||||
UniversalNewlineIterator(StringIO(u'héllø wo®ld'), buffer_size=buffer_size)], [u'héllø wo®ld']) # lint-amnesty, pylint: disable=line-too-long
|
||||
|
||||
@@ -21,7 +21,7 @@ class KeywordSubTest(ModuleStoreTestCase):
|
||||
CREATE_USER = False
|
||||
|
||||
def setUp(self):
|
||||
super(KeywordSubTest, self).setUp()
|
||||
super(KeywordSubTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.user = UserFactory.create(
|
||||
email="testuser@edx.org",
|
||||
username="testuser",
|
||||
|
||||
@@ -21,7 +21,7 @@ class MemcacheTest(TestCase):
|
||||
[129, 500, 2 ** 8 - 1, 2 ** 8 + 1, 2 ** 16 - 1])
|
||||
|
||||
def setUp(self):
|
||||
super(MemcacheTest, self).setUp()
|
||||
super(MemcacheTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.cache = caches['default']
|
||||
|
||||
def test_safe_key(self):
|
||||
|
||||
@@ -31,7 +31,7 @@ class MilestonesHelpersTestCase(ModuleStoreTestCase):
|
||||
"""
|
||||
Test case scaffolding
|
||||
"""
|
||||
super(MilestonesHelpersTestCase, self).setUp()
|
||||
super(MilestonesHelpersTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
self.course = CourseFactory.create(
|
||||
metadata={
|
||||
'entrance_exam_enabled': True,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import unittest
|
||||
|
||||
from ddt import data, ddt, unpack
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.test.utils import override_settings
|
||||
|
||||
@@ -73,25 +73,25 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
'This password is too short. It must contain at least 2 characters.')
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2})], # lint-amnesty, pylint: disable=line-too-long
|
||||
'at least 2 characters.'),
|
||||
|
||||
([
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 2}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2}), # lint-amnesty, pylint: disable=line-too-long
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 2}), # lint-amnesty, pylint: disable=line-too-long
|
||||
], 'characters, including 2 letters.'),
|
||||
|
||||
([
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 2}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 1}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2}), # lint-amnesty, pylint: disable=line-too-long
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 2}), # lint-amnesty, pylint: disable=line-too-long
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 1}), # lint-amnesty, pylint: disable=line-too-long
|
||||
], 'characters, including 2 letters & 1 number.'),
|
||||
|
||||
([
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.UppercaseValidator', {'min_upper': 3}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 1}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.SymbolValidator', {'min_symbol': 2}),
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 2}), # lint-amnesty, pylint: disable=line-too-long
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.UppercaseValidator', {'min_upper': 3}), # lint-amnesty, pylint: disable=line-too-long
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 1}), # lint-amnesty, pylint: disable=line-too-long
|
||||
create_validator_config('common.djangoapps.util.password_policy_validators.SymbolValidator', {'min_symbol': 2}), # lint-amnesty, pylint: disable=line-too-long
|
||||
], 'including 3 uppercase letters & 1 number & 2 symbols.'),
|
||||
)
|
||||
@unpack
|
||||
@@ -116,13 +116,13 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
self.validation_errors_checker(password, msg, user)
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'', 'This password is too short. It must contain at least 1 character.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 8})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 8})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'd', 'This password is too short. It must contain at least 8 characters.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 8})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MinimumLengthValidator', {'min_length': 8})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'longpassword', None),
|
||||
)
|
||||
@unpack
|
||||
@@ -132,13 +132,13 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
self.validation_errors_checker(password, msg)
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MaximumLengthValidator', {'max_length': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MaximumLengthValidator', {'max_length': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'longpassword', 'This password is too long. It must contain no more than 1 character.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MaximumLengthValidator', {'max_length': 10})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MaximumLengthValidator', {'max_length': 10})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'longpassword', 'This password is too long. It must contain no more than 10 characters.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MaximumLengthValidator', {'max_length': 20})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.MaximumLengthValidator', {'max_length': 20})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'shortpassword', None),
|
||||
)
|
||||
@unpack
|
||||
@@ -160,13 +160,13 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
self.validation_errors_checker(password, msg)
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'12345', 'This password must contain at least 1 letter.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 5})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 5})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'test123', 'This password must contain at least 5 letters.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 2})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.AlphabeticValidator', {'min_alphabetic': 2})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'password', None),
|
||||
)
|
||||
@unpack
|
||||
@@ -176,13 +176,13 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
self.validation_errors_checker(password, msg)
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'test', 'This password must contain at least 1 number.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 4})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 4})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'test123', 'This password must contain at least 4 numbers.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 2})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.NumericValidator', {'min_numeric': 2})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'password123', None),
|
||||
)
|
||||
@unpack
|
||||
@@ -192,13 +192,13 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
self.validation_errors_checker(password, msg)
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.UppercaseValidator', {'min_upper': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.UppercaseValidator', {'min_upper': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'lowercase', 'This password must contain at least 1 uppercase letter.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.UppercaseValidator', {'min_upper': 6})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.UppercaseValidator', {'min_upper': 6})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'NOTenough', 'This password must contain at least 6 uppercase letters.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.UppercaseValidator', {'min_upper': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.UppercaseValidator', {'min_upper': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'camelCase', None),
|
||||
)
|
||||
@unpack
|
||||
@@ -208,13 +208,13 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
self.validation_errors_checker(password, msg)
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.LowercaseValidator', {'min_lower': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.LowercaseValidator', {'min_lower': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'UPPERCASE', 'This password must contain at least 1 lowercase letter.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.LowercaseValidator', {'min_lower': 4})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.LowercaseValidator', {'min_lower': 4})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'notENOUGH', 'This password must contain at least 4 lowercase letters.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.LowercaseValidator', {'min_lower': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.LowercaseValidator', {'min_lower': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'goodPassword', None),
|
||||
)
|
||||
@unpack
|
||||
@@ -224,13 +224,13 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
self.validation_errors_checker(password, msg)
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.PunctuationValidator', {'min_punctuation': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.PunctuationValidator', {'min_punctuation': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'no punctuation', 'This password must contain at least 1 punctuation mark.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.PunctuationValidator', {'min_punctuation': 7})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.PunctuationValidator', {'min_punctuation': 7})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'p@$$w0rd$!', 'This password must contain at least 7 punctuation marks.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.PunctuationValidator', {'min_punctuation': 3})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.PunctuationValidator', {'min_punctuation': 3})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'excl@m@t!on', None),
|
||||
)
|
||||
@unpack
|
||||
@@ -240,13 +240,13 @@ class PasswordPolicyValidatorsTestCase(unittest.TestCase):
|
||||
self.validation_errors_checker(password, msg)
|
||||
|
||||
@data(
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.SymbolValidator', {'min_symbol': 1})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.SymbolValidator', {'min_symbol': 1})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'no symbol', 'This password must contain at least 1 symbol.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.SymbolValidator', {'min_symbol': 3})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.SymbolValidator', {'min_symbol': 3})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'☹️boo☹️', 'This password must contain at least 3 symbols.'),
|
||||
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.SymbolValidator', {'min_symbol': 2})],
|
||||
([create_validator_config('common.djangoapps.util.password_policy_validators.SymbolValidator', {'min_symbol': 2})], # lint-amnesty, pylint: disable=line-too-long
|
||||
u'☪symbols!☹️', None),
|
||||
)
|
||||
@unpack
|
||||
|
||||
@@ -34,7 +34,7 @@ class SandboxingTest(TestCase):
|
||||
|
||||
def test_courselikes_with_unsafe_code_default(self):
|
||||
"""
|
||||
Test that the default setting for COURSES_WITH_UNSAFE_CODE is an empty setting, e.g. we don't use @override_settings in these tests
|
||||
Test that the default setting for COURSES_WITH_UNSAFE_CODE is an empty setting, e.g. we don't use @override_settings in these tests # lint-amnesty, pylint: disable=line-too-long
|
||||
"""
|
||||
self.assertFalse(can_execute_unsafe_code(CourseLocator('edX', 'full', '2012_Fall')))
|
||||
self.assertFalse(can_execute_unsafe_code(CourseLocator('edX', 'full', '2013_Spring')))
|
||||
|
||||
@@ -11,4 +11,4 @@ class ValidateOnSaveMixin(object):
|
||||
"""
|
||||
if not (force_insert or force_update):
|
||||
self.full_clean()
|
||||
super(ValidateOnSaveMixin, self).save(force_insert, force_update, **kwargs)
|
||||
super(ValidateOnSaveMixin, self).save(force_insert, force_update, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import json
|
||||
import json # lint-amnesty, pylint: disable=missing-module-docstring
|
||||
import logging
|
||||
import sys
|
||||
from functools import wraps
|
||||
@@ -38,7 +38,7 @@ def ensure_valid_course_key(view_func):
|
||||
try:
|
||||
CourseKey.from_string(course_key)
|
||||
except InvalidKeyError:
|
||||
raise Http404
|
||||
raise Http404 # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
response = view_func(request, *args, **kwargs)
|
||||
return response
|
||||
@@ -58,7 +58,7 @@ def ensure_valid_usage_key(view_func):
|
||||
try:
|
||||
UsageKey.from_string(usage_key)
|
||||
except InvalidKeyError:
|
||||
raise Http404
|
||||
raise Http404 # lint-amnesty, pylint: disable=raise-missing-from
|
||||
|
||||
response = view_func(request, *args, **kwargs)
|
||||
return response
|
||||
@@ -138,7 +138,7 @@ def handle_500(template_path, context=None, test_func=None):
|
||||
try:
|
||||
return func(request, *args, **kwargs)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
if settings.DEBUG:
|
||||
if settings.DEBUG: # lint-amnesty, pylint: disable=no-else-raise
|
||||
# In debug mode let django process the 500 errors and display debug info for the developer
|
||||
raise
|
||||
elif test_func is None or test_func(request):
|
||||
@@ -159,12 +159,12 @@ def calculate(request):
|
||||
equation = request.GET['equation']
|
||||
try:
|
||||
result = calc.evaluator({}, {}, equation)
|
||||
except:
|
||||
except: # lint-amnesty, pylint: disable=bare-except
|
||||
event = {'error': list(map(str, sys.exc_info())),
|
||||
'equation': equation}
|
||||
track_views.server_track(request, 'error:calc', event, page='calc')
|
||||
return HttpResponse(json.dumps({'result': 'Invalid syntax'}))
|
||||
return HttpResponse(json.dumps({'result': str(result)}))
|
||||
return HttpResponse(json.dumps({'result': 'Invalid syntax'})) # lint-amnesty, pylint: disable=http-response-with-json-dumps
|
||||
return HttpResponse(json.dumps({'result': str(result)})) # lint-amnesty, pylint: disable=http-response-with-json-dumps
|
||||
|
||||
|
||||
def info(request):
|
||||
|
||||
Reference in New Issue
Block a user