#!/usr/bin/env python3 import logging import sys import uuid from typing import Dict, List, Optional import requests BASE_URL = "http://localhost:8888" POSTS_URL = f"{BASE_URL}/posts" DELETE_UUID = "00000000-0000-dddd-0000-000000000000" POST_UUID = "6d011855-6b0d-4202-a243-4d9db9807f14" BAD_UUID = "00000000-0000-1111-0000-000000000000" INVALID_UUID = "0" JSON_ACCEPT_HEADER = {"Accept": "application/json"} log = logging.getLogger(__name__) log.setLevel(logging.INFO) def test_redirect(): url = f"{BASE_URL}/asdf" r = requests.get(url, allow_redirects=False) assert r.status_code == 307 assert r.headers["Location"] == "/" def test_html_get_post(): url = f"{POSTS_URL}/{POST_UUID}" r = requests.get(url) assert r.status_code == 200 text = r.text assert "A Solid Breakdown of the Linux Font Rendering Stack" in text assert "hinting and anti-aliasing" in text assert "Debugging CGI / CGit" not in text def test_html_get_base_url(): url = BASE_URL r = requests.get(url) assert r.status_code == 200 text = r.text assert "A Solid Breakdown of the Linux Font Rendering Stack" in text assert "hinting and anti-aliasing" in text assert "Debugging CGI / CGit" in text def test_html_get_posts(): url = POSTS_URL r = requests.get(url) assert r.status_code == 200 text = r.text assert "A Solid Breakdown of the Linux Font Rendering Stack" in text assert "hinting and anti-aliasing" in text assert "Debugging CGI / CGit" in text def test_html_get_post_not_found(): url = f"{POSTS_URL}/{BAD_UUID}" r = requests.get(url) assert r.status_code == 404 text = r.text assert "Resource not found" in text url = f"{POSTS_URL}/{INVALID_UUID}" r = requests.get(url) assert r.status_code == 404 text = r.text assert "Resource not found" in text def main(): winner = True for func in dir(sys.modules[__name__]): if func.startswith("test_"): try: globals()[func]() except Exception as e: winner = False log.exception(f"🚫 {func} failed {e} 🚫") print(f"🚫 {func} failed {e} 🚫") if winner: log.info("🏆 You're winner !") print("🏆 You're winner !") if __name__ == "__main__": main()