diff --git a/docker/conf/nginx.conf b/docker/conf/nginx.conf --- a/docker/conf/nginx.conf +++ b/docker/conf/nginx.conf @@ -13,13 +13,14 @@ default_type application/octet-stream; sendfile on; keepalive_timeout 65; + client_max_body_size 100M; # Built-in Docker resolver. Needed to allow on-demand resolution of proxy # upstreams. resolver 127.0.0.11 valid=30s; server { - listen 80 default_server; + listen 5080 default_server; # Add a trailing slash to top level requests (e.g. http://localhost:5080/flower) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -80,7 +80,7 @@ volumes: - "./conf/nginx.conf:/etc/nginx/nginx.conf:ro" ports: - - 5080:80 + - 5080:5080 # Scheduler diff --git a/docker/services/swh-deposit/entrypoint.sh b/docker/services/swh-deposit/entrypoint.sh --- a/docker/services/swh-deposit/entrypoint.sh +++ b/docker/services/swh-deposit/entrypoint.sh @@ -9,7 +9,12 @@ setup_pgsql if [ "$1" = 'shell' ] ; then - exec bash -i + shift + if (( $# == 0)); then + exec bash -i + else + "$@" + fi else wait_pgsql diff --git a/docker/tests/test_deposit.py b/docker/tests/test_deposit.py new file mode 100644 --- /dev/null +++ b/docker/tests/test_deposit.py @@ -0,0 +1,121 @@ +import pytest +import subprocess +import testinfra +import json +import time + + +# scope='session' so we use the same container for all the tests; +@pytest.fixture(scope='session') +def host(request): + # start the whole cluster + subprocess.check_output(['docker-compose', 'up', '-d']) + # run a container in which test commands are executed + docker_id = subprocess.check_output( + ['docker-compose', 'run', '-d', + 'swh-deposit', 'shell', 'sleep', '1h']).decode().strip() + host = testinfra.get_host("docker://" + docker_id) + host.check_output( + 'wget https://github.com/SoftwareHeritage/swh-core/archive/master.zip ' + '-O /tmp/archive.zip') + host.check_output( + 'wget https://raw.githubusercontent.com/SoftwareHeritage/swh-deposit/' + 'master/swh/deposit/tests/data/atom/metadata.xml ' + '-O /tmp/metadata.xml') + # return a testinfra connection to the container + yield host + + # at the end of the test suite, destroy the container + subprocess.check_call(['docker', 'rm', '-f', docker_id]) + # and the wole cluster + subprocess.check_call(['docker-compose', 'down']) + + +def test_admin_collection(host): + # 'host' binds to the container + assert host.check_output('swh deposit admin collection list') == 'test' + + +def test_admin_user(host): + assert host.check_output('swh deposit admin user list') == 'test' + + +def test_create_deposit_simple(host): + deposit = host.check_output( + 'swh deposit upload --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 --archive /tmp/archive.zip ' + '--name test_deposit --author somebody') + deposit = json.loads(deposit) + + assert set(deposit.keys()) == {'deposit_id', 'deposit_status', + 'deposit_status_detail', 'deposit_date'} + assert deposit['deposit_status'] == 'deposited' + deposit_id = deposit['deposit_id'] + + for i in range(60): + status = json.loads(host.check_output( + 'swh deposit status --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 --deposit-id %s' % deposit_id)) + if status['deposit_status'] == 'done': + break + time.sleep(1) + else: + assert False, "Deposit loading failed" + + +def test_create_deposit_with_metadata(host): + deposit = host.check_output( + 'swh deposit upload --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 ' + '--archive /tmp/archive.zip ' + '--metadata /tmp/metadata.xml') + deposit = json.loads(deposit) + + assert set(deposit.keys()) == {'deposit_id', 'deposit_status', + 'deposit_status_detail', 'deposit_date'} + assert deposit['deposit_status'] == 'deposited' + deposit_id = deposit['deposit_id'] + + for i in range(60): + status = json.loads(host.check_output( + 'swh deposit status --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 --deposit-id %s' % deposit_id)) + if status['deposit_status'] == 'done': + break + time.sleep(1) + else: + assert False, "Deposit loading failed" + + +def test_create_deposit_multipart(host): + deposit = host.check_output( + 'swh deposit upload --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 ' + '--archive /tmp/archive.zip ' + '--partial') + deposit = json.loads(deposit) + + assert set(deposit.keys()) == {'deposit_id', 'deposit_status', + 'deposit_status_detail', 'deposit_date'} + assert deposit['deposit_status'] == 'partial' + deposit_id = deposit['deposit_id'] + + deposit = host.check_output( + 'swh deposit upload --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 ' + '--metadata /tmp/metadata.xml ' + '--deposit-id %s' + % deposit_id) + deposit = json.loads(deposit) + assert deposit['deposit_status'] == 'deposited' + assert deposit['deposit_id'] == deposit_id + + for i in range(60): + status = json.loads(host.check_output( + 'swh deposit status --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 --deposit-id %s' % deposit_id)) + if status['deposit_status'] == 'done': + break + time.sleep(1) + else: + assert False, "Deposit loading failed; current status is %s" % status