diff --git a/.travis.yml b/.travis.yml index 3ebc4a14..b91d8b93 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,10 @@ -language: generic - +language: python +python: + - 3.6 sudo: required services: - docker - +install: + - pip install pytest docker script: - make build-test-all diff --git a/Makefile b/Makefile index 677dcb9b..8fea83e7 100644 --- a/Makefile +++ b/Makefile @@ -54,15 +54,8 @@ dev/%: PORT?=8888 dev/%: ## run a foreground container for a stack docker run -it --rm -p $(PORT):8888 $(DARGS) $(OWNER)/$(notdir $@) $(ARGS) +test/%: + @TEST_IMAGE="$(OWNER)/$(notdir $@)" pytest test - -test/%: ## run a stack container, check for jupyter server liveliness - @-docker rm -f iut - @docker run -d --name iut $(OWNER)/$(notdir $@) - @for i in $$(seq 0 9); do \ - sleep $$i; \ - docker exec iut bash -c 'wget http://localhost:8888 -O- | grep -i jupyter'; \ - if [[ $$? == 0 ]]; then exit 0; fi; \ - done ; exit 1 - -test-all: $(ALL_IMAGES:%=test/%) ## test all stacks \ No newline at end of file +test/base-notebook: ## test supported options in the base notebook + @TEST_IMAGE="$(OWNER)/$(notdir $@)" pytest test base-notebook/test \ No newline at end of file diff --git a/test/test_notebook.py b/test/test_notebook.py new file mode 100644 index 00000000..ed3c0ebb --- /dev/null +++ b/test/test_notebook.py @@ -0,0 +1,52 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. +import os +import time + +import docker +import pytest +import requests + + +@pytest.fixture(scope='session') +def docker_client(): + """Docker client to use""" + return docker.from_env() + + +@pytest.fixture(scope='session') +def image_name(): + """Image name to test""" + return os.getenv('TEST_IMAGE', 'jupyter/base-notebook') + + +@pytest.fixture(scope='function') +def nb_container(docker_client, image_name): + """Notebook container to test""" + container = docker_client.containers.run( + image_name, + detach=True, + auto_remove=True, + ports={ + '8888/tcp': 8888 + } + ) + yield container + container.kill() + + +def test_server_liveliness(nb_container): + """Notebook server should eventually respond with HTTP 200 OK.""" + for i in range(10): + try: + resp = requests.get('http://localhost:8888') + except requests.exceptions.ConnectionError: + # Wait a bit and try again. Just because the docker container + # is running doesn't mean the notebook server is ready to accept + # connections inside it. + time.sleep(i) + else: + assert resp.status_code == 200 + break + else: + assert False, 'could not connect to server'