Skip to content

Commit

Permalink
Fix new_article.py script to handle file name containing an upper-c…
Browse files Browse the repository at this point in the history
…ase letter (#59)

* Add a regression test

* Fix lastly introduced regression test expected date formatting

* Fix script
  • Loading branch information
ctmbl authored May 5, 2024
1 parent 5b2c6e3 commit c4ba0ca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scripts/new_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def main(files_paths):
file_name = basename[:-3] # get rid of the `.md`

## Add URL info:
data["url"] = f"https://iscsc.fr/posts/{file_name}"
data["url"] = f"https://iscsc.fr/posts/{file_name.lower()}" # filename generated by HUGO will be lowercase
# so must be the URL

## Finally send Data
req = requests.post("http://iscsc.fr:8001/new-blog", json=data)
Expand Down
20 changes: 20 additions & 0 deletions scripts/test_new_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ def test_new_article_file(mock_requests_post):
}
)


def test_new_article_file_upper_case(mock_requests_post):
# Add an article with an Upper case --> URL should be lower case
new_article.main(["test_resources/Article-2.md"])

mock_requests_post.assert_called_once_with(
'http://iscsc.fr:8001/new-blog',
json={
'title': 'article title',
'summary': 'article name contains an upper case letter',
'date': '2024-05-05 12:00:00+02:00',
'lastUpdate': '2024-05-05 12:00:00+02:00',
'tags': "['some', 'tags']",
'author': 'ctmbl',
'draft': False,
'url': 'https://iscsc.fr/posts/article-2'
}
)


def test_new_leaf_bundle_article(mock_requests_post):
new_article.main(["test_resources/leaf_bundle/index.md"])

Expand Down
9 changes: 9 additions & 0 deletions scripts/test_resources/Article-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: "article title"
summary: "article name contains an upper case letter"
date: 2024-05-05T12:00:00+02:00
lastUpdate: 2024-05-05T12:00:00+02:00
tags: ["some","tags"]
author: ctmbl
draft: false
---

0 comments on commit c4ba0ca

Please sign in to comment.