Add a date format for download names
The new setting gives the strftime format of {pubdate}, {timestamp} and {last_modified}.
The default is Calibre's "%b, %Y".
This commit is contained in:
@@ -174,6 +174,24 @@ def test_download_template_names_the_file(client, story):
|
||||
assert "filename*=UTF-8''Caf%C3%A9%20-%20Ann%20Writer.epub" in download_name(client, sid)
|
||||
|
||||
|
||||
def test_date_format_of_download_names(client, story):
|
||||
sid, _ = story
|
||||
o.store.update_story(sid, metahtml=metahtml(), site_values={"pubdate": "2020-05-06T00:00:00"})
|
||||
client.put("/api/settings", json={"download_template": "{title} {pubdate}"}, headers=H)
|
||||
assert 'filename="Story May, 2020.epub"' in download_name(client, sid)
|
||||
saved = client.put("/api/settings", json={"download_date_format": " %Y-%m-%d "}, headers=H).json
|
||||
assert saved["download_date_format"] == "%Y-%m-%d"
|
||||
assert "filename=Story 2020-05-06.epub" in download_name(client, sid).replace('"', "")
|
||||
response = client.put("/api/settings", json={"download_date_format": 5}, headers=H)
|
||||
assert (response.status_code, response.json) == (400, {"error": "The date format must be text"})
|
||||
response = client.put("/api/settings", json={"download_date_format": "%Y" * 51}, headers=H)
|
||||
assert (response.status_code, response.json) == (400, {"error": "A date format can have 100 characters at most"})
|
||||
# An empty format restores the default.
|
||||
assert client.put("/api/settings", json={"download_date_format": ""}, headers=H).json["download_date_format"] == (
|
||||
"%b, %Y"
|
||||
)
|
||||
|
||||
|
||||
def test_download_template_that_fails_gives_the_title(client, story, caplog):
|
||||
sid, _ = story
|
||||
o.store.update_story(sid, metahtml=metahtml())
|
||||
|
||||
Reference in New Issue
Block a user