-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_gallery.py
More file actions
38 lines (27 loc) · 943 Bytes
/
test_gallery.py
File metadata and controls
38 lines (27 loc) · 943 Bytes
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
#!/usr/bin/python
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
import os
import pytest
import requests
import yaml
here = os.path.abspath(os.path.dirname(__file__))
root = os.path.dirname(here)
def test_memes():
memes_file = os.path.join(root, "_data", "gallery.yml")
assert os.path.exists(memes_file)
with open(memes_file, "r") as stream:
memes = load(stream, Loader=Loader)
for meme in memes:
# 1. Check for required fields
for required in ["image", "url", "alt"]:
assert required in meme
assert meme[required]
# Ensure image path exists
image_path = os.path.join(root, "assets", "gallery", meme["image"])
assert os.path.exists(image_path)
# Assert url exists
assert requests.get(meme["url"]).status_code in [200, 301, 302]