INCR-259 Run python-modernize on lms/djangoapps/survey (#20561)

* run python modernize

* run isort
This commit is contained in:
Stu Young
2019-05-21 11:35:25 -04:00
committed by Christie Rice
parent da616921f0
commit 367736614d
13 changed files with 46 additions and 21 deletions

View File

@@ -2,6 +2,8 @@
Provide accessors to these models via the Django Admin pages
"""
from __future__ import absolute_import
from django import forms
from django.contrib import admin

View File

@@ -2,6 +2,8 @@
Survey Application Configuration
"""
from __future__ import absolute_import
from django.apps import AppConfig

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import absolute_import
from django.db import migrations, models
import django.utils.timezone
from django.conf import settings

View File

@@ -2,6 +2,8 @@
Models to support Course Surveys feature
"""
from __future__ import absolute_import
import logging
from collections import OrderedDict
@@ -157,7 +159,7 @@ class SurveyForm(TimeStampedModel):
)
for input_field in input_fields:
if 'name' in input_field.keys() and input_field.attrib['name'] not in names:
if 'name' in list(input_field.keys()) and input_field.attrib['name'] not in names:
names.append(input_field.attrib['name'])
return names

View File

@@ -1,10 +1,11 @@
"""
Signal handlers for the survey app
"""
from __future__ import absolute_import
from django.dispatch.dispatcher import receiver
from openedx.core.djangoapps.user_api.accounts.signals import USER_RETIRE_LMS_MISC
from survey.models import SurveyAnswer

View File

@@ -1,4 +1,6 @@
# pylint:disable=missing-docstring
from __future__ import absolute_import
import factory
from student.tests.factories import UserFactory

View File

@@ -2,9 +2,12 @@
Python tests for the Survey models
"""
from __future__ import absolute_import
from collections import OrderedDict
import ddt
import six
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.test import TestCase
@@ -94,7 +97,7 @@ class SurveyModelsTests(TestCase):
"""
survey = self._create_test_survey()
self.assertIsNotNone(survey)
self.assertEquals(unicode(survey), self.test_survey_name)
self.assertEquals(six.text_type(survey), self.test_survey_name)
def test_create_form_with_malformed_html(self):
"""
@@ -169,12 +172,12 @@ class SurveyModelsTests(TestCase):
self.assertTrue(survey.has_user_answered_survey(self.student))
all_answers = survey.get_answers()
self.assertEquals(len(all_answers.keys()), 1)
self.assertEquals(len(list(all_answers.keys())), 1)
self.assertIn(self.student.id, all_answers)
self.assertEquals(all_answers[self.student.id], self.student_answers)
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertEquals(len(list(answers.keys())), 1)
self.assertIn(self.student.id, answers)
self.assertEquals(all_answers[self.student.id], self.student_answers)
@@ -187,7 +190,7 @@ class SurveyModelsTests(TestCase):
for answer_obj in answer_objs:
if course_id:
self.assertEquals(unicode(answer_obj.course_key), course_id)
self.assertEquals(six.text_type(answer_obj.course_key), course_id)
else:
self.assertIsNone(answer_obj.course_key)
@@ -205,19 +208,19 @@ class SurveyModelsTests(TestCase):
self.assertTrue(survey.has_user_answered_survey(self.student))
all_answers = survey.get_answers()
self.assertEquals(len(all_answers.keys()), 2)
self.assertEquals(len(list(all_answers.keys())), 2)
self.assertIn(self.student.id, all_answers)
self.assertIn(self.student2.id, all_answers)
self.assertEquals(all_answers[self.student.id], self.student_answers)
self.assertEquals(all_answers[self.student2.id], self.student2_answers)
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertEquals(len(list(answers.keys())), 1)
self.assertIn(self.student.id, answers)
self.assertEquals(answers[self.student.id], self.student_answers)
answers = survey.get_answers(self.student2)
self.assertEquals(len(answers.keys()), 1)
self.assertEquals(len(list(answers.keys())), 1)
self.assertIn(self.student2.id, answers)
self.assertEquals(answers[self.student2.id], self.student2_answers)
@@ -232,7 +235,7 @@ class SurveyModelsTests(TestCase):
survey.save_user_answers(self.student, self.student_answers, self.course_id)
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertEquals(len(list(answers.keys())), 1)
self.assertIn(self.student.id, answers)
self.assertEquals(answers[self.student.id], self.student_answers)
@@ -240,7 +243,7 @@ class SurveyModelsTests(TestCase):
survey.save_user_answers(self.student, self.student_answers_update, self.course_id)
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertEquals(len(list(answers.keys())), 1)
self.assertIn(self.student.id, answers)
self.assertEquals(answers[self.student.id], self.student_answers_update)
@@ -248,7 +251,7 @@ class SurveyModelsTests(TestCase):
survey.save_user_answers(self.student, self.student_answers_update2, self.course_id)
answers = survey.get_answers(self.student)
self.assertEquals(len(answers.keys()), 1)
self.assertEquals(len(list(answers.keys())), 1)
self.assertIn(self.student.id, answers)
self.assertEquals(answers[self.student.id], self.student_answers_update2)
@@ -265,7 +268,7 @@ class SurveyModelsTests(TestCase):
# even though we have 2 users submitted answers
# limit the result set to just 1
all_answers = survey.get_answers(limit_num_users=1)
self.assertEquals(len(all_answers.keys()), 1)
self.assertEquals(len(list(all_answers.keys())), 1)
def test_get_field_names(self):
"""

View File

@@ -2,14 +2,15 @@
Test signal handlers for the survey app
"""
from __future__ import absolute_import
from lms.djangoapps.survey.signals import _listen_for_lms_retire
from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import fake_completed_retirement
from student.tests.factories import UserFactory
from survey.models import SurveyAnswer
from survey.tests.factories import SurveyAnswerFactory
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from lms.djangoapps.survey.signals import _listen_for_lms_retire
class SurveyRetireSignalTests(ModuleStoreTestCase):
"""

View File

@@ -2,13 +2,15 @@
Python tests for the Survey models
"""
from __future__ import absolute_import
from collections import OrderedDict
from django.contrib.auth.models import User
from django.test.client import Client
from survey.models import SurveyForm
from survey.utils import is_survey_required_for_course, is_survey_required_and_unanswered
from survey.utils import is_survey_required_and_unanswered, is_survey_required_for_course
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory

View File

@@ -2,11 +2,14 @@
Python tests for the Survey views
"""
from __future__ import absolute_import
import json
from collections import OrderedDict
from django.urls import reverse
import six
from django.test.client import Client
from django.urls import reverse
from student.tests.factories import UserFactory
from survey.models import SurveyAnswer, SurveyForm
@@ -129,7 +132,7 @@ class SurveyViewsTests(ModuleStoreTestCase):
data['csrfmiddlewaretoken'] = 'foo'
data['_redirect_url'] = 'bar'
data['course_id'] = unicode(self.course.id)
data['course_id'] = six.text_type(self.course.id)
resp = self.client.post(
self.postback_url,
@@ -148,7 +151,7 @@ class SurveyViewsTests(ModuleStoreTestCase):
)
for answer_obj in answer_objs:
self.assertEquals(unicode(answer_obj.course_key), data['course_id'])
self.assertEquals(six.text_type(answer_obj.course_key), data['course_id'])
def test_encoding_answers(self):
"""

View File

@@ -2,6 +2,8 @@
URL mappings for the Survey feature
"""
from __future__ import absolute_import
from django.conf.urls import url
from survey import views

View File

@@ -1,8 +1,10 @@
"""
Utilities for determining whether or not a survey needs to be completed.
"""
from __future__ import absolute_import
from courseware.access import has_access
from survey.models import SurveyForm, SurveyAnswer
from survey.models import SurveyAnswer, SurveyForm
def is_survey_required_for_course(course_descriptor):

View File

@@ -2,13 +2,15 @@
View endpoints for Survey
"""
from __future__ import absolute_import
import json
import logging
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.urls import reverse
from django.http import HttpResponse, HttpResponseNotFound, HttpResponseRedirect
from django.urls import reverse
from django.utils.html import escape
from django.views.decorators.http import require_POST
from opaque_keys.edx.keys import CourseKey