forked from poole/hyde
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtests.py
More file actions
57 lines (47 loc) · 1.48 KB
/
tests.py
File metadata and controls
57 lines (47 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import glob
import unittest
import frontmatter
class TestPosts(unittest.TestCase):
POST_REQUIRED_KEYS = [
"title",
"description",
"image",
"tags"
]
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.POST_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']}")
class TestPodcastPosts(unittest.TestCase):
PODCAST_REQUIRED_KEYS = [
"title",
"date",
"file",
"duration",
"guid",
"spotify_url",
"itunes_url",
"description"
]
def test_podcast_posts(self):
tags = []
for file in glob.glob("_hackerspublics/*.md"):
with open(file) as f:
post = frontmatter.load(f)
for key in self.PODCAST_REQUIRED_KEYS:
if key not in post:
self.fail(
f"La clé `{key}` est absente de `{file}` et est obligatoire"
)