Skip to content

Commit

Permalink
Merge branch 'master' into umar/remove-old-boto
Browse files Browse the repository at this point in the history
  • Loading branch information
mumarkhan999 committed Feb 8, 2023
2 parents 09ee98d + 65da5b5 commit 81fbb85
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 13 deletions.
8 changes: 5 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ Please give your pull request a short but descriptive title.
Use conventional commits to separate and summarize commits logically:
https://open-edx-proposals.readthedocs.io/en/latest/oep-0051-bp-conventional-commits.html
Use this template as a guide. Omit sections that don't apply. You may link to information rather than copy it.
More details about the template are at https://github.com/openedx/open-edx-proposals/pull/180
(link will be updated when that document merges)
Use this template as a guide. Omit sections that don't apply.
You may link to information rather than copy it, but only if the link is publicly
readable. If you must linked information must be private (because it has secrets),
clearly label the link as private.
-->

## Description
Expand Down
9 changes: 9 additions & 0 deletions cms/djangoapps/contentstore/views/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import LibraryLocator
from path import Path as path
from storages.backends.s3boto import S3BotoStorage
from storages.backends.s3boto3 import S3Boto3Storage
from user_tasks.conf import settings as user_tasks_settings
from user_tasks.models import UserTaskArtifact, UserTaskStatus
Expand Down Expand Up @@ -380,6 +381,14 @@ def export_status_handler(request, course_key_string):
artifact = UserTaskArtifact.objects.get(status=task_status, name='Output')
if isinstance(artifact.file.storage, FileSystemStorage):
output_url = reverse_course_url('export_output_handler', course_key)
elif isinstance(artifact.file.storage, S3BotoStorage):
filename = os.path.basename(artifact.file.name)
disposition = f'attachment; filename="{filename}"'
output_url = artifact.file.storage.url(artifact.file.name, response_headers={
'response-content-disposition': disposition,
'response-content-encoding': 'application/octet-stream',
'response-content-type': 'application/x-tgz'
})
elif isinstance(artifact.file.storage, S3Boto3Storage):
filename = os.path.basename(artifact.file.name)
disposition = f'attachment; filename="{filename}"'
Expand Down
3 changes: 1 addition & 2 deletions common/djangoapps/student/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from django.contrib.auth.models import AnonymousUser, User # lint-amnesty, pylint: disable=imported-auth-user
from django.core.cache import cache
from django.conf import settings
from django.db.models import signals # pylint: disable=unused-import
from django.db.models.functions import Lower
from django.test import TestCase, override_settings
from edx_toggles.toggles.testutils import override_waffle_flag
Expand Down Expand Up @@ -832,7 +831,7 @@ def test_is_marketable_set_to_false_for_user_created_via_management_command(self
'username': 'some_user',
'name': 'Student Person',
'age': -1,
'yearOfBirth': 2022,
'yearOfBirth': datetime.datetime.today().year,
'education': None,
'address': None,
'gender': 'Male',
Expand Down
36 changes: 36 additions & 0 deletions lms/djangoapps/learner_home/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,42 @@ def test_get_cert_statuses(self, mock_get_cert_info):
},
)

@patch.dict(settings.FEATURES, ENTERPRISE_ENABLED=False)
@patch("lms.djangoapps.learner_home.views.cert_info")
def test_get_cert_statuses_exception(self, mock_get_cert_info):
"""Test that cert information gets loaded correctly"""

# Given I am logged in
self.log_in()

# (and we have tons of mocks to avoid integration tests)
mock_enrollment = create_test_enrollment(
self.user, course_mode=CourseMode.VERIFIED
)

# but have an issue with a particular certificate
mock_get_cert_info.side_effect = Exception("test exception")

# When I request the dashboard
response = self.client.get(self.view_url)

# Then I get the expected success response
assert response.status_code == 200
response_data = json.loads(response.content)

