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

fix: allow both active and marketable runs in update_course_ai_translations #4441

Merged
merged 2 commits into from
Sep 12, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
continue-on-error: ${{ matrix.status == 'ignored' }}
- name: Upload coverage
if: matrix.db-version == 'mysql80'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: coverage${{ matrix.pytest-split-group }}
path: .coverage
Expand All @@ -60,7 +60,7 @@ jobs:
PYTHON_VERSION: 3.12
- name: Download all artifacts
# Downloads coverage1, coverage2, etc.
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
- name: Run coverage
run: make ci_coverage
- uses: codecov/codecov-action@v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,43 @@ def test_command_with_marketable_flag(self, mock_get_translations):
[{'code': 'es', 'label': 'Spanish'}]
)

def test_command_with_marketable_and_active_flag(self, mock_get_translations):
"""Test the command with the marketable and active flag filtering both marketable and active course runs."""
mock_get_translations.return_value = {
**self.TRANSLATION_DATA,
'available_translation_languages': [{'code': 'fr', 'label': 'French'}]
}

non_active_non_marketable_course_run = CourseRunFactory(
end=now() - datetime.timedelta(days=10), translation_languages=[])
active_non_marketable_course_run = CourseRunFactory(end=now() + datetime.timedelta(days=10))

verified_and_audit_type = CourseRunType.objects.get(slug='verified-audit')
verified_and_audit_type.is_marketable = True
verified_and_audit_type.save()

marketable_non_active_course_run = CourseRunFactory(
status='published',
slug='test-course-run',
type=verified_and_audit_type,
end=now() - datetime.timedelta(days=10), translation_languages=[]
)
seat = SeatFactory(course_run=marketable_non_active_course_run)
marketable_non_active_course_run.seats.add(seat)

call_command('update_course_ai_translations', partner=self.partner.name, marketable=True, active=True)

marketable_non_active_course_run.refresh_from_db()
self.assertListEqual(
marketable_non_active_course_run.translation_languages,
[{'code': 'fr', 'label': 'French'}]
)
self.assertListEqual(
active_non_marketable_course_run.translation_languages,
[{'code': 'fr', 'label': 'French'}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mock_get_translations returns Spanish, why is this French?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the marketable course was also active somehow. Updated the test by adding end date to past.

)
self.assertListEqual(non_active_non_marketable_course_run.translation_languages, [])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a non-marketable non-active run and assert that the translation_languages are empty?

def test_command_no_partner(self, _):
"""Test the command raises an error if no valid partner is found."""
with self.assertRaises(CommandError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ def handle(self, *args, **options):

course_runs = CourseRun.objects.all()

if options['active']:
if options['active'] and options['marketable']:
course_runs = course_runs.marketable().union(course_runs.active())
elif options['active']:
course_runs = course_runs.active()

if options['marketable']:
elif options['marketable']:
course_runs = course_runs.marketable()

for course_run in course_runs:
Expand Down
Loading