Skip to content

Commit

Permalink
fix: To website automation test on windows (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsuits authored Feb 19, 2021
1 parent 14686a8 commit 8e3ecbf
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions tests/trestle/docs-serve/website_automation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,30 @@
"""website automation tests."""

import http.client
import multiprocessing
import subprocess
import time

from click.testing import CliRunner

from mkdocs import __main__ as cli


def _webserver():
CliRunner().invoke(cli.cli, ['serve'], catch_exceptions=False)
def _ensure_not_running() -> None:
"""Ensure test website not running."""
response = None
try:
connection = http.client.HTTPConnection('localhost', 8000, timeout=60)
connection.request('GET', '/')
response = connection.getresponse()
except Exception:
pass
if response is not None:
raise Exception('mkdocs server running')


def test_website_automation(tmpdir):
def test_website_automation(tmpdir) -> None:
"""Test website boot and usability."""
p = multiprocessing.Process(target=_webserver)
p.start()
_ensure_not_running()
try:
# launch webserver
p = subprocess.Popen(['mkdocs', 'serve'])
# try connect to and fetch data from webserver
retrys_max = 90
retrys = 0
while retrys < retrys_max:
Expand All @@ -45,12 +52,16 @@ def test_website_automation(tmpdir):
if retrys >= retrys_max:
raise e
time.sleep(1)
# assure expected response
if response.status != 200:
raise Exception(f'status: {response.status}')
if response.reason != 'OK':
raise Exception(f'reason: {response.reason}')
body = response.read().decode('utf-8')
if '<meta name="description" content="Documentation for compliance-trestle package.">' not in body:
raise Exception(f'body: {body}')
# stop webserver
finally:
p.terminate()
p.wait()
_ensure_not_running()

0 comments on commit 8e3ecbf

Please sign in to comment.