Skip to content

Instantly share code, notes, and snippets.

@AntoineAugusti
Last active April 17, 2020 07:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AntoineAugusti/809d6ea91051430fd263dd5b682a738d to your computer and use it in GitHub Desktop.
Save AntoineAugusti/809d6ea91051430fd263dd5b682a738d to your computer and use it in GitHub Desktop.
version: 2
jobs:
build:
docker:
- image: circleci/python:3.6
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "requirements.txt" }}
- run:
name: Install dependencies
command: |
python -m venv venv
. venv/bin/activate
pip install -r requirements.txt
- save_cache:
paths:
- ./venv
key: v1-dependencies-{{ checksum "requirements.txt" }}
- run:
name: Tests
command: |
. venv/bin/activate
nosetests .
nose==1.3.7
python-frontmatter==0.4.5
PyYAML==5.1.2
import glob
import frontmatter
class TestPosts(unittest.TestCase):
REQUIRED_KEYS = [
"author",
"description",
"image",
"layout",
"title",
"twitter",
"tags",
]
ALLOWED_TAGS = {
"accompagnement",
"algorithme",
"collectif",
"datascience",
"design",
"développement",
}
def test_posts(self):
tags = []
for file in glob.glob("_posts/*.md"):
# Skip drafts
if file.startswith("_posts/_"):
continue
with open(file) as f:
post = frontmatter.load(f)
for key in self.REQUIRED_KEYS:
if key not in post:
self.fail(
f"La clé `{key}` est absente de `{file}` et est obligatoire"
)
image = post["image"]
if not (image.startswith("/img/") or image.startswith("http")):
self.fail(f"L'image de `{file}` semble invalide : {post['image']}")
self.assertEquals(post["layout"], "post")
twitter = post["twitter"]
if twitter is not None and (
twitter.startswith("https://") or twitter.startswith("@")
):
self.fail(
f"Le Twitter `{file}` semble invalide, il faut indiquer uniquement le nom d'utilisateur : {post['twitter']}"
)
for tag in post["tags"]:
self.assertIn(
tag, self.ALLOWED_TAGS, f"Le fichier `{file}` a un tag invalide."
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment