Skip to content
Snippets Groups Projects
Unverified Commit feaf5011 authored by M. Zulqarnain's avatar M. Zulqarnain Committed by GitHub
Browse files

BOM-2287 : Pylint amnesty in teams,tests,survey and verify_student (#26305)

* lint amnesty in teams,tests,survey and verify_student
parent 59f41365
Branches
Tags
No related merge requests found
Showing
with 54 additions and 53 deletions
......@@ -199,7 +199,7 @@ class OverrideFieldData(FieldData):
return enabled_providers
def __init__(self, user, fallback, providers):
def __init__(self, user, fallback, providers): # pylint: disable=super-init-not-called
self.fallback = fallback
self.providers = tuple(provider(user, fallback) for provider in providers)
......
......@@ -7,11 +7,11 @@ class SurveyFormNotFound(Exception):
"""
Thrown when a SurveyForm is not found in the database
"""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class SurveyFormNameAlreadyExists(Exception):
"""
Thrown when a SurveyForm is created but that name already exists
"""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
......@@ -48,7 +48,7 @@ class SurveyForm(TimeStampedModel):
self.validate_form_html(self.form)
# now call the actual save method
super(SurveyForm, self).save(*args, **kwargs)
super(SurveyForm, self).save(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
@classmethod
def validate_form_html(cls, html):
......@@ -59,9 +59,9 @@ class SurveyForm(TimeStampedModel):
fields = cls.get_field_names_from_html(html)
except Exception as ex:
log.exception(u"Cannot parse SurveyForm html: {}".format(ex))
raise ValidationError(u"Cannot parse SurveyForm as HTML: {}".format(ex))
raise ValidationError(u"Cannot parse SurveyForm as HTML: {}".format(ex)) # lint-amnesty, pylint: disable=raise-missing-from
if not len(fields):
if not len(fields): # lint-amnesty, pylint: disable=len-as-condition
raise ValidationError("SurveyForms must contain at least one form input field")
@classmethod
......
# lint-amnesty, pylint: disable=missing-module-docstring
import factory
from common.djangoapps.student.tests.factories import UserFactory
from lms.djangoapps.survey.models import SurveyAnswer, SurveyForm
class SurveyFormFactory(factory.DjangoModelFactory):
class SurveyFormFactory(factory.DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
class Meta(object):
model = SurveyForm
......@@ -12,7 +13,7 @@ class SurveyFormFactory(factory.DjangoModelFactory):
form = '<form>First name:<input type="text" name="firstname"/></form>'
class SurveyAnswerFactory(factory.DjangoModelFactory):
class SurveyAnswerFactory(factory.DjangoModelFactory): # lint-amnesty, pylint: disable=missing-class-docstring
class Meta(object):
model = SurveyAnswer
......
......@@ -7,7 +7,7 @@ from collections import OrderedDict
import ddt
import six
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 import TestCase
from django.test.client import Client
......@@ -26,7 +26,7 @@ class SurveyModelsTests(TestCase):
"""
Set up the test data used in the specific tests
"""
super(SurveyModelsTests, self).setUp()
super(SurveyModelsTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.client = Client()
# Create two accounts
......@@ -35,7 +35,7 @@ class SurveyModelsTests(TestCase):
self.student2 = User.objects.create_user('student2', 'student2@test.com', self.password)
self.test_survey_name = 'TestForm'
self.test_form = '<li><input name="field1" /></li><li><input name="field2" /></li><li><select name="ddl"><option>1</option></select></li>'
self.test_form = '<li><input name="field1" /></li><li><input name="field2" /></li><li><select name="ddl"><option>1</option></select></li>' # lint-amnesty, pylint: disable=line-too-long
self.test_form_update = '<input name="field1" />'
self.course_id = 'foo/bar/baz'
......
......@@ -5,7 +5,7 @@ Python tests for the Survey models
from collections import OrderedDict
from django.contrib.auth.models import User
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.test.client import Client
from lms.djangoapps.survey.models import SurveyForm
......@@ -23,7 +23,7 @@ class SurveyModelsTests(ModuleStoreTestCase):
"""
Set up the test data used in the specific tests
"""
super(SurveyModelsTests, self).setUp()
super(SurveyModelsTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.client = Client()
......
......@@ -25,7 +25,7 @@ class SurveyViewsTests(ModuleStoreTestCase):
"""
Set up the test data used in the specific tests
"""
super(SurveyViewsTests, self).setUp()
super(SurveyViewsTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.client = Client()
......
......@@ -18,7 +18,7 @@ class SurveyRequiredAccessError(AccessError):
error_code = "survey_required"
developer_message = u"User must complete a survey"
user_message = _(u"You must complete a survey")
super(SurveyRequiredAccessError, self).__init__(error_code, developer_message, user_message)
super(SurveyRequiredAccessError, self).__init__(error_code, developer_message, user_message) # lint-amnesty, pylint: disable=super-with-arguments
def is_survey_required_for_course(course_descriptor):
......
......@@ -99,7 +99,7 @@ def submit_answers(request, survey_name):
# scrub the answers to make sure nothing malicious from the user gets stored in
# our database, e.g. JavaScript
filtered_answers = {}
for answer_key in answers.keys():
for answer_key in answers.keys(): # lint-amnesty, pylint: disable=consider-iterating-dictionary
# only allow known input fields
if answer_key in allowed_field_names:
filtered_answers[answer_key] = escape(answers[answer_key])
......
"""
""" # lint-amnesty, pylint: disable=django-not-configured
Defines common methods shared by Teams classes
"""
......
......@@ -185,7 +185,7 @@ def user_organization_protection_status(user, course_key):
else:
return OrganizationProtectionStatus.unprotected
else:
raise ValueError(
raise ValueError( # lint-amnesty, pylint: disable=raising-format-tuple
'Cannot check the org_protection status on a student [%s] not enrolled in course [%s]',
user.id,
course_key
......@@ -349,7 +349,7 @@ def get_team_for_user_course_topic(user, course_id, topic_id):
try:
course_key = CourseKey.from_string(course_id)
except InvalidKeyError:
raise ValueError(u"The supplied course id {course_id} is not valid.".format(
raise ValueError(u"The supplied course id {course_id} is not valid.".format( # lint-amnesty, pylint: disable=raise-missing-from
course_id=course_id
))
try:
......
......@@ -5,7 +5,7 @@ CSV processing and generation utilities for Teams LMS app.
import csv
from collections import Counter
from django.contrib.auth.models import User
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django.db.models import Prefetch
from lms.djangoapps.teams.api import (
......
......@@ -5,17 +5,17 @@ Errors thrown in the Team API.
class TeamAPIRequestError(Exception):
"""There was a problem with a request to the Team API."""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class NotEnrolledInCourseForTeam(TeamAPIRequestError):
"""User is not enrolled in the course for the team they are trying to join."""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class AlreadyOnTeamInTeamset(TeamAPIRequestError):
"""User is already a member of another team in the same teamset."""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class AddToIncompatibleTeamError(TeamAPIRequestError):
......@@ -23,14 +23,14 @@ class AddToIncompatibleTeamError(TeamAPIRequestError):
User is enrolled in a mode that is incompatible with this team type.
e.g. Masters learners cannot be placed in a team with audit learners
"""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class ElasticSearchConnectionError(TeamAPIRequestError):
"""The system was unable to connect to the configured elasticsearch instance."""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
class ImmutableMembershipFieldException(Exception):
"""An attempt was made to change an immutable field on a CourseTeamMembership model."""
pass
pass # lint-amnesty, pylint: disable=unnecessary-pass
......@@ -38,7 +38,7 @@ class Command(BaseCommand):
try:
result = CourseTeam.objects.get(team_id=team_id)
except ObjectDoesNotExist:
raise CommandError('Argument {} is not a course_team team_id'.format(team_id))
raise CommandError('Argument {} is not a course_team team_id'.format(team_id)) # lint-amnesty, pylint: disable=raise-missing-from
return result
......
"""
""" # lint-amnesty, pylint: disable=cyclic-import
Tests for course_team reindex command.
"""
......@@ -27,7 +27,7 @@ class ReindexCourseTeamTest(SharedModuleStoreTestCase):
"""
Set up tests.
"""
super(ReindexCourseTeamTest, self).setUp()
super(ReindexCourseTeamTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.team1 = CourseTeamFactory(course_id=COURSE_KEY1, team_id='team1')
self.team2 = CourseTeamFactory(course_id=COURSE_KEY1, team_id='team2')
......
......@@ -7,7 +7,7 @@ from datetime import datetime
from uuid import uuid4
import pytz
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 ObjectDoesNotExist
from django.db import models
from django.dispatch import receiver
......@@ -115,7 +115,7 @@ class CourseTeam(models.Model):
return "{} in {}".format(self.name, self.course_id)
def __repr__(self):
return (
return ( # lint-amnesty, pylint: disable=missing-format-attribute
"<CourseTeam"
" id={0.id}"
" team_id={0.team_id}"
......@@ -236,7 +236,7 @@ class CourseTeamMembership(models.Model):
return "{} is member of {}".format(self.user.username, self.team)
def __repr__(self):
return (
return ( # lint-amnesty, pylint: disable=missing-format-attribute
"<CourseTeamMembership"
" id={0.id}"
" user_id={0.user.id}"
......@@ -277,9 +277,9 @@ class CourseTeamMembership(models.Model):
raise ImmutableMembershipFieldException(
u"Field %r shouldn't change from %r to %r" % (name, current_value, value)
)
super(CourseTeamMembership, self).__setattr__(name, value)
super(CourseTeamMembership, self).__setattr__(name, value) # lint-amnesty, pylint: disable=super-with-arguments
def save(self, *args, **kwargs): # pylint: disable=arguments-differ
def save(self, *args, **kwargs): # lint-amnesty, pylint: disable=arguments-differ, signature-differs
"""Customize save method to set the last_activity_at if it does not
currently exist. Also resets the team's size if this model is
being created.
......@@ -289,13 +289,13 @@ class CourseTeamMembership(models.Model):
should_reset_team_size = True
if not self.last_activity_at:
self.last_activity_at = datetime.utcnow().replace(tzinfo=pytz.utc)
super(CourseTeamMembership, self).save(*args, **kwargs)
super(CourseTeamMembership, self).save(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
if should_reset_team_size:
self.team.reset_team_size()
def delete(self, *args, **kwargs): # pylint: disable=arguments-differ
def delete(self, *args, **kwargs): # lint-amnesty, pylint: disable=arguments-differ, signature-differs
"""Recompute the related team's team_size after deleting a membership"""
super(CourseTeamMembership, self).delete(*args, **kwargs)
super(CourseTeamMembership, self).delete(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
self.team.reset_team_size()
@classmethod
......
......@@ -10,7 +10,7 @@ from django.conf import settings
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from django.utils import translation
from elasticsearch.exceptions import ConnectionError
from elasticsearch.exceptions import ConnectionError # lint-amnesty, pylint: disable=redefined-builtin
from search.search_engine_base import SearchEngine
from lms.djangoapps.teams.models import CourseTeam
......@@ -124,7 +124,7 @@ class CourseTeamIndexer(object):
return SearchEngine.get_search_engine(index=cls.INDEX_NAME)
except ConnectionError as err:
logging.error(u'Error connecting to elasticsearch: %s', err)
raise ElasticSearchConnectionError
raise ElasticSearchConnectionError # lint-amnesty, pylint: disable=raise-missing-from
@classmethod
def search_is_enabled(cls):
......
......@@ -7,7 +7,7 @@ from copy import deepcopy
import six
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
from django_countries import countries
from rest_framework import serializers
......@@ -135,7 +135,7 @@ class CourseTeamSerializerWithoutMembership(CourseTeamSerializer):
"""
def __init__(self, *args, **kwargs):
super(CourseTeamSerializerWithoutMembership, self).__init__(*args, **kwargs)
super(CourseTeamSerializerWithoutMembership, self).__init__(*args, **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
del self.fields['membership']
......@@ -209,7 +209,7 @@ class BulkTeamCountTopicListSerializer(serializers.ListSerializer): # pylint: d
def to_representation(self, obj): # pylint: disable=arguments-differ
"""Adds team_count to each topic. """
data = super(BulkTeamCountTopicListSerializer, self).to_representation(obj)
data = super(BulkTeamCountTopicListSerializer, self).to_representation(obj) # lint-amnesty, pylint: disable=super-with-arguments
add_team_count(
self.context['request'].user,
data,
......
......@@ -2,7 +2,7 @@
from csv import DictWriter, DictReader
from io import BytesIO, StringIO, TextIOWrapper
from django.contrib.auth.models import User
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user, unused-import
from lms.djangoapps.program_enrollments.tests.factories import ProgramEnrollmentFactory, ProgramCourseEnrollmentFactory
from lms.djangoapps.teams import csv
......@@ -252,7 +252,7 @@ class TeamMembershipImportManagerTests(TeamMembershipEventTestMixin, SharedModul
def setUp(self):
""" Initialize import manager """
super(TeamMembershipImportManagerTests, self).setUp()
super(TeamMembershipImportManagerTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.import_manager = csv.TeamMembershipImportManager(self.course)
self.import_manager.teamset_ids = {ts.teamset_id for ts in self.course.teamsets}
......@@ -261,10 +261,10 @@ class TeamMembershipImportManagerTests(TeamMembershipEventTestMixin, SharedModul
Lodaing course teams shold get the users by team with only 2 queries
1 for teams, 1 for user count
"""
team1 = CourseTeamFactory.create(course_id=self.course.id)
team2 = CourseTeamFactory.create(course_id=self.course.id)
team3 = CourseTeamFactory.create(course_id=self.course.id)
team4 = CourseTeamFactory.create(course_id=self.course.id)
team1 = CourseTeamFactory.create(course_id=self.course.id) # lint-amnesty, pylint: disable=unused-variable
team2 = CourseTeamFactory.create(course_id=self.course.id) # lint-amnesty, pylint: disable=unused-variable
team3 = CourseTeamFactory.create(course_id=self.course.id) # lint-amnesty, pylint: disable=unused-variable
team4 = CourseTeamFactory.create(course_id=self.course.id) # lint-amnesty, pylint: disable=unused-variable
with self.assertNumQueries(2):
self.import_manager.load_course_teams()
......@@ -405,7 +405,7 @@ class TeamMembershipImportManagerTests(TeamMembershipEventTestMixin, SharedModul
['user', 'mode', 'teamset_1'],
[user.username, mode, ''],
])
result = self.import_manager.set_team_memberships(csv_data)
result = self.import_manager.set_team_memberships(csv_data) # lint-amnesty, pylint: disable=unused-variable
# Then they are removed from the team and the correct events are issued
self.assertFalse(CourseTeamMembership.is_user_on_team(user, team))
......@@ -458,7 +458,7 @@ class TeamMembershipImportManagerTests(TeamMembershipEventTestMixin, SharedModul
['user', 'mode', 'teamset_1'],
[user.username, mode, 'new_exciting_team'],
])
result = self.import_manager.set_team_memberships(csv_data)
result = self.import_manager.set_team_memberships(csv_data) # lint-amnesty, pylint: disable=unused-variable
# Then a new team is created
self.assertEqual(CourseTeam.objects.all().count(), 1)
......
......@@ -11,7 +11,7 @@ from datetime import datetime
import ddt
import pytz
import six
from mock import Mock, patch
from mock import Mock, patch # lint-amnesty, pylint: disable=unused-import
from opaque_keys.edx.keys import CourseKey
from common.djangoapps.course_modes.models import CourseMode
......@@ -161,7 +161,7 @@ class TeamMembershipTest(SharedModuleStoreTestCase):
"""
Set up tests.
"""
super(TeamMembershipTest, self).setUp()
super(TeamMembershipTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
self.user1 = UserFactory.create(username='user1')
self.user2 = UserFactory.create(username='user2')
......@@ -266,7 +266,7 @@ class TeamSignalsTest(EventTestMixin, SharedModuleStoreTestCase):
def setUp(self): # pylint: disable=arguments-differ
"""Create a user with a team to test signals."""
super(TeamSignalsTest, self).setUp('lms.djangoapps.teams.utils.tracker')
super(TeamSignalsTest, self).setUp('lms.djangoapps.teams.utils.tracker') # lint-amnesty, pylint: disable=super-with-arguments
self.user = UserFactory.create(username="user")
self.moderator = UserFactory.create(username="moderator")
self.team = CourseTeamFactory(discussion_topic_id=self.DISCUSSION_TOPIC_ID)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment