diff --git a/lms/djangoapps/bulk_email/migrations/0001_initial.py b/lms/djangoapps/bulk_email/migrations/0001_initial.py index fdb7c68c54..2ded5223e6 100644 --- a/lms/djangoapps/bulk_email/migrations/0001_initial.py +++ b/lms/djangoapps/bulk_email/migrations/0001_initial.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals -from django.db import migrations, models from django.conf import settings +from django.db import migrations, models from opaque_keys.edx.django.models import CourseKeyField diff --git a/lms/djangoapps/bulk_email/migrations/0002_data__load_course_email_template.py b/lms/djangoapps/bulk_email/migrations/0002_data__load_course_email_template.py index fe5a40232d..e41e62332f 100644 --- a/lms/djangoapps/bulk_email/migrations/0002_data__load_course_email_template.py +++ b/lms/djangoapps/bulk_email/migrations/0002_data__load_course_email_template.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.core.management import call_command from django.db import migrations, models + def forwards(apps, schema_editor): """Load data from the fixture""" CourseEmailTemplate = apps.get_model("bulk_email", "CourseEmailTemplate") diff --git a/lms/djangoapps/bulk_email/migrations/0003_config_model_feature_flag.py b/lms/djangoapps/bulk_email/migrations/0003_config_model_feature_flag.py index ee26fce7bc..4bd12d11f0 100644 --- a/lms/djangoapps/bulk_email/migrations/0003_config_model_feature_flag.py +++ b/lms/djangoapps/bulk_email/migrations/0003_config_model_feature_flag.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals -from django.db import migrations, models import django.db.models.deletion from django.conf import settings +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/lms/djangoapps/bulk_email/migrations/0004_add_email_targets.py b/lms/djangoapps/bulk_email/migrations/0004_add_email_targets.py index 4acc63d9d3..32c34add75 100644 --- a/lms/djangoapps/bulk_email/migrations/0004_add_email_targets.py +++ b/lms/djangoapps/bulk_email/migrations/0004_add_email_targets.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models diff --git a/lms/djangoapps/bulk_email/migrations/0005_move_target_data.py b/lms/djangoapps/bulk_email/migrations/0005_move_target_data.py index 44c364fad6..cb2b492a86 100644 --- a/lms/djangoapps/bulk_email/migrations/0005_move_target_data.py +++ b/lms/djangoapps/bulk_email/migrations/0005_move_target_data.py @@ -1,10 +1,12 @@ # -*- coding: utf- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models from django.db.utils import DatabaseError + from bulk_email.models import EMAIL_TARGETS, SEND_TO_MYSELF + def to_option_to_targets(apps, schema_editor): CourseEmail = apps.get_model("bulk_email", "CourseEmail") Target = apps.get_model("bulk_email", "Target") diff --git a/lms/djangoapps/bulk_email/migrations/0006_course_mode_targets.py b/lms/djangoapps/bulk_email/migrations/0006_course_mode_targets.py index 98cf5a3310..bb108cfb87 100644 --- a/lms/djangoapps/bulk_email/migrations/0006_course_mode_targets.py +++ b/lms/djangoapps/bulk_email/migrations/0006_course_mode_targets.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import absolute_import, unicode_literals from django.db import migrations, models diff --git a/lms/djangoapps/bulk_email/tests/test_course_optout.py b/lms/djangoapps/bulk_email/tests/test_course_optout.py index 1d209bbfa3..a48d700744 100644 --- a/lms/djangoapps/bulk_email/tests/test_course_optout.py +++ b/lms/djangoapps/bulk_email/tests/test_course_optout.py @@ -2,20 +2,22 @@ """ Unit tests for student optouts from course email """ +from __future__ import absolute_import + import json from django.core import mail from django.core.management import call_command from django.urls import reverse +from edx_ace.channel import ChannelType +from edx_ace.message import Message +from edx_ace.policy import PolicyResult +from edx_ace.recipient import Recipient from mock import Mock, patch from six import text_type from bulk_email.models import BulkEmailFlag from bulk_email.policies import CourseEmailOptout -from edx_ace.message import Message -from edx_ace.recipient import Recipient -from edx_ace.policy import PolicyResult -from edx_ace.channel import ChannelType from student.models import CourseEnrollment from student.tests.factories import AdminFactory, CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase diff --git a/lms/djangoapps/bulk_email/tests/test_email.py b/lms/djangoapps/bulk_email/tests/test_email.py index 89cc7f6fbf..7a83f0f7b4 100644 --- a/lms/djangoapps/bulk_email/tests/test_email.py +++ b/lms/djangoapps/bulk_email/tests/test_email.py @@ -2,17 +2,21 @@ """ Unit tests for sending course email """ +from __future__ import absolute_import + import json import os from unittest import skipIf import ddt +import six +from six.moves import range from django.conf import settings from django.core import mail from django.core.mail.message import forbid_multi_line_headers from django.core.management import call_command -from django.urls import reverse from django.test.utils import override_settings +from django.urls import reverse from django.utils.translation import get_language from markupsafe import escape from mock import Mock, patch @@ -67,7 +71,7 @@ class EmailSendFromDashboardTestCase(SharedModuleStoreTestCase): self.instructor = InstructorFactory(course_key=self.course.id) self.staff = [ - StaffFactory(course_key=self.course.id) for __ in xrange(STAFF_COUNT) + StaffFactory(course_key=self.course.id) for __ in range(STAFF_COUNT) ] def create_students(self): @@ -75,7 +79,7 @@ class EmailSendFromDashboardTestCase(SharedModuleStoreTestCase): Creates users and enrolls them in self.course. Assigns these users to self.students. """ - self.students = [UserFactory() for _ in xrange(STUDENT_COUNT)] + self.students = [UserFactory() for _ in range(STUDENT_COUNT)] for student in self.students: CourseEnrollmentFactory.create(user=student, course_id=self.course.id) @@ -90,7 +94,7 @@ class EmailSendFromDashboardTestCase(SharedModuleStoreTestCase): Goes to the instructor dashboard to verify that the email section is there. """ - url = reverse('instructor_dashboard', kwargs={'course_id': unicode(self.course.id)}) + url = reverse('instructor_dashboard', kwargs={'course_id': six.text_type(self.course.id)}) # Response loads the whole instructor dashboard, so no need to explicitly # navigate to a particular email section response = self.client.get(url) @@ -121,10 +125,10 @@ class EmailSendFromDashboardTestCase(SharedModuleStoreTestCase): # Pulling up the instructor dash email view here allows us to test sending emails in tests self.goto_instructor_dash_email_view() self.send_mail_url = reverse( - 'send_email', kwargs={'course_id': unicode(self.course.id)} + 'send_email', kwargs={'course_id': six.text_type(self.course.id)} ) self.success_content = { - 'course_id': unicode(self.course.id), + 'course_id': six.text_type(self.course.id), 'success': True, } @@ -338,7 +342,7 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) """ CourseMode.objects.create(mode_slug='test', course_id=self.course.id) for student in self.students: - update_enrollment(student, unicode(self.course.id), 'test') + update_enrollment(student, six.text_type(self.course.id), 'test') test_email = { 'action': 'Send email', 'send_to': '["track:test"]', @@ -362,7 +366,7 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) # Create a mode and designate an enrolled user to be placed in that mode CourseMode.objects.create(mode_slug='test_mode', course_id=self.course.id) test_mode_student = self.students[0] - update_enrollment(test_mode_student, unicode(self.course.id), 'test_mode') + update_enrollment(test_mode_student, six.text_type(self.course.id), 'test_mode') # Take another user already enrolled in the course, then enroll them in # another course but in that same test mode @@ -373,7 +377,7 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) user=test_mode_student_other_course, course_id=other_course.id ) - update_enrollment(test_mode_student_other_course, unicode(other_course.id), 'test_mode') + update_enrollment(test_mode_student_other_course, six.text_type(other_course.id), 'test_mode') # Send the emails... test_email = { @@ -537,7 +541,7 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) self.assertEqual(len(unexpected_from_addr), 137) self.login_as_user(instructor) - send_mail_url = reverse('send_email', kwargs={'course_id': unicode(course.id)}) + send_mail_url = reverse('send_email', kwargs={'course_id': six.text_type(course.id)}) response = self.client.post(send_mail_url, test_email) self.assertTrue(json.loads(response.content)['success']) @@ -563,7 +567,7 @@ class TestEmailSendFromDashboardMockedHtmlToText(EmailSendFromDashboardTestCase) mock_factory = MockCourseEmailResult() email_mock.side_effect = mock_factory.get_mock_update_subtask_status() added_users = [] - for _ in xrange(LARGE_NUM_EMAILS): + for _ in range(LARGE_NUM_EMAILS): user = UserFactory() added_users.append(user) CourseEnrollmentFactory.create(user=user, course_id=self.course.id) diff --git a/lms/djangoapps/bulk_email/tests/test_err_handling.py b/lms/djangoapps/bulk_email/tests/test_err_handling.py index 131bf0c61a..75a4683973 100644 --- a/lms/djangoapps/bulk_email/tests/test_err_handling.py +++ b/lms/djangoapps/bulk_email/tests/test_err_handling.py @@ -2,6 +2,8 @@ """ Unit tests for handling email sending errors """ +from __future__ import absolute_import + import json from itertools import cycle from smtplib import SMTPConnectError, SMTPDataError, SMTPServerDisconnected @@ -10,11 +12,12 @@ import ddt from celery.states import RETRY, SUCCESS from django.conf import settings from django.core.management import call_command -from django.urls import reverse from django.db import DatabaseError +from django.urls import reverse from mock import Mock, patch from opaque_keys.edx.locator import CourseLocator from six import text_type +from six.moves import range from bulk_email.models import SEND_TO_MYSELF, BulkEmailFlag, CourseEmail from bulk_email.tasks import perform_delegate_email_batches, send_course_email @@ -105,7 +108,7 @@ class TestEmailErrors(ModuleStoreTestCase): get_conn.return_value.send_messages.side_effect = cycle([SMTPDataError(554, "Email address is blacklisted"), None, None, None]) # Don't forget to account for the "myself" instructor user - students = [UserFactory() for _ in xrange(settings.BULK_EMAIL_EMAILS_PER_TASK - 1)] + students = [UserFactory() for _ in range(settings.BULK_EMAIL_EMAILS_PER_TASK - 1)] for student in students: CourseEnrollmentFactory.create(user=student, course_id=self.course.id) diff --git a/lms/djangoapps/bulk_email/tests/test_forms.py b/lms/djangoapps/bulk_email/tests/test_forms.py index 851a2b7e7e..5bb212472a 100644 --- a/lms/djangoapps/bulk_email/tests/test_forms.py +++ b/lms/djangoapps/bulk_email/tests/test_forms.py @@ -3,6 +3,8 @@ Unit tests for bulk-email-related forms. """ +from __future__ import absolute_import + from opaque_keys.edx.locator import CourseLocator from six import text_type diff --git a/lms/djangoapps/bulk_email/tests/test_models.py b/lms/djangoapps/bulk_email/tests/test_models.py index c98c612ae1..c3bf79fdc1 100644 --- a/lms/djangoapps/bulk_email/tests/test_models.py +++ b/lms/djangoapps/bulk_email/tests/test_models.py @@ -1,6 +1,8 @@ """ Unit tests for bulk-email-related models. """ +from __future__ import absolute_import + import datetime import ddt diff --git a/lms/djangoapps/bulk_email/tests/test_signals.py b/lms/djangoapps/bulk_email/tests/test_signals.py index 8673e4f1ea..60dea496b6 100644 --- a/lms/djangoapps/bulk_email/tests/test_signals.py +++ b/lms/djangoapps/bulk_email/tests/test_signals.py @@ -1,6 +1,8 @@ """ Unit tests for student optouts from course email """ +from __future__ import absolute_import + import json from django.core import mail diff --git a/lms/djangoapps/bulk_email/tests/test_tasks.py b/lms/djangoapps/bulk_email/tests/test_tasks.py index aa1f253784..d2fe1842bb 100644 --- a/lms/djangoapps/bulk_email/tests/test_tasks.py +++ b/lms/djangoapps/bulk_email/tests/test_tasks.py @@ -6,7 +6,8 @@ Runs tasks on answers to course problems to validate that code paths actually work. """ -from __future__ import print_function +from __future__ import absolute_import, print_function + import json from itertools import chain, cycle, repeat from smtplib import SMTPAuthenticationError, SMTPConnectError, SMTPDataError, SMTPServerDisconnected @@ -29,6 +30,7 @@ from django.conf import settings from django.core.management import call_command from mock import Mock, patch from opaque_keys.edx.locator import CourseLocator +from six.moves import range from bulk_email.models import SEND_TO_LEARNERS, SEND_TO_MYSELF, SEND_TO_STAFF, CourseEmail, Optout from bulk_email.tasks import _get_course_email_context @@ -137,7 +139,7 @@ class TestBulkEmailInstructorTask(InstructorTaskCourseTestCase): def _create_students(self, num_students): """Create students for testing""" - return [self.create_student('robot%d' % i) for i in xrange(num_students)] + return [self.create_student('robot%d' % i) for i in range(num_students)] def _assert_single_subtask_status(self, entry, succeeded, failed=0, skipped=0, retried_nomax=0, retried_withmax=0): """Compare counts with 'subtasks' entry in InstructorTask table.""" @@ -148,7 +150,7 @@ class TestBulkEmailInstructorTask(InstructorTaskCourseTestCase): self.assertEquals(subtask_info.get('failed'), 0 if succeeded > 0 else 1) # verify individual subtask status: subtask_status_info = subtask_info.get('status') - task_id_list = subtask_status_info.keys() + task_id_list = list(subtask_status_info.keys()) self.assertEquals(len(task_id_list), 1) task_id = task_id_list[0] subtask_status = subtask_status_info.get(task_id)