diff --git a/core/jobs/playtime_entries.py b/core/jobs/playtime_entries.py index 6e5917ed84..c9f72bc87f 100644 --- a/core/jobs/playtime_entries.py +++ b/core/jobs/playtime_entries.py @@ -132,12 +132,18 @@ def do_run(self): Configuration.REPORTING_NAME_ENVIRONMENT_VARIABLE, "" ) + # format report name for use in csv attachment filename below + subject_prefix = reporting_name if len(reporting_name) > 0: - reporting_name += ": " + subject_prefix += ": " - email_subject = f"{reporting_name}Playtime Summaries {formatted_start_date} - {formatted_until_date}" + email_subject = f"{subject_prefix}Playtime Summaries {formatted_start_date} - {formatted_until_date}" + reporting_name_with_no_spaces = reporting_name.replace(" ", "_") + "-" attachment_extension = "csv" - attachment_name = f"playtime-summary-{formatted_start_date}-{formatted_until_date}.{attachment_extension}" + attachment_name = ( + f"playtime-summary-{reporting_name_with_no_spaces}" + f"{formatted_start_date}-{formatted_until_date}.{attachment_extension}" + ) # Write to a temporary file so we don't overflow the memory with TemporaryFile( diff --git a/tests/core/jobs/test_playtime_entries.py b/tests/core/jobs/test_playtime_entries.py index 438293e44c..b7bd95e8ab 100644 --- a/tests/core/jobs/test_playtime_entries.py +++ b/tests/core/jobs/test_playtime_entries.py @@ -247,7 +247,7 @@ def test_do_run(self, db: DatabaseTransactionFixture): # collection2 library2 playtime(db.session, identifier, collection2, library2, date3m(3), 300) - reporting_name = "test-cm" + reporting_name = "test cm" # Horrible unbracketted syntax for python 3.8 with patch("core.jobs.playtime_entries.csv.writer") as writer, patch( @@ -297,7 +297,7 @@ def test_do_run(self, db: DatabaseTransactionFixture): receivers=["reporting@test.email"], text="", attachments={ - f"playtime-summary-{cutoff}-{until}.csv": "" + f"playtime-summary-{reporting_name.replace(' ', '_')}-{cutoff}-{until}.csv": "" }, # Mock objects do not write data )