cleanup references of python 2 & <3.11 (#35799)
* chore: cleanup of old python references
This commit is contained in:
@@ -38,28 +38,20 @@ class LinkedInAddToProfileUrlTests(TestCase):
|
||||
def test_linked_in_url(self, cert_mode, expected_cert_name):
|
||||
config = LinkedInAddToProfileConfigurationFactory()
|
||||
|
||||
# We can switch to this once edx-platform reaches Python 3.8
|
||||
# expected_url = (
|
||||
# 'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&'
|
||||
# 'name={platform}+{cert_name}&certUrl={cert_url}&'
|
||||
# 'organizationId={company_identifier}'
|
||||
# ).format(
|
||||
# platform=quote(settings.PLATFORM_NAME.encode('utf-8')),
|
||||
# cert_name=expected_cert_name,
|
||||
# cert_url=quote(self.CERT_URL, safe=''),
|
||||
# company_identifier=config.company_identifier,
|
||||
# )
|
||||
expected_url = (
|
||||
'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&'
|
||||
'name={platform}+{cert_name}&certUrl={cert_url}&'
|
||||
'organizationId={company_identifier}'
|
||||
).format(
|
||||
platform=quote(settings.PLATFORM_NAME.encode('utf-8')),
|
||||
cert_name=expected_cert_name,
|
||||
cert_url=quote(self.CERT_URL, safe=''),
|
||||
company_identifier=config.company_identifier,
|
||||
)
|
||||
|
||||
actual_url = config.add_to_profile_url(self.COURSE_NAME, cert_mode, self.CERT_URL)
|
||||
|
||||
# We can switch to this instead of the assertIn once edx-platform reaches Python 3.8
|
||||
# There was a problem with dict ordering in the add_to_profile_url function that will go away then.
|
||||
# self.assertEqual(actual_url, expected_url)
|
||||
|
||||
assert 'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME' in actual_url
|
||||
assert f'&name={quote(settings.PLATFORM_NAME.encode("utf-8"))}+{expected_cert_name}' in actual_url
|
||||
assert '&certUrl={cert_url}'.format(cert_url=quote(self.CERT_URL, safe='')) in actual_url
|
||||
assert f'&organizationId={config.company_identifier}' in actual_url
|
||||
self.assertEqual(actual_url, expected_url)
|
||||
|
||||
@ddt.data(
|
||||
('honor', 'Honor+Code+Credential+for+Test+Course+%E2%98%83'),
|
||||
@@ -72,26 +64,18 @@ class LinkedInAddToProfileUrlTests(TestCase):
|
||||
def test_linked_in_url_with_cert_name_override(self, cert_mode, expected_cert_name):
|
||||
config = LinkedInAddToProfileConfigurationFactory()
|
||||
|
||||
# We can switch to this once edx-platform reaches Python 3.8
|
||||
# expected_url = (
|
||||
# 'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&'
|
||||
# 'name={platform}+{cert_name}&certUrl={cert_url}&'
|
||||
# 'organizationId={company_identifier}'
|
||||
# ).format(
|
||||
# platform=quote(settings.PLATFORM_NAME.encode('utf-8')),
|
||||
# cert_name=expected_cert_name,
|
||||
# cert_url=quote(self.CERT_URL, safe=''),
|
||||
# company_identifier=config.company_identifier,
|
||||
# )
|
||||
expected_url = (
|
||||
'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&'
|
||||
'name={platform}+{cert_name}&certUrl={cert_url}&'
|
||||
'organizationId={company_identifier}'
|
||||
).format(
|
||||
platform=quote(settings.PLATFORM_NAME.encode('utf-8')),
|
||||
cert_name=expected_cert_name,
|
||||
cert_url=quote(self.CERT_URL, safe=''),
|
||||
company_identifier=config.company_identifier,
|
||||
)
|
||||
|
||||
with with_site_configuration_context(configuration=self.SITE_CONFIGURATION):
|
||||
actual_url = config.add_to_profile_url(self.COURSE_NAME, cert_mode, self.CERT_URL)
|
||||
|
||||
# We can switch to this instead of the assertIn once edx-platform reaches Python 3.8
|
||||
# There was a problem with dict ordering in the add_to_profile_url function that will go away then.
|
||||
# self.assertEqual(actual_url, expected_url)
|
||||
|
||||
assert 'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME' in actual_url
|
||||
assert f'&name={quote(settings.PLATFORM_NAME.encode("utf-8"))}+{expected_cert_name}' in actual_url
|
||||
assert '&certUrl={cert_url}'.format(cert_url=quote(self.CERT_URL, safe='')) in actual_url
|
||||
assert f'&organizationId={config.company_identifier}' in actual_url
|
||||
self.assertEqual(actual_url, expected_url)
|
||||
|
||||
@@ -440,28 +440,19 @@ class DashboardTest(ModuleStoreTestCase, TestVerificationBase):
|
||||
assert response.status_code == 200
|
||||
self.assertContains(response, 'Add Certificate to LinkedIn')
|
||||
|
||||
# We can switch to this and the commented out assertContains once edx-platform reaches Python 3.8
|
||||
# expected_url = (
|
||||
# 'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&'
|
||||
# 'name={platform}+Honor+Code+Certificate+for+Omega&certUrl={cert_url}&'
|
||||
# 'organizationId={company_identifier}'
|
||||
# ).format(
|
||||
# platform=quote(settings.PLATFORM_NAME.encode('utf-8')),
|
||||
# cert_url=quote(cert.download_url, safe=''),
|
||||
# company_identifier=linkedin_config.company_identifier,
|
||||
# )
|
||||
|
||||
# self.assertContains(response, escape(expected_url))
|
||||
|
||||
# These can be removed (in favor of the above) once we are on Python 3.8. Fails in 3.5 because of dict ordering
|
||||
self.assertContains(response, escape('https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME'))
|
||||
self.assertContains(response, escape('&name={platform}+Honor+Code+Certificate+for+Omega'.format(
|
||||
platform=quote(settings.PLATFORM_NAME.encode('utf-8'))
|
||||
)))
|
||||
self.assertContains(response, escape('&certUrl={cert_url}'.format(cert_url=quote(cert.download_url, safe=''))))
|
||||
self.assertContains(response, escape('&organizationId={company_identifier}'.format(
|
||||
expected_url = (
|
||||
'https://www.linkedin.com/profile/add?startTask=CERTIFICATION_NAME&'
|
||||
'name={platform}+Honor+Code+Certificate+for+Omega&'
|
||||
'certUrl={cert_url}&'
|
||||
'organizationId={company_identifier}'
|
||||
).format(
|
||||
platform=quote(settings.PLATFORM_NAME.encode('utf-8')),
|
||||
cert_url=quote(cert.download_url, safe=''),
|
||||
company_identifier=linkedin_config.company_identifier
|
||||
)))
|
||||
)
|
||||
|
||||
# Single assertion for the expected LinkedIn URL
|
||||
self.assertContains(response, escape(expected_url))
|
||||
|
||||
@skip_unless_lms
|
||||
def test_dashboard_metadata_caching(self):
|
||||
|
||||
@@ -53,13 +53,11 @@ def cache_if_anonymous(*get_parameters):
|
||||
# specifically the branding index, to do authentication.
|
||||
# If that page is cached the authentication doesn't
|
||||
# happen, so we disable the cache when that feature is enabled.
|
||||
if (
|
||||
not request.user.is_authenticated
|
||||
):
|
||||
if not request.user.is_authenticated:
|
||||
# Use the cache. The same view accessed through different domain names may
|
||||
# return different things, so include the domain name in the key.
|
||||
domain = str(request.META.get('HTTP_HOST')) + '.'
|
||||
cache_key = domain + "cache_if_anonymous." + get_language() + '.' + request.path
|
||||
domain = request.META.get('HTTP_HOST', '') + '.'
|
||||
cache_key = f"{domain}cache_if_anonymous.{get_language()}.{request.path}"
|
||||
|
||||
# Include the values of GET parameters in the cache key.
|
||||
for get_parameter in get_parameters:
|
||||
@@ -67,24 +65,20 @@ def cache_if_anonymous(*get_parameters):
|
||||
if parameter_value is not None:
|
||||
# urlencode expects data to be of type str, and doesn't deal well with Unicode data
|
||||
# since it doesn't provide a way to specify an encoding.
|
||||
cache_key = cache_key + '.' + urlencode({
|
||||
get_parameter: str(parameter_value).encode('utf-8')
|
||||
})
|
||||
cache_key += '.' + urlencode({get_parameter: str(parameter_value).encode('utf-8')})
|
||||
|
||||
response = cache.get(cache_key)
|
||||
|
||||
if response:
|
||||
# A hack to ensure that the response data is a valid text type for both Python 2 and 3.
|
||||
response_content = list(response._container) # lint-amnesty, pylint: disable=bad-option-value, protected-access, protected-member
|
||||
response.content = b''
|
||||
for item in response_content:
|
||||
response.write(item)
|
||||
# Ensure that response content is properly handled for caching
|
||||
response.content = (
|
||||
# pylint: disable=protected-access
|
||||
b''.join(response._container) if hasattr(response, '_container') else response.content
|
||||
)
|
||||
else:
|
||||
response = view_func(request, *args, **kwargs)
|
||||
cache.set(cache_key, response, 60 * 3)
|
||||
|
||||
return response
|
||||
|
||||
else:
|
||||
# Don't use the cache.
|
||||
return view_func(request, *args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user