Skip to content
Snippets Groups Projects
Commit 24c0974f authored by Feanil Patel's avatar Feanil Patel
Browse files

BOM-619 Fix csv encoding/decoding in management command test.

parent ae2c3b8e
No related branches found
No related tags found
No related merge requests found
......@@ -33,6 +33,7 @@ from django.core.management.base import BaseCommand, CommandError
from django.db import connections
from django.utils import timezone
from opaque_keys.edx.keys import CourseKey
import six
from six import text_type
from six.moves import range
......@@ -251,14 +252,19 @@ class Command(BaseCommand):
else:
pref_set_datetime = self.DEFAULT_DATETIME_STR
if not full_name:
full_name = ""
# Only encode to utf-8 in python2 because python3's csv writer can handle unicode.
writer.writerow({
"user_id": user_id,
"username": username.encode('utf-8'),
"email": email.encode('utf-8'),
"username": username.encode('utf-8') if six.PY2 else username,
"email": email.encode('utf-8') if six.PY2 else email,
# There should not be a case where users are without full_names. We only need this safe check because
# of ECOM-1995.
"full_name": full_name.encode('utf-8') if full_name else '',
"course_id": course_id.encode('utf-8'),
"full_name": full_name.encode('utf-8') if six.PY2 else full_name,
"course_id": course_id.encode('utf-8') if six.PY2 else course_id,
"is_opted_in_for_email": is_opted_in if is_opted_in else "True",
"preference_set_datetime": pref_set_datetime,
})
......
......@@ -9,6 +9,7 @@ import tempfile
from collections import defaultdict
import ddt
import six
from django.contrib.auth.models import User
from django.core.management import call_command
from django.core.management.base import CommandError
......@@ -213,7 +214,15 @@ class EmailOptInListTest(ModuleStoreTestCase):
# Execute the command, but exclude the second course from the list
output = self._run_command(self.TEST_ORG, chunk_size=2)
course_ids = [row['course_id'].strip().decode('utf-8') for row in output]
course_ids = []
for row in output:
course_id = row['course_id'].strip()
# Python3 takes care of the decoding in the csv object
# but python 2 doesn't
if six.PY2:
course_id = course_id.decode('utf-8')
course_ids.append(course_id)
for course in self.courses:
assert text_type(course.id) in course_ids
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment