microblog.pub/tests/integration_test.py

32 lines
778 B
Python
Raw Permalink Normal View History

import os
import pytest
2018-05-20 20:34:56 +00:00
import requests
from html2text import html2text
@pytest.fixture
def config():
"""Return the current config as a dict."""
import yaml
2018-06-17 17:21:59 +00:00
with open(
os.path.join(os.path.dirname(__file__), "..", "config/me.yml"), "rb"
) as f:
yield yaml.load(f)
def resp2plaintext(resp):
"""Convert the body of a requests reponse to plain text in order to make basic assertions."""
return html2text(resp.text)
2018-05-20 20:34:56 +00:00
def test_ping_homepage(config):
2018-05-20 20:34:56 +00:00
"""Ensure the homepage is accessible."""
2018-06-17 17:21:59 +00:00
resp = requests.get("http://localhost:5005")
2018-05-20 20:34:56 +00:00
resp.raise_for_status()
2018-05-20 20:55:52 +00:00
assert resp.status_code == 200
body = resp2plaintext(resp)
2018-06-17 17:21:59 +00:00
assert config["name"] in body
assert f"@{config['username']}@{config['domain']}" in body