empty_cert_data = {
"availableDate": None,
"isRestricted": False,
"isEarned": False,
"isDownloadable": False,
"certPreviewUrl": None,
}

# with empty cert data instead of a break
self.assertDictEqual(
response_data["courses"][0]["certificate"], empty_cert_data
)

@patch.dict(settings.FEATURES, ENTERPRISE_ENABLED=False)
@patch("openedx.core.djangoapps.programs.utils.get_programs")
def test_get_for_one_of_course_programs(self, mock_get_programs):
Expand Down
22 changes: 18 additions & 4 deletions lms/djangoapps/learner_home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,24 @@ def get_ecommerce_payment_page(user):
@function_trace("get_cert_statuses")
def get_cert_statuses(user, course_enrollments):
"""Get cert status by course for user enrollments"""
return {
enrollment.course_id: cert_info(user, enrollment)
for enrollment in course_enrollments
}

cert_statuses = {}

for enrollment in course_enrollments:
# APER-2171 - trying to get a cert for a deleted course can throw an exception
# Wrap in exception handling to avoid this issue.
try:
certificate_for_course = cert_info(user, enrollment)

if certificate_for_course:
cert_statuses[enrollment.course_id] = certificate_for_course

except Exception as ex: # pylint: disable=broad-except
logger.exception(
f"Error getting certificate status for (user, course) ({user}, {enrollment.course_id}): {ex}"
)

return cert_statuses


@function_trace("get_org_block_and_allow_lists")
Expand Down
2 changes: 1 addition & 1 deletion requirements/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ django-storages<1.9
# The team that owns this package will manually bump this package rather than having it pulled in automatically.
# This is to allow them to better control its deployment and to do it in a process that works better
# for them.
edx-enterprise==3.60.4
edx-enterprise==3.60.5

# oauthlib>3.0.1 causes test failures ( also remove the django-oauth-toolkit constraint when this is fixed )
oauthlib==3.0.1
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ edx-drf-extensions==8.4.0
# edx-when
# edxval
# learner-pathway-progress
edx-enterprise==3.60.4
edx-enterprise==3.60.5
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/base.in
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ edx-drf-extensions==8.4.0
# edx-when
# edxval
# learner-pathway-progress
edx-enterprise==3.60.4
edx-enterprise==3.60.5
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ edx-drf-extensions==8.4.0
# edx-when
# edxval
# learner-pathway-progress
edx-enterprise==3.60.4
edx-enterprise==3.60.5
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/base.txt
Expand Down
8 changes: 8 additions & 0 deletions xmodule/modulestore/xml_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,13 @@ def adapt_references(subtree, destination_course_key, export_fs):
Map every reference in the subtree into destination_course_key and set it back into the xblock fields
"""
subtree.runtime.export_fs = export_fs # ensure everything knows where it's going!
# TODO: Remove logging statements after export issue is resolved (INF-667)
node_id = subtree.scope_ids.usage_id.html_id()
logging.info(f"Exporting {destination_course_key} node {node_id}")
for field_name, field in subtree.fields.items():
logging.info(f"Exporting {destination_course_key} node {node_id} field {field_name}")
if field.is_set_on(subtree):
logging.info(f"Exporting {destination_course_key} node {node_id} field_on {field_name}")
if isinstance(field, Reference):
value = field.read_from(subtree)
if value is not None:
Expand All @@ -375,6 +380,9 @@ def adapt_references(subtree, destination_course_key, export_fs):
key: ele.map_into_course(destination_course_key) for key, ele in field.read_from(subtree).items() # lint-amnesty, pylint: disable=line-too-long
}
)
logging.info(f"Export_successful {destination_course_key} node {node_id} field_on {field_name}")
logging.info(f"Export_successful {destination_course_key} node {node_id} field {field_name}")
logging.info(f"Export_successful {destination_course_key} node {node_id}")


def _export_field_content(xblock_item, item_dir):
Expand Down

0 comments on commit 81fbb85

Please sign in to comment.