Skip to content

Commit

Permalink
fix: resolve nits and update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
AliAdnanSohail authored and uzairr committed Sep 25, 2023
1 parent f7475f2 commit 9d997d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def write_csv_file_content(self):
"""
Write the csv file content to a file.
"""
# add csv headers
csv_file_content = self.csv_header
program_data = [
(self.program1.uuid, self.test_active_url_slugs[0]),
Expand Down Expand Up @@ -117,6 +116,12 @@ def test_success_flow__through_configuration_model(self, mock_send_email_for_slu
)

assert mock_send_email_for_slug_updates.call_count == 1
self.program1.refresh_from_db()
self.program2.refresh_from_db()
self.program3.refresh_from_db()
assert self.program1.marketing_slug == self.test_active_url_slugs[0]
assert self.program2.marketing_slug == self.test_active_url_slugs[1]
assert self.program3.marketing_slug == self.test_active_url_slugs[2]
expected_msg = f'program_uuid,old_slug,new_slug,error\n{self.program1.uuid},{current_slug_program1},' \
f'{self.test_active_url_slugs[0]},None\n{self.program2.uuid},{current_slug_program2},' \
f'{self.test_active_url_slugs[1]},None\n{self.program3.uuid},{current_slug_program3},' \
Expand Down Expand Up @@ -204,7 +209,7 @@ def test_invalid_program_uuid(self, mock_send_email_for_slug_updates):
call_command(
'update_program_url_slugs', args_from_database=True
)
# Assert that the email is sent and assert the email content

assert mock_send_email_for_slug_updates.call_count == 1
expected_msg = 'program_uuid,old_slug,new_slug,error\ninvalid-program-uuid,None,None,' \
'Skipping uuid invalid-program-uuid because of incorrect slug format\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def _get_report_in_csv_format(self):
report_in_csv_format = "program_uuid,old_slug,new_slug,error\n"

for record in self.slug_update_report:
report_in_csv_format = report_in_csv_format + f"{record['program_uuid']},{record['old_slug']}," \
f"{record['new_slug']},{record['error']}\n"
report_in_csv_format = f"{report_in_csv_format}{record['program_uuid']},{record['old_slug']}," \
f"{record['new_slug']},{record['error']}\n"

return report_in_csv_format

Expand Down Expand Up @@ -131,7 +131,7 @@ def validate_program_fields(self, program_uuid, new_url_slug):

programs_qs = Program.objects.filter(marketing_slug=new_url_slug)
if programs_qs.exists():
self.update_slug_report(program_uuid, error.format(program_uuid, 'program already exists'))
self.update_slug_report(program_uuid, error.format(program_uuid, 'program with same slug already exists'))
return False

return True
3 changes: 2 additions & 1 deletion course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3305,7 +3305,8 @@ def marketing_url(self):
if self.marketing_slug:
if self.marketing_slug.find('/') != -1:
return self.marketing_slug
return urljoin(self.partner.marketing_site_url_root, self.marketing_slug)
path = f'{self.type.slug.lower()}/{self.marketing_slug}'
return urljoin(self.partner.marketing_site_url_root, path)

return None

Expand Down

0 comments on commit 9d997d6

Please sign in to comment.