Skip to content

Commit

Permalink
chore: fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Jan 16, 2025
1 parent 33f3f97 commit fcf8ee6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def handle(self, *args, **options):
courses = options['course']
should_process_all = options['all']
force = options['force']
self.time_now = datetime.now(tz=timezone.utc)
time_now = datetime.now(tz=timezone.utc)
if not courses and not should_process_all:
raise CommandError('Either --course or --all argument should be provided.')

Expand All @@ -73,4 +73,4 @@ def handle(self, *args, **options):
courses = CourseOverview.get_all_course_keys()
for course in courses:
log.info(f"Start processing upstream->dowstream links in course: {course}")
create_or_update_upstream_links.delay(str(course), force)
create_or_update_upstream_links.delay(str(course), force, created=time_now)
8 changes: 6 additions & 2 deletions openedx/core/djangoapps/content_libraries/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ def duplicate_children(
@shared_task(base=LoggedTask)
@set_code_owner_attribute
def create_or_update_xblock_upstream_link(usage_key):
"""
Create or update upstream link for a single xblock.
"""
ensure_cms("create_or_update_xblock_upstream_link may only be executed in a CMS context")
xblock = modulestore().get_item(UsageKey.from_string(usage_key))
if not xblock.upstream:
Expand All @@ -192,13 +195,14 @@ def create_or_update_xblock_upstream_link(usage_key):

@shared_task(base=LoggedTask)
@set_code_owner_attribute
def create_or_update_upstream_links(course_key_str: str, force: bool = False):
def create_or_update_upstream_links(course_key_str: str, force: bool = False, created: datetime | None = None):
"""
A Celery task to create or update upstream downstream links in database from course xblock content.
"""
ensure_cms("create_or_update_upstream_links may only be executed in a CMS context")

created = datetime.now(timezone.utc)
if not created:
created = datetime.now(timezone.utc)
course_status = get_or_create_course_link_status(course_key_str, created)
if course_status.status in [
CourseLinksStatusChoices.COMPLETED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_call_with_invalid_args(self):
self.call_command('--all', '--course', 'some-course')

@patch(
'openedx.core.djangoapps.content_libraries.management.commands.recreate_upstream_links.create_or_update_upstream_links'
'openedx.core.djangoapps.content_libraries.management.commands.recreate_upstream_links.create_or_update_upstream_links' # pylint: disable=line-too-long
)
def test_call_for_single_course(self, mock_task):
"""
Expand All @@ -55,7 +55,7 @@ def test_call_for_single_course(self, mock_task):
mock_task.delay.assert_called_with('some-course', True)

@patch(
'openedx.core.djangoapps.content_libraries.management.commands.recreate_upstream_links.create_or_update_upstream_links'
'openedx.core.djangoapps.content_libraries.management.commands.recreate_upstream_links.create_or_update_upstream_links' # pylint: disable=line-too-long
)
def test_call_for_multiple_course(self, mock_task):
"""
Expand All @@ -66,7 +66,7 @@ def test_call_for_multiple_course(self, mock_task):
mock_task.delay.assert_any_call('one-more-course', False)

@patch(
'openedx.core.djangoapps.content_libraries.management.commands.recreate_upstream_links.create_or_update_upstream_links'
'openedx.core.djangoapps.content_libraries.management.commands.recreate_upstream_links.create_or_update_upstream_links' # pylint: disable=line-too-long
)
def test_call_for_all_courses(self, mock_task):
"""
Expand Down

0 comments on commit fcf8ee6

Please sign in to comment.