From 871bc39b641fc83756f5234f8779b123060be343 Mon Sep 17 00:00:00 2001 From: Stu Young Date: Wed, 15 May 2019 16:15:01 -0400 Subject: [PATCH] incr-270 (#20569) * run python modernize * run isort * pylint supression --- .../instructor/tests/test_access.py | 13 ++++--- lms/djangoapps/instructor/tests/test_api.py | 24 ++++++------ .../tests/test_api_email_localization.py | 2 + .../instructor/tests/test_certificates.py | 39 ++++++++++--------- .../instructor/tests/test_ecommerce.py | 5 ++- lms/djangoapps/instructor/tests/test_email.py | 2 + .../instructor/tests/test_enrollment.py | 7 ++-- .../tests/test_enrollment_store_provider.py | 2 + .../instructor/tests/test_proctoring.py | 8 ++-- .../tests/test_registration_codes.py | 6 ++- .../instructor/tests/test_services.py | 23 ++++++----- .../instructor/tests/test_spoc_gradebook.py | 7 +++- lms/djangoapps/instructor/tests/test_tools.py | 2 +- lms/djangoapps/instructor/tests/utils.py | 5 ++- .../tests/views/test_instructor_dashboard.py | 22 ++++++----- 15 files changed, 100 insertions(+), 67 deletions(-) diff --git a/lms/djangoapps/instructor/tests/test_access.py b/lms/djangoapps/instructor/tests/test_access.py index 4a8423f65d..de149a8e53 100644 --- a/lms/djangoapps/instructor/tests/test_access.py +++ b/lms/djangoapps/instructor/tests/test_access.py @@ -2,7 +2,10 @@ Test instructor.access """ +from __future__ import absolute_import + import pytest +from six.moves import range from lms.djangoapps.instructor.access import allow_access, list_with_level, revoke_access, update_forum_role from openedx.core.djangoapps.ace_common.tests.mixins import EmailTemplateTagMixin @@ -22,10 +25,10 @@ class TestInstructorAccessList(SharedModuleStoreTestCase): def setUp(self): super(TestInstructorAccessList, self).setUp() - self.instructors = [UserFactory.create() for _ in xrange(4)] + self.instructors = [UserFactory.create() for _ in range(4)] for user in self.instructors: allow_access(self.course, user, 'instructor') - self.beta_testers = [UserFactory.create() for _ in xrange(4)] + self.beta_testers = [UserFactory.create() for _ in range(4)] for user in self.beta_testers: allow_access(self.course, user, 'beta') @@ -92,10 +95,10 @@ class TestInstructorAccessRevoke(SharedModuleStoreTestCase): def setUp(self): super(TestInstructorAccessRevoke, self).setUp() - self.staff = [UserFactory.create() for _ in xrange(4)] + self.staff = [UserFactory.create() for _ in range(4)] for user in self.staff: allow_access(self.course, user, 'staff') - self.beta_testers = [UserFactory.create() for _ in xrange(4)] + self.beta_testers = [UserFactory.create() for _ in range(4)] for user in self.beta_testers: allow_access(self.course, user, 'beta') @@ -135,7 +138,7 @@ class TestInstructorAccessForum(SharedModuleStoreTestCase): course_id=self.course.id, name=FORUM_ROLE_MODERATOR ) - self.moderators = [UserFactory.create() for _ in xrange(4)] + self.moderators = [UserFactory.create() for _ in range(4)] for user in self.moderators: self.mod_role.users.add(user) diff --git a/lms/djangoapps/instructor/tests/test_api.py b/lms/djangoapps/instructor/tests/test_api.py index b66fd8635a..88fc6a9eae 100644 --- a/lms/djangoapps/instructor/tests/test_api.py +++ b/lms/djangoapps/instructor/tests/test_api.py @@ -2,7 +2,7 @@ """ Unit tests for instructor.api methods. """ -from __future__ import print_function +from __future__ import absolute_import, print_function import datetime import functools @@ -28,7 +28,8 @@ from mock import Mock, NonCallableMock, patch from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import UsageKey from pytz import UTC -from six import text_type +from six import text_type, unichr # pylint: disable=redefined-builtin +from six.moves import range, zip from bulk_email.models import BulkEmailFlag, CourseEmail, CourseEmailTemplate from course_modes.models import CourseMode @@ -42,6 +43,8 @@ from courseware.tests.factories import ( UserProfileFactory ) from courseware.tests.helpers import LoginEnrollmentTestCase +from edx_when.api import get_overrides_for_user +from edx_when.signals import extract_dates from lms.djangoapps.certificates.models import CertificateStatuses from lms.djangoapps.certificates.tests.factories import GeneratedCertificateFactory from lms.djangoapps.instructor.tests.utils import FakeContentTask, FakeEmail, FakeEmailInfo @@ -62,9 +65,6 @@ from openedx.core.djangoapps.django_comment_common.utils import seed_permissions from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.lib.xblock_utils import grade_histogram -from edx_when.api import get_overrides_for_user -from edx_when.signals import extract_dates - from shoppingcart.models import ( Coupon, CouponRedemption, @@ -2604,7 +2604,7 @@ class TestInstructorAPILevelsDataDump(SharedModuleStoreTestCase, LoginEnrollment course_id=self.course.id ) - self.students = [UserFactory() for _ in xrange(6)] + self.students = [UserFactory() for _ in range(6)] for student in self.students: CourseEnrollment.enroll(student, self.course.id) @@ -4094,7 +4094,7 @@ class TestInstructorAPITaskLists(SharedModuleStoreTestCase, LoginEnrollmentTestC state=json.dumps({'attempts': 10}), ) mock_factory = MockCompletionInfo() - self.tasks = [self.FakeTask(mock_factory.mock_get_task_completion_info) for _ in xrange(7)] + self.tasks = [self.FakeTask(mock_factory.mock_get_task_completion_info) for _ in range(7)] self.tasks[-1].make_invalid_output() @patch('lms.djangoapps.instructor_task.api.get_running_instructor_tasks') @@ -4228,7 +4228,7 @@ class TestInstructorEmailContentList(SharedModuleStoreTestCase, LoginEnrollmentT def get_email_content_response(self, num_emails, task_history_request, with_failures=False): """ Calls the list_email_content endpoint and returns the repsonse """ self.setup_fake_email_info(num_emails, with_failures) - task_history_request.return_value = self.tasks.values() + task_history_request.return_value = list(self.tasks.values()) url = reverse('list_email_content', kwargs={'course_id': text_type(self.course.id)}) with patch('lms.djangoapps.instructor.views.api.CourseEmail.objects.get') as mock_email_info: mock_email_info.side_effect = self.get_matching_mock_email @@ -4679,7 +4679,7 @@ class TestCourseIssuedCertificatesData(SharedModuleStoreTestCase): url = reverse('get_issued_certificates', kwargs={'course_id': text_type(self.course.id)}) # firstly generating downloadable certificates with 'honor' mode certificate_count = 3 - for __ in xrange(certificate_count): + for __ in range(certificate_count): self.generate_certificate(course_id=self.course.id, mode='honor', status=CertificateStatuses.generating) response = self.client.post(url) @@ -4701,7 +4701,7 @@ class TestCourseIssuedCertificatesData(SharedModuleStoreTestCase): url = reverse('get_issued_certificates', kwargs={'course_id': text_type(self.course.id)}) # firstly generating downloadable certificates with 'honor' mode certificate_count = 3 - for __ in xrange(certificate_count): + for __ in range(certificate_count): self.generate_certificate(course_id=self.course.id, mode='honor', status=CertificateStatuses.downloadable) response = self.client.post(url) @@ -4716,7 +4716,7 @@ class TestCourseIssuedCertificatesData(SharedModuleStoreTestCase): self.assertEqual(certificate.get('course_id'), str(self.course.id)) # Now generating downloadable certificates with 'verified' mode - for __ in xrange(certificate_count): + for __ in range(certificate_count): self.generate_certificate( course_id=self.course.id, mode='verified', @@ -4742,7 +4742,7 @@ class TestCourseIssuedCertificatesData(SharedModuleStoreTestCase): url = reverse('get_issued_certificates', kwargs={'course_id': text_type(self.course.id)}) # firstly generating downloadable certificates with 'honor' mode certificate_count = 3 - for __ in xrange(certificate_count): + for __ in range(certificate_count): self.generate_certificate(course_id=self.course.id, mode='honor', status=CertificateStatuses.downloadable) current_date = datetime.date.today().strftime(u"%B %d, %Y") diff --git a/lms/djangoapps/instructor/tests/test_api_email_localization.py b/lms/djangoapps/instructor/tests/test_api_email_localization.py index d7f38b21b8..b818358bde 100644 --- a/lms/djangoapps/instructor/tests/test_api_email_localization.py +++ b/lms/djangoapps/instructor/tests/test_api_email_localization.py @@ -3,6 +3,8 @@ Unit tests for the localization of emails sent by instructor.api methods. """ +from __future__ import absolute_import + from django.core import mail from django.test.utils import override_settings from django.urls import reverse diff --git a/lms/djangoapps/instructor/tests/test_certificates.py b/lms/djangoapps/instructor/tests/test_certificates.py index e285dbb704..1c507af2a2 100644 --- a/lms/djangoapps/instructor/tests/test_certificates.py +++ b/lms/djangoapps/instructor/tests/test_certificates.py @@ -1,20 +1,23 @@ """Tests for the certificates panel of the instructor dash. """ +from __future__ import absolute_import + import contextlib import io import json from datetime import datetime, timedelta +import ddt import mock import pytz +import six +from config_models.models import cache from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.core.files.uploadedfile import SimpleUploadedFile from django.test.utils import override_settings from django.urls import reverse -import ddt from capa.xqueue_interface import XQueueInterface -from config_models.models import cache from course_modes.models import CourseMode from courseware.tests.factories import GlobalStaffFactory, InstructorFactory, UserFactory from lms.djangoapps.certificates import api as certs_api @@ -51,7 +54,7 @@ class CertificatesInstructorDashTest(SharedModuleStoreTestCase): cls.course = CourseFactory.create() cls.url = reverse( 'instructor_dashboard', - kwargs={'course_id': unicode(cls.course.id)} + kwargs={'course_id': six.text_type(cls.course.id)} ) def setUp(self): @@ -249,7 +252,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): self.client.login(username=self.global_staff.username, password='test') url = reverse( 'generate_example_certificates', - kwargs={'course_id': unicode(self.course.id)} + kwargs={'course_id': six.text_type(self.course.id)} ) response = self.client.post(url) @@ -267,7 +270,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): self.client.login(username=self.global_staff.username, password='test') url = reverse( 'enable_certificate_generation', - kwargs={'course_id': unicode(self.course.id)} + kwargs={'course_id': six.text_type(self.course.id)} ) params = {'certificates-enabled': 'true' if is_enabled else 'false'} response = self.client.post(url, data=params) @@ -283,7 +286,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): """Check that the response redirects to the certificates section. """ expected_redirect = reverse( 'instructor_dashboard', - kwargs={'course_id': unicode(self.course.id)} + kwargs={'course_id': six.text_type(self.course.id)} ) expected_redirect += '#view-certificates' self.assertRedirects(response, expected_redirect) @@ -297,7 +300,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): self.client.login(username=user.username, password='test') url = reverse( 'start_certificate_generation', - kwargs={'course_id': unicode(self.course.id)} + kwargs={'course_id': six.text_type(self.course.id)} ) response = self.client.post(url) @@ -315,7 +318,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): self.client.login(username=self.global_staff.username, password='test') url = reverse( 'start_certificate_generation', - kwargs={'course_id': unicode(self.course.id)} + kwargs={'course_id': six.text_type(self.course.id)} ) response = self.client.post(url) @@ -340,7 +343,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): # Login the client and access the url with 'certificate_statuses' self.client.login(username=self.global_staff.username, password='test') - url = reverse('start_certificate_regeneration', kwargs={'course_id': unicode(self.course.id)}) + url = reverse('start_certificate_regeneration', kwargs={'course_id': six.text_type(self.course.id)}) response = self.client.post(url, data={'certificate_statuses': [CertificateStatuses.downloadable]}) # Assert 200 status code in response @@ -405,7 +408,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): self.client.login(username=self.global_staff.username, password='test') url = reverse( 'start_certificate_regeneration', - kwargs={'course_id': unicode(self.course.id)} + kwargs={'course_id': six.text_type(self.course.id)} ) with mock.patch.object(XQueueInterface, 'send_to_queue') as mock_send: @@ -453,7 +456,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): # Login the client and access the url without 'certificate_statuses' self.client.login(username=self.global_staff.username, password='test') - url = reverse('start_certificate_regeneration', kwargs={'course_id': unicode(self.course.id)}) + url = reverse('start_certificate_regeneration', kwargs={'course_id': six.text_type(self.course.id)}) response = self.client.post(url) # Assert 400 status code in response @@ -467,7 +470,7 @@ class CertificatesInstructorApiTest(SharedModuleStoreTestCase): ) # Access the url passing 'certificate_statuses' that are not present in db - url = reverse('start_certificate_regeneration', kwargs={'course_id': unicode(self.course.id)}) + url = reverse('start_certificate_regeneration', kwargs={'course_id': six.text_type(self.course.id)}) response = self.client.post(url, data={'certificate_statuses': [CertificateStatuses.generating]}) # Assert 400 status code in response @@ -495,7 +498,7 @@ class CertificateExceptionViewInstructorApiTest(SharedModuleStoreTestCase): self.user2 = UserFactory() CourseEnrollment.enroll(self.user, self.course.id) CourseEnrollment.enroll(self.user2, self.course.id) - self.url = reverse('certificate_exception_view', kwargs={'course_id': unicode(self.course.id)}) + self.url = reverse('certificate_exception_view', kwargs={'course_id': six.text_type(self.course.id)}) certificate_white_list_item = CertificateWhitelistFactory.create( user=self.user2, @@ -507,7 +510,7 @@ class CertificateExceptionViewInstructorApiTest(SharedModuleStoreTestCase): notes="Test Notes for Test Certificate Exception", user_email='', user_id='', - user_name=unicode(self.user.username) + user_name=six.text_type(self.user.username) ) self.certificate_exception_in_db = dict( @@ -640,7 +643,7 @@ class CertificateExceptionViewInstructorApiTest(SharedModuleStoreTestCase): course2 = CourseFactory.create() url_course2 = reverse( 'certificate_exception_view', - kwargs={'course_id': unicode(course2.id)} + kwargs={'course_id': six.text_type(course2.id)} ) # add certificate exception for same user in a different course @@ -804,7 +807,7 @@ class GenerateCertificatesInstructorApiTest(SharedModuleStoreTestCase): """ url = reverse( 'generate_certificate_exceptions', - kwargs={'course_id': unicode(self.course.id), 'generate_for': 'all'} + kwargs={'course_id': six.text_type(self.course.id), 'generate_for': 'all'} ) response = self.client.post( @@ -831,7 +834,7 @@ class GenerateCertificatesInstructorApiTest(SharedModuleStoreTestCase): """ url = reverse( 'generate_certificate_exceptions', - kwargs={'course_id': unicode(self.course.id), 'generate_for': 'new'} + kwargs={'course_id': six.text_type(self.course.id), 'generate_for': 'new'} ) response = self.client.post( @@ -859,7 +862,7 @@ class GenerateCertificatesInstructorApiTest(SharedModuleStoreTestCase): """ url = reverse( 'generate_certificate_exceptions', - kwargs={'course_id': unicode(self.course.id), 'generate_for': ''} + kwargs={'course_id': six.text_type(self.course.id), 'generate_for': ''} ) response = self.client.post( diff --git a/lms/djangoapps/instructor/tests/test_ecommerce.py b/lms/djangoapps/instructor/tests/test_ecommerce.py index 982453312d..8e8c30c151 100644 --- a/lms/djangoapps/instructor/tests/test_ecommerce.py +++ b/lms/djangoapps/instructor/tests/test_ecommerce.py @@ -2,9 +2,12 @@ Unit tests for Ecommerce feature flag in new instructor dashboard. """ +from __future__ import absolute_import + import datetime import pytz +import six from django.urls import reverse from six import text_type @@ -343,7 +346,7 @@ class TestECommerceDashboardViews(SiteMixin, SharedModuleStoreTestCase): original_mode = CourseMode.objects.get(course_id=self.course.id, mode_slug='honor') original_mode.delete() new_mode = CourseMode( - course_id=unicode(self.course.id), mode_slug='verified', + course_id=six.text_type(self.course.id), mode_slug='verified', mode_display_name='verified', min_price=10, currency='usd' ) new_mode.save() diff --git a/lms/djangoapps/instructor/tests/test_email.py b/lms/djangoapps/instructor/tests/test_email.py index 4c70ddd20d..d44e51aa07 100644 --- a/lms/djangoapps/instructor/tests/test_email.py +++ b/lms/djangoapps/instructor/tests/test_email.py @@ -5,6 +5,8 @@ non-Mongo backed courses, regardless of email feature flag, and that the view is conditionally available when Course Auth is turned on. """ +from __future__ import absolute_import + from django.urls import reverse from opaque_keys.edx.keys import CourseKey from six import text_type diff --git a/lms/djangoapps/instructor/tests/test_enrollment.py b/lms/djangoapps/instructor/tests/test_enrollment.py index af2f809741..250b530742 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment.py +++ b/lms/djangoapps/instructor/tests/test_enrollment.py @@ -2,12 +2,13 @@ """ Unit tests for instructor.enrollment methods. """ -from __future__ import print_function +from __future__ import absolute_import, print_function import json from abc import ABCMeta import ddt +import six from ccx_keys.locator import CCXLocator from crum import set_current_request from django.conf import settings @@ -64,7 +65,7 @@ class TestSettableEnrollmentState(CacheIsolationTestCase): self.assertEqual(mes, ees) -class TestEnrollmentChangeBase(CacheIsolationTestCase): +class TestEnrollmentChangeBase(six.with_metaclass(ABCMeta, CacheIsolationTestCase)): """ Test instructor enrollment administration against database effects. @@ -73,8 +74,6 @@ class TestEnrollmentChangeBase(CacheIsolationTestCase): the test will pass if `action` mutates state from `before_ideal` to `after_ideal` """ - __metaclass__ = ABCMeta - def setUp(self): super(TestEnrollmentChangeBase, self).setUp() self.course_key = CourseLocator('Robot', 'fAKE', 'C--se--ID') diff --git a/lms/djangoapps/instructor/tests/test_enrollment_store_provider.py b/lms/djangoapps/instructor/tests/test_enrollment_store_provider.py index 1277d09244..22bbfb4476 100644 --- a/lms/djangoapps/instructor/tests/test_enrollment_store_provider.py +++ b/lms/djangoapps/instructor/tests/test_enrollment_store_provider.py @@ -2,6 +2,8 @@ Exercises tests on the base_store_provider file """ +from __future__ import absolute_import + from django.test import TestCase from lms.djangoapps.instructor.enrollment_report import AbstractEnrollmentReportProvider diff --git a/lms/djangoapps/instructor/tests/test_proctoring.py b/lms/djangoapps/instructor/tests/test_proctoring.py index b82d803b4f..aa6fa9cfcf 100644 --- a/lms/djangoapps/instructor/tests/test_proctoring.py +++ b/lms/djangoapps/instructor/tests/test_proctoring.py @@ -2,15 +2,17 @@ Unit tests for Edx Proctoring feature flag in new instructor dashboard. """ +from __future__ import absolute_import + +import ddt from django.apps import apps from django.conf import settings from django.urls import reverse +from edx_proctoring.api import create_exam +from edx_proctoring.backends.tests.test_backend import TestBackendProvider from mock import patch from six import text_type -import ddt -from edx_proctoring.api import create_exam -from edx_proctoring.backends.tests.test_backend import TestBackendProvider from student.roles import CourseInstructorRole, CourseStaffRole from student.tests.factories import AdminFactory from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase diff --git a/lms/djangoapps/instructor/tests/test_registration_codes.py b/lms/djangoapps/instructor/tests/test_registration_codes.py index 601dcedbfb..9563130ee4 100644 --- a/lms/djangoapps/instructor/tests/test_registration_codes.py +++ b/lms/djangoapps/instructor/tests/test_registration_codes.py @@ -1,12 +1,16 @@ """ Test for the registration code status information. """ +from __future__ import absolute_import + import json +import six from django.test.utils import override_settings from django.urls import reverse from django.utils.translation import ugettext as _ from six import text_type +from six.moves import range from course_modes.models import CourseMode from course_modes.tests.factories import CourseModeFactory @@ -120,7 +124,7 @@ class TestCourseRegistrationCodeStatus(SharedModuleStoreTestCase): for i in range(2): CourseRegistrationCode.objects.create( code='reg_code{}'.format(i), - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), created_by=self.instructor, invoice=self.sale_invoice, invoice_item=self.invoice_item, diff --git a/lms/djangoapps/instructor/tests/test_services.py b/lms/djangoapps/instructor/tests/test_services.py index bb8916a8d5..ee2723051d 100644 --- a/lms/djangoapps/instructor/tests/test_services.py +++ b/lms/djangoapps/instructor/tests/test_services.py @@ -2,9 +2,12 @@ Tests for the InstructorService """ +from __future__ import absolute_import + import json import mock +import six from courseware.models import StudentModule from lms.djangoapps.instructor.access import allow_access @@ -33,8 +36,8 @@ class InstructorServiceTests(SharedModuleStoreTestCase): cls.course.id, 'robot-some-other_problem-urlname' ) - cls.problem_urlname = unicode(cls.problem_location) - cls.other_problem_urlname = unicode(cls.other_problem_location) + cls.problem_urlname = six.text_type(cls.problem_location) + cls.other_problem_urlname = six.text_type(cls.other_problem_location) def setUp(self): super(InstructorServiceTests, self).setUp() @@ -68,7 +71,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): self.service.delete_student_attempt( self.student.username, - unicode(self.course.id), + six.text_type(self.course.id), self.problem_urlname, requesting_user=self.student, ) @@ -90,7 +93,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): result = self.service.delete_student_attempt( self.student.username, - unicode(self.course.id), + six.text_type(self.course.id), 'foo/bar/baz', requesting_user=self.student, ) @@ -103,7 +106,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): result = self.service.delete_student_attempt( 'bad_student', - unicode(self.course.id), + six.text_type(self.course.id), 'foo/bar/baz', requesting_user=self.student, ) @@ -116,7 +119,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): result = self.service.delete_student_attempt( self.student.username, - unicode(self.course.id), + six.text_type(self.course.id), self.other_problem_urlname, requesting_user=self.student, ) @@ -128,7 +131,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): """ result = self.service.is_course_staff( self.student, - unicode(self.course.id) + six.text_type(self.course.id) ) self.assertFalse(result) @@ -136,7 +139,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): allow_access(self.course, self.student, 'staff') result = self.service.is_course_staff( self.student, - unicode(self.course.id) + six.text_type(self.course.id) ) self.assertTrue(result) @@ -163,7 +166,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): with mock.patch("lms.djangoapps.instructor.services.create_zendesk_ticket") as mock_create_zendesk_ticket: self.service.send_support_notification( - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), exam_name=args['exam_name'], student_username=args["student_username"], review_status="Suspicious", @@ -175,7 +178,7 @@ class InstructorServiceTests(SharedModuleStoreTestCase): args['url'] = 'http://review/url' with mock.patch("lms.djangoapps.instructor.services.create_zendesk_ticket") as mock_create_zendesk_ticket: self.service.send_support_notification( - course_id=unicode(self.course.id), + course_id=six.text_type(self.course.id), exam_name=args['exam_name'], student_username=args["student_username"], review_status="Suspicious", diff --git a/lms/djangoapps/instructor/tests/test_spoc_gradebook.py b/lms/djangoapps/instructor/tests/test_spoc_gradebook.py index ec12369438..b1a88db803 100644 --- a/lms/djangoapps/instructor/tests/test_spoc_gradebook.py +++ b/lms/djangoapps/instructor/tests/test_spoc_gradebook.py @@ -2,8 +2,11 @@ Tests of the instructor dashboard spoc gradebook """ +from __future__ import absolute_import + from django.urls import reverse from six import text_type +from six.moves import range from capa.tests.response_xml_factory import StringResponseXMLFactory from courseware.tests.factories import StudentModuleFactory @@ -51,7 +54,7 @@ class TestGradebook(SharedModuleStoreTestCase): data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) - for __ in xrange(USER_COUNT - 1) + for __ in range(USER_COUNT - 1) ] def setUp(self): @@ -59,7 +62,7 @@ class TestGradebook(SharedModuleStoreTestCase): instructor = AdminFactory.create() self.client.login(username=instructor.username, password='test') - self.users = [UserFactory.create() for _ in xrange(USER_COUNT)] + self.users = [UserFactory.create() for _ in range(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) diff --git a/lms/djangoapps/instructor/tests/test_tools.py b/lms/djangoapps/instructor/tests/test_tools.py index 5073a539e2..9ab7ac689d 100644 --- a/lms/djangoapps/instructor/tests/test_tools.py +++ b/lms/djangoapps/instructor/tests/test_tools.py @@ -15,7 +15,7 @@ from django.test import TestCase from opaque_keys.edx.keys import CourseKey from pytz import UTC -from edx_when import signals, api +from edx_when import api, signals from edx_when.field_data import DateLookupFieldData from student.tests.factories import UserFactory from xmodule.fields import Date diff --git a/lms/djangoapps/instructor/tests/utils.py b/lms/djangoapps/instructor/tests/utils.py index 84c34e1cf2..4d549eea7e 100644 --- a/lms/djangoapps/instructor/tests/utils.py +++ b/lms/djangoapps/instructor/tests/utils.py @@ -1,10 +1,13 @@ """ Utilities for instructor unit tests """ +from __future__ import absolute_import + import datetime import json import random +import six from pytz import UTC from util.date_utils import get_default_time_display @@ -55,7 +58,7 @@ class FakeEmail(FakeInfo): def __init__(self, email_id): super(FakeEmail, self).__init__() - self.id = unicode(email_id) # pylint: disable=invalid-name + self.id = six.text_type(email_id) # pylint: disable=invalid-name # Select a random data for create field year = random.randint(1950, 2000) month = random.randint(1, 12) diff --git a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py index 011b1eae53..177f365782 100644 --- a/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py +++ b/lms/djangoapps/instructor/tests/views/test_instructor_dashboard.py @@ -1,17 +1,22 @@ """ Unit tests for instructor_dashboard.py. """ +from __future__ import absolute_import + import datetime import ddt +import six from django.conf import settings from django.contrib.sites.models import Site -from django.urls import reverse from django.test.client import RequestFactory from django.test.utils import override_settings +from django.urls import reverse from mock import patch +from pyquery import PyQuery as pq from pytz import UTC from six import text_type +from six.moves import range from common.test.utils import XssTestMixin from course_modes.models import CourseMode @@ -19,11 +24,10 @@ from courseware.tabs import get_course_tab_list from courseware.tests.factories import StaffFactory, StudentModuleFactory, UserFactory from courseware.tests.helpers import LoginEnrollmentTestCase from edxmako.shortcuts import render_to_response -from lms.djangoapps.grades.config.waffle import waffle_flags, WRITABLE_GRADEBOOK +from lms.djangoapps.grades.config.waffle import WRITABLE_GRADEBOOK, waffle_flags from lms.djangoapps.instructor.views.gradebook_api import calculate_page_info from openedx.core.djangoapps.site_configuration.models import SiteConfiguration from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag -from pyquery import PyQuery as pq from shoppingcart.models import CourseRegCodeItem, Order, PaidCourseRegistration from student.models import CourseEnrollment from student.roles import CourseFinanceAdminRole @@ -127,7 +131,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT url = reverse( 'instructor_dashboard', kwargs={ - 'course_id': unicode(self.course_info.id) + 'course_id': six.text_type(self.course_info.id) } ) @@ -171,7 +175,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT url = reverse( 'instructor_dashboard', kwargs={ - 'course_id': unicode(self.course_info.id) + 'course_id': six.text_type(self.course_info.id) } ) @@ -188,7 +192,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT url = reverse( 'instructor_dashboard', kwargs={ - 'course_id': unicode(self.course_info.id) + 'course_id': six.text_type(self.course_info.id) } ) @@ -449,7 +453,7 @@ class TestInstructorDashboard(ModuleStoreTestCase, LoginEnrollmentTestCase, XssT @patch('lms.djangoapps.instructor.views.gradebook_api.render_to_response', intercept_renderer) @patch('lms.djangoapps.instructor.views.gradebook_api.MAX_STUDENTS_PER_PAGE_GRADE_BOOK', 1) def test_spoc_gradebook_pages(self): - for i in xrange(2): + for i in range(2): username = "user_%d" % i student = UserFactory.create(username=username) CourseEnrollmentFactory.create(user=student, course_id=self.course.id) @@ -541,7 +545,7 @@ class TestInstructorDashboardPerformance(ModuleStoreTestCase, LoginEnrollmentTes ) students = [] - for i in xrange(20): + for i in range(20): username = "user_%d" % i student = UserFactory.create(username=username) CourseEnrollmentFactory.create(user=student, course_id=self.course.id) @@ -569,7 +573,7 @@ class TestInstructorDashboardPerformance(ModuleStoreTestCase, LoginEnrollmentTes publish_item=True, start=datetime.datetime(2015, 4, 1, tzinfo=UTC), ) - for i in xrange(10): + for i in range(10): problem = ItemFactory.create( category="problem", parent=vertical,