Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOM-1832 : Run 2to3 #200

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions enterprise_data/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class Meta:

_DEFAULT_PASSWORD = 'test'

username = factory.Sequence(u'robot{0}'.format)
email = factory.Sequence(u'robot+test+{0}@edx.org'.format)
username = factory.Sequence('robot{0}'.format)
email = factory.Sequence('robot+test+{0}@edx.org'.format)
password = factory.PostGenerationMethodCall('set_password', _DEFAULT_PASSWORD)
first_name = factory.Sequence(u'Robot{0}'.format)
first_name = factory.Sequence('Robot{0}'.format)
last_name = 'Test'
is_staff = factory.lazy_attribute(lambda x: False)
is_active = True
Expand All @@ -80,8 +80,8 @@ class Meta:
enterprise_user_id = factory.lazy_attribute(lambda x: FAKER.random_int(min=1)) # pylint: disable=no-member
enterprise_sso_uid = factory.lazy_attribute(lambda x: FAKER.text(max_nb_chars=255)) # pylint: disable=no-member
user_account_creation_timestamp = datetime(2011, 1, 1, tzinfo=pytz.utc)
user_username = factory.Sequence(u'robot{0}'.format)
user_email = factory.Sequence(u'robot+test+{0}@edx.org'.format)
user_username = factory.Sequence('robot{0}'.format)
user_email = factory.Sequence('robot+test+{0}@edx.org'.format)
user_country_code = factory.lazy_attribute(lambda x: FAKER.country_code()) # pylint: disable=no-member
last_activity_date = datetime(2012, 1, 1).date()

Expand Down
8 changes: 4 additions & 4 deletions enterprise_data/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_empty_result_for_invalid_enterprise_uuid(self):
def test_get_queryset_returns_enrollments_with_passed_date_filter(self):
enterprise = EnterpriseUserFactory()
enterprise_id = enterprise.enterprise_id
url = u"{url}?passed_date=last_week".format(
url = "{url}?passed_date=last_week".format(
url=reverse('v0:enterprise-enrollments-list', kwargs={'enterprise_id': enterprise_id})
)

Expand Down Expand Up @@ -362,7 +362,7 @@ def test_get_queryset_returns_enrollments_with_audit_enrollment_filter(
def test_get_queryset_returns_enrollments_with_learner_activity_filter(self, activity_filter, expected_dates):
enterprise = EnterpriseUserFactory()
enterprise_id = enterprise.enterprise_id
url = u"{url}?learner_activity={activity_filter}".format(
url = "{url}?learner_activity={activity_filter}".format(
url=reverse('v0:enterprise-enrollments-list', kwargs={'enterprise_id': enterprise_id}),
activity_filter=activity_filter
)
Expand Down Expand Up @@ -408,7 +408,7 @@ def test_get_queryset_returns_learner_activity_filter_no_consent(self, activity_
"""
enterprise = EnterpriseUserFactory()
enterprise_id = enterprise.enterprise_id
url = u"{url}?learner_activity={activity_filter}".format(
url = "{url}?learner_activity={activity_filter}".format(
url=reverse('v0:enterprise-enrollments-list', kwargs={'enterprise_id': enterprise_id}),
activity_filter=activity_filter
)
Expand Down Expand Up @@ -493,7 +493,7 @@ def test_get_queryset_returns_learner_activity_filter_no_active_enrollments(
"""
enterprise = EnterpriseUserFactory()
enterprise_id = enterprise.enterprise_id
url = u"{url}?learner_activity={activity_filter}".format(
url = "{url}?learner_activity={activity_filter}".format(
url=reverse('v0:enterprise-enrollments-list', kwargs={'enterprise_id': enterprise_id}),
activity_filter=activity_filter
)
Expand Down
2 changes: 1 addition & 1 deletion enterprise_data_roles/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class EnterpriseDataFeatureRoleFactory(factory.django.DjangoModelFactory):
class Meta:
model = EnterpriseDataFeatureRole

name = factory.Sequence(u'User Role-{0}'.format)
name = factory.Sequence('User Role-{0}'.format)
description = factory.lazy_attribute(lambda x: FAKER.text(max_nb_chars=255)) # pylint: disable=no-member


Expand Down
2 changes: 1 addition & 1 deletion enterprise_reporting/clients/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def get_content_metadata(self, enterprise_customer_uuid, reporting_config):
content_metadata[item[key]] = item

# We only made this a dictionary to help filter out duplicates by a common key. We just want values now.
return content_metadata.values()
return list(content_metadata.values())


def extract_catalog_uuids_from_reporting_config(reporting_config):
Expand Down
19 changes: 8 additions & 11 deletions enterprise_reporting/external_resource_link_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
import os
import re
import sys
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from urllib.parse import urlparse

from py2neo import Graph

Expand All @@ -23,7 +20,7 @@
logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__)

AGGREGATE_REPORT_CSV_HEADER_ROW = u'Course Key,Course Title,Partner,External Domain,Count\n'
AGGREGATE_REPORT_CSV_HEADER_ROW = 'Course Key,Course Title,Partner,External Domain,Count\n'


def create_csv_string(processed_results, header_row, additional_columns):
Expand All @@ -41,8 +38,8 @@ def create_csv_string(processed_results, header_row, additional_columns):

Returns (unicode) string
"""
for course_key, data in processed_results.items():
header_row += u'{},"{}",{},{}\n'.format(
for course_key, data in list(processed_results.items()):
header_row += '{},"{}",{},{}\n'.format(
course_key,
data['course_title'],
data['organization'],
Expand All @@ -56,15 +53,15 @@ def create_columns_for_aggregate_report(data):
Creates a csv string for additional columns in report
"""
urls_sorted_by_counts = sorted(
data['domain_count'].items(),
list(data['domain_count'].items()),
key=operator.itemgetter(1),
reverse=True
)
stringified_urls_and_counts = [
u'{},{}'.format(url, count)
'{},{}'.format(url, count)
for url, count in urls_sorted_by_counts
]
return u'\n,,,'.join(stringified_urls_and_counts)
return '\n,,,'.join(stringified_urls_and_counts)


def gather_links_from_html(html_string):
Expand Down Expand Up @@ -136,7 +133,7 @@ def process_coursegraph_results(raw_results):
# calculate the unique counts for all the urls
domains_with_counts = dict(Counter(domains))

for domain, count in domains_with_counts.items():
for domain, count in list(domains_with_counts.items()):
if domain in processed_results[course_key]['domain_count']:
processed_results[course_key]['domain_count'][domain] += count
else:
Expand Down
2 changes: 1 addition & 1 deletion enterprise_reporting/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _generate_enterprise_report_catalog_csv(self):

LOGGER.info('Beginning to write content metadata groups to CSVs...')
files = []
for content_type, grouped_items in grouped_content_metadata.items():
for content_type, grouped_items in list(grouped_content_metadata.items()):
with open(self.data_report_file_name_with.format(content_type), 'w') as data_report_file:
writer = csv.writer(data_report_file)
if grouped_items:
Expand Down
10 changes: 5 additions & 5 deletions enterprise_reporting/tests/test_external_link_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ def test_create_aggregate_report_csv_string(self):
}),
])
expected = (
u'Course Key,Course Title,Partner,External Domain,Count\n'
u'course-v1:I+am+a+test1,"course1",edx,http://www.google.com,2\n'
u',,,http://www.facebook.com,1\n'
u'course-v1:I+am+a+test2,"course2",edx,http://www.google2.com,4\n'
u'course-v1:I+am+a+test3,"course3",edx2,http://www.google3.com,1\n'
'Course Key,Course Title,Partner,External Domain,Count\n'
'course-v1:I+am+a+test1,"course1",edx,http://www.google.com,2\n'
',,,http://www.facebook.com,1\n'
'course-v1:I+am+a+test2,"course2",edx,http://www.google2.com,4\n'
'course-v1:I+am+a+test3,"course3",edx2,http://www.google3.com,1\n'
)
actual = create_csv_string(
processed_results,
Expand Down
14 changes: 7 additions & 7 deletions enterprise_reporting/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def prepare_attachments(attachment_data):
"""

attachments = []
for filename, data in attachment_data.items():
for filename, data in list(attachment_data.items()):
if data is None:
msg_attachment = MIMEApplication(open(filename, 'rb').read())
else:
Expand Down Expand Up @@ -228,14 +228,14 @@ def format_nested(nested, _key=None):

flattened = []
target_is_key = target == 'key'
for key, value in OrderedDict(sorted(d.items())).items():
for key, value in list(OrderedDict(sorted(d.items())).items()):

# Simple case: recursively flatten the dictionary.
if isinstance(value, dict):
flattened += map(
flattened += list(map(
format_nested if target_is_key else lambda x: x,
flatten_dict(value, target=target)
)
))

# We are suddenly in muddy waters, because lists can have multiple types within them in JSON.
elif isinstance(value, list):
Expand Down Expand Up @@ -263,11 +263,11 @@ def format_nested(nested, _key=None):
_flattened_dict = [format_nested(flattened_item, _key=index)
for flattened_item in _flattened_dict]

flattened += map(format_nested if target_is_key else lambda x: x, _flattened_dict)
flattened += list(map(format_nested if target_is_key else lambda x: x, _flattened_dict))

# All items are non-dict, so just directly add either the index or the value.
else:
flattened += map(format_nested, range(len(value))) if target_is_key else value
flattened += list(map(format_nested, list(range(len(value))))) if target_is_key else value

# Kindergarten -- just add to the list.
else:
Expand All @@ -282,7 +282,7 @@ def generate_data(item, target='key' or 'value'):
"""
data = []
target_is_key = target == 'key'
for key, value in OrderedDict(sorted(item.items())).items():
for key, value in list(OrderedDict(sorted(item.items())).items()):
if target_is_key:
data.append(key)
continue
Expand Down