Skip to content
Snippets Groups Projects
Commit cf694828 authored by James Vasile's avatar James Vasile
Browse files

Add some test support and a test for issue 6

parent 92e8a3c5
No related branches found
No related tags found
No related merge requests found
pytest
psutil
bs4
PORT = 8000
from bs4 import BeautifulSoup as Soup
import subprocess
import pytest
import psutil
import requests
site_rebuilt = False
@pytest.fixture
def rebuild_site():
"""We only want to rebuid the site once and only if bin/serve isn't already
automaritcally rebuilding it."""
# Use a global to keep state between runs because I couldn't figure out how
# to decorate a closure as a pytest.fixture.
global site_rebuilt
if not site_rebuilt:
# Check if automatic rebuilder already running
for pid in psutil.pids():
p = psutil.Process(pid)
if p.name() == "pelican" and p.cmdline()[-1] == "PELICAN_BINSERVE=true":
site_rebuilt = True
return True
# Do the rebuild by running our build script
out = subprocess.check_output("build").decode("utf-8")
print(out)
site_rebuilt = True
return site_rebuilt
def fetch(url, just_contents=True):
res = requests.get(f'http://localhost:{PORT}/{url}')
if just_contents:
return res.content.decode('utf-8')
return res
def test_recent_post_sidebar_link(rebuild_site):
# test index page
soup = Soup(fetch(''), 'html.parser')
for rec in [l for l in soup.find(id="recent-posts").find_all('a')]:
print(rec['href'])
assert(rec['href'].startswith('/'))
# test article page
soup = Soup(fetch('2019/10/commoditization'), 'html.parser')
for rec in [l for l in soup.find(id="recent-posts").find_all('a')]:
assert(rec['href'].startswith('/'))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment