Fix for decode errors in bulk_email.tests.test_course_optout.py

This commit is contained in:
Nimisha Asthagiri
2019-08-19 14:26:48 -04:00
parent f17f9d3862
commit d564af8301
6 changed files with 6 additions and 6 deletions

View File

@@ -121,7 +121,7 @@ def server_track(request, event_type, event, page=None):
"event_source": "server",
"event_type": event_type,
"event": event,
"agent": _get_request_header(request, 'HTTP_USER_AGENT').decode('latin1'),
"agent": _get_request_header(request, 'HTTP_USER_AGENT').encode().decode('latin1'),
"page": page,
"time": datetime.datetime.utcnow().replace(tzinfo=pytz.utc),
"host": _get_request_header(request, 'SERVER_NAME'),

View File

@@ -57,7 +57,7 @@ class TestOptoutCourseEmails(ModuleStoreTestCase):
response = self.client.get(url)
email_section = '<div class="vert-left send-email" id="section-send-email">'
# If this fails, it is likely because BulkEmailFlag.is_enabled() is set to False
self.assertIn(email_section, response.content)
self.assertIn(email_section, response.content.decode('utf-8'))
def test_optout_course(self):
"""

View File

@@ -739,7 +739,7 @@ def _section_send_email(course, access):
usage_id_serializer=lambda usage_id: quote_slashes(six.text_type(usage_id)),
# Generate a new request_token here at random, because this module isn't connected to any other
# xblock rendering.
request_token=uuid.uuid1().get_hex()
request_token=uuid.uuid1().hex
)
cohorts = []
if is_course_cohorted(course_key):

View File

@@ -320,7 +320,7 @@ def submit_bulk_course_email(request, course_key, email_id):
task_input = {'email_id': email_id, 'to_option': targets}
task_key_stub = str(email_id)
# create the key value by using MD5 hash:
task_key = hashlib.md5(task_key_stub).hexdigest()
task_key = hashlib.md5(task_key_stub.encode('utf-8')).hexdigest()
return submit_task(request, task_type, task_class, course_key, task_input, task_key)

View File

@@ -140,7 +140,7 @@ def _get_xmodule_instance_args(request, task_id):
request_info = {'username': request.user.username,
'user_id': request.user.id,
'ip': request.META['REMOTE_ADDR'],
'agent': request.META.get('HTTP_USER_AGENT', '').decode('latin1'),
'agent': request.META.get('HTTP_USER_AGENT', '').encode().decode('latin1'),
'host': request.META['SERVER_NAME'],
}

View File

@@ -59,7 +59,7 @@ if course_key:
}
if not course_id:
user_metadata['course_id'] = unicode(course_key)
user_metadata['course_id'] = six.text_type(course_key)
elif isinstance(course_key, six.string_types):
user_metadata['course_id'] = course_key