diff --git a/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/Makefile b/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/Makefile index 8bda4586..98e589c8 100644 --- a/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/Makefile +++ b/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/Makefile @@ -1,6 +1,6 @@ POETRY ?= $(shell which poetry || echo poetry) -.PHONY: start install +.PHONY: start install test start: install @@ -8,3 +8,6 @@ start: install install: $(POETRY) install + +test: install + $(RUN) pytest diff --git a/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/tests/conftest.py b/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/tests/conftest.py new file mode 100644 index 00000000..807c817c --- /dev/null +++ b/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/tests/conftest.py @@ -0,0 +1,26 @@ +import pytest +from subprocess import Popen, PIPE +from http.client import HTTPConnection +import time + +@pytest.fixture(scope="session") +def process(): + process = Popen( ["make", "start"], stdout=PIPE) + retries = 5 + while retries > 0: + conn = HTTPConnection("localhost:4080") + try: + conn.request("HEAD", "/") + response = conn.getresponse() + if response is not None: + yield process + break + except ConnectionRefusedError: + time.sleep(1) + retries -= 1 + + if not retries: + raise RuntimeError("Failed to start http server") + else: + process.terminate() + process.wait() \ No newline at end of file diff --git a/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/tests/test_e2e.py b/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/tests/test_e2e.py new file mode 100644 index 00000000..b4f025f6 --- /dev/null +++ b/harp/commandline/cookiecutters/project/{{cookiecutter.__dir_name}}/tests/test_e2e.py @@ -0,0 +1,6 @@ +import httpx + +def test_get_dashboard(process): + response = httpx.get('http://localhost:4080/') + assert response.status_code == 200 +