From 7eb409a3d3724f9c7336eb20d7c9216f6278dfa5 Mon Sep 17 00:00:00 2001 From: Jan Range Date: Thu, 28 Dec 2023 21:53:36 +0100 Subject: [PATCH 1/9] ignore test and macOS artifacts --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 5610c23..6a67685 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ +# Local testing dv artifacts +dv +solr + +# Apple artifacts +.DS_Store + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] From 8c3da4c5aa50582f1ea11cfd7636c53e7825503e Mon Sep 17 00:00:00 2001 From: Jan Range Date: Thu, 28 Dec 2023 21:54:53 +0100 Subject: [PATCH 2/9] add local testing and instructions - Spins up a Dataverse installation similar to the test action - Allows to specify the version of Python to test against --- README.md | 14 ++++ docker-compose-test.yml | 157 ++++++++++++++++++++++++++++++++++++++++ local-test.env | 9 +++ run-tests.sh | 66 +++++++++++++++++ 4 files changed, 246 insertions(+) create mode 100644 docker-compose-test.yml create mode 100644 local-test.env create mode 100644 run-tests.sh diff --git a/README.md b/README.md index fe8fbb0..0ed53cc 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,20 @@ It helps to access the Dataverse [API's](http://guides.dataverse.org/en/latest/a **Find out more: [Read the Docs](https://pydataverse.readthedocs.io/en/latest/)** +## Running the tests + +To run pyDataverse's tests locally, you need to install docker and docker-compose. This will spin up a local Dataverse instance and run the tests against it. You can run the tests with: + +```bash +sh run_tests.sh +``` + +By default local tests are using the python `3.11` slim image. However, you can change the python version by providing a valid version via the `-p` keyword argument. For example, to run the tests with python `3.9`: + +```bash +sh run_tests.sh -p 3.9 +``` + ## Chat with us! If you are interested in the development of pyDataverse, we invite you to join us for a chat on our [Zulip Channel](https://dataverse.zulipchat.com/#narrow/stream/377090-python). This is the perfect place to discuss and exchange ideas about the development of pyDataverse. Whether you need help or have ideas to share, feel free to join us! diff --git a/docker-compose-test.yml b/docker-compose-test.yml new file mode 100644 index 0000000..e9cdf77 --- /dev/null +++ b/docker-compose-test.yml @@ -0,0 +1,157 @@ +version: '2.4' +name: pydataverse +services: + unit-tests: + container_name: unit-tests + image: python:${PYTHON_VERSION}-slim + environment: + BASE_URL: http://dataverse:8080 + DV_VERSION: 6.1 + networks: + - dataverse + volumes: + - ${PWD}:/pydataverse + - ./dv:/dv + command: + - sh + - -c + - | + export $(grep "API_TOKEN" "dv/bootstrap.exposed.env") + export API_TOKEN_SUPERUSER=$$API_TOKEN + cd /pydataverse + python3 -m pip install --upgrade pip + python3 -m pip install -r ./requirements/tests.txt + python3 -m pip install -e . + python3 -m pytest + depends_on: + bootstrap: + condition: service_completed_successfully + + dataverse: + container_name: 'dataverse' + hostname: dataverse + image: ${DATAVERSE_IMAGE} + restart: on-failure + user: payara + environment: + - DATAVERSE_DB_HOST=postgres + - DATAVERSE_DB_USER=${DATAVERSE_DB_USER} + - DATAVERSE_DB_PASSWORD=${DATAVERSE_DB_PASSWORD} + ports: + - '8080:8080' + networks: + - dataverse + depends_on: + postgres: + condition: service_started + solr: + condition: service_started + dv_initializer: + condition: service_completed_successfully + volumes: + - ${PWD}/dv/data:/dv + - ${PWD}:/secrets + tmpfs: + - /dumps:mode=770,size=2052M,uid=1000,gid=1000 + - /tmp:mode=770,size=2052M,uid=1000,gid=1000 + mem_limit: 2147483648 # 2 GiB + mem_reservation: 1024m + privileged: false + healthcheck: + test: curl --fail http://dataverse:8080/api/info/version || exit 1 + interval: 10s + retries: 20 + start_period: 20s + timeout: 240s + + dv_initializer: + container_name: 'dv_initializer' + image: ${CONFIGBAKER_IMAGE} + restart: 'no' + command: + - sh + - -c + - 'fix-fs-perms.sh dv' + volumes: + - ${PWD}/dv/data:/dv + + postgres: + container_name: 'postgres' + hostname: postgres + image: postgres:${POSTGRES_VERSION} + restart: on-failure + environment: + - POSTGRES_USER=${DATAVERSE_DB_USER} + - POSTGRES_PASSWORD=${DATAVERSE_DB_PASSWORD} + ports: + - '5432:5432' + networks: + - dataverse + + solr_initializer: + container_name: 'solr_initializer' + image: ${CONFIGBAKER_IMAGE} + restart: 'no' + command: + - sh + - -c + - 'fix-fs-perms.sh solr && cp -a /template/* /solr-template' + volumes: + - ${PWD}/solr/data:/var/solr + - ${PWD}/solr/conf:/solr-template + + solr: + container_name: 'solr' + hostname: 'solr' + image: solr:${SOLR_VERSION} + depends_on: + solr_initializer: + condition: service_completed_successfully + restart: on-failure + ports: + - '8983:8983' + networks: + - dataverse + command: + - 'solr-precreate' + - 'collection1' + - '/template' + volumes: + - ${PWD}/solr/data:/var/solr + - ${PWD}/solr/conf:/template + + smtp: + container_name: 'smtp' + hostname: 'smtp' + image: maildev/maildev:2.0.5 + restart: on-failure + expose: + - '25' # smtp server + environment: + - MAILDEV_SMTP_PORT=25 + - MAILDEV_MAIL_DIRECTORY=/mail + networks: + - dataverse + tmpfs: + - /mail:mode=770,size=128M,uid=1000,gid=1000 + + bootstrap: + container_name: 'bootstrap' + hostname: 'bootstrap' + image: ${CONFIGBAKER_IMAGE} + restart: 'no' + networks: + - dataverse + volumes: + - ./dv/bootstrap.exposed.env:/.env + command: + - sh + - -c + - 'bootstrap.sh -e /.env dev' + depends_on: + dataverse: + condition: service_healthy + +networks: + dataverse: + driver: bridge diff --git a/local-test.env b/local-test.env new file mode 100644 index 0000000..7400574 --- /dev/null +++ b/local-test.env @@ -0,0 +1,9 @@ +# Dataverse +DATAVERSE_IMAGE=docker.io/gdcc/dataverse:unstable +DATAVERSE_DB_USER=dataverse +DATAVERSE_DB_PASSWORD=secret +CONFIGBAKER_IMAGE=docker.io/gdcc/configbaker:unstable + +# Services +POSTGRES_VERSION=15 +SOLR_VERSION=9.3.0 \ No newline at end of file diff --git a/run-tests.sh b/run-tests.sh new file mode 100644 index 0000000..57697f7 --- /dev/null +++ b/run-tests.sh @@ -0,0 +1,66 @@ +#!bin/bash + +# Parse arguments +usage() { + echo "Usage: $0 [-p Python version (e.g. 3.10, 3.11, ...)]" 1>&2 + exit 1 +} + +while getopts ":p:d:" o; do + case "${o}" in + p) + p=${OPTARG} + ;; + *) ;; + esac +done +shift $((OPTIND - 1)) + +# Fall back to Python 3.11 if no Python version is specified +if [ -z "${p}" ]; then + printf "\nāš ļø No Python version specified falling back to '3.11'\n" + p=3.11 +fi + +# Validate Python version +if [[ ! "${p}" =~ ^3\.[0-9]+$ ]]; then + echo "\nāŒ Invalid Python version. Please specify a valid Python version (e.g. 3.10, 3.11, ...)\n" + exit 1 +fi + +# Check if Docker is installed +if ! command -v docker &>/dev/null; then + echo "āœ‹ Docker is not installed. Please install Docker before running this script." + exit 1 +fi + +# Prepare the environment for the test +mkdir dv >>/dev/null 2>&1 +touch dv/bootstrap.exposed.env >>/dev/null 2>&1 + +# Add python version to the environment +export PYTHON_VERSION=${p} + +printf "\nšŸš€ Preparing containers\n" +printf " Using PYTHON_VERSION=${p}\n\n" + +# Run all containers +docker compose -f ./docker-compose-test.yml \ + --env-file local-test.env \ + up -d + +printf "\nšŸ”Ž Running pyDataverse tests\n" +printf " Logs will be printed once finished...\n\n" + +# Check if "unit-test" container has finished +while [ -n "$(docker ps -f "name=unit-tests" -f "status=running" -q)" ]; do + printf " Waiting for unit-tests container to finish...\n" + sleep 5 +done + +# Print logs of "unit-tests" container +docker logs unit-tests + +# Stop all containers +docker compose -f ./docker-compose-test.yml --env-file local-test.env down +printf "\nāœ… Done\n\n" From f118438e758b62867ee29f6bbeb2503dbee0a7c0 Mon Sep 17 00:00:00 2001 From: Jan Range Date: Thu, 28 Dec 2023 22:28:47 +0100 Subject: [PATCH 3/9] write test results to file --- docker-compose-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose-test.yml b/docker-compose-test.yml index e9cdf77..d0756cb 100644 --- a/docker-compose-test.yml +++ b/docker-compose-test.yml @@ -22,7 +22,7 @@ services: python3 -m pip install --upgrade pip python3 -m pip install -r ./requirements/tests.txt python3 -m pip install -e . - python3 -m pytest + python3 -m pytest > /dv/unit-tests.log depends_on: bootstrap: condition: service_completed_successfully From 428a1c7f3e67dd5b190f3077d8f50945a822c7a2 Mon Sep 17 00:00:00 2001 From: Jan Range Date: Thu, 28 Dec 2023 22:29:08 +0100 Subject: [PATCH 4/9] pretty printing and logging --- run-tests.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 57697f7..8ea6c23 100644 --- a/run-tests.sh +++ b/run-tests.sh @@ -58,9 +58,20 @@ while [ -n "$(docker ps -f "name=unit-tests" -f "status=running" -q)" ]; do sleep 5 done -# Print logs of "unit-tests" container -docker logs unit-tests +# Check if "unit-test" container has failed +if [ "$(docker inspect -f '{{.State.ExitCode}}' unit-tests)" -ne 0 ]; then + printf "\nāŒ Unit tests failed. Printing logs...\n" + docker logs unit-tests + printf "\n Stopping containers\n" + docker compose -f ./docker-compose-test.yml --env-file local-test.env down + exit 1 +fi + +# Print test results +printf "\n" +cat dv/unit-tests.log +printf "\n\nāœ… Unit tests passed\n\n" # Stop all containers docker compose -f ./docker-compose-test.yml --env-file local-test.env down -printf "\nāœ… Done\n\n" +printf "\nšŸŽ‰ Done\n\n" From 478f5dedb6c3fb766fc606fa72cd4b29b139a65a Mon Sep 17 00:00:00 2001 From: Jan Range Date: Fri, 12 Apr 2024 00:06:20 +0200 Subject: [PATCH 5/9] move to separate directory --- docker-compose-test.yml | 157 ---------------------------------------- 1 file changed, 157 deletions(-) delete mode 100644 docker-compose-test.yml diff --git a/docker-compose-test.yml b/docker-compose-test.yml deleted file mode 100644 index d0756cb..0000000 --- a/docker-compose-test.yml +++ /dev/null @@ -1,157 +0,0 @@ -version: '2.4' -name: pydataverse -services: - unit-tests: - container_name: unit-tests - image: python:${PYTHON_VERSION}-slim - environment: - BASE_URL: http://dataverse:8080 - DV_VERSION: 6.1 - networks: - - dataverse - volumes: - - ${PWD}:/pydataverse - - ./dv:/dv - command: - - sh - - -c - - | - export $(grep "API_TOKEN" "dv/bootstrap.exposed.env") - export API_TOKEN_SUPERUSER=$$API_TOKEN - cd /pydataverse - python3 -m pip install --upgrade pip - python3 -m pip install -r ./requirements/tests.txt - python3 -m pip install -e . - python3 -m pytest > /dv/unit-tests.log - depends_on: - bootstrap: - condition: service_completed_successfully - - dataverse: - container_name: 'dataverse' - hostname: dataverse - image: ${DATAVERSE_IMAGE} - restart: on-failure - user: payara - environment: - - DATAVERSE_DB_HOST=postgres - - DATAVERSE_DB_USER=${DATAVERSE_DB_USER} - - DATAVERSE_DB_PASSWORD=${DATAVERSE_DB_PASSWORD} - ports: - - '8080:8080' - networks: - - dataverse - depends_on: - postgres: - condition: service_started - solr: - condition: service_started - dv_initializer: - condition: service_completed_successfully - volumes: - - ${PWD}/dv/data:/dv - - ${PWD}:/secrets - tmpfs: - - /dumps:mode=770,size=2052M,uid=1000,gid=1000 - - /tmp:mode=770,size=2052M,uid=1000,gid=1000 - mem_limit: 2147483648 # 2 GiB - mem_reservation: 1024m - privileged: false - healthcheck: - test: curl --fail http://dataverse:8080/api/info/version || exit 1 - interval: 10s - retries: 20 - start_period: 20s - timeout: 240s - - dv_initializer: - container_name: 'dv_initializer' - image: ${CONFIGBAKER_IMAGE} - restart: 'no' - command: - - sh - - -c - - 'fix-fs-perms.sh dv' - volumes: - - ${PWD}/dv/data:/dv - - postgres: - container_name: 'postgres' - hostname: postgres - image: postgres:${POSTGRES_VERSION} - restart: on-failure - environment: - - POSTGRES_USER=${DATAVERSE_DB_USER} - - POSTGRES_PASSWORD=${DATAVERSE_DB_PASSWORD} - ports: - - '5432:5432' - networks: - - dataverse - - solr_initializer: - container_name: 'solr_initializer' - image: ${CONFIGBAKER_IMAGE} - restart: 'no' - command: - - sh - - -c - - 'fix-fs-perms.sh solr && cp -a /template/* /solr-template' - volumes: - - ${PWD}/solr/data:/var/solr - - ${PWD}/solr/conf:/solr-template - - solr: - container_name: 'solr' - hostname: 'solr' - image: solr:${SOLR_VERSION} - depends_on: - solr_initializer: - condition: service_completed_successfully - restart: on-failure - ports: - - '8983:8983' - networks: - - dataverse - command: - - 'solr-precreate' - - 'collection1' - - '/template' - volumes: - - ${PWD}/solr/data:/var/solr - - ${PWD}/solr/conf:/template - - smtp: - container_name: 'smtp' - hostname: 'smtp' - image: maildev/maildev:2.0.5 - restart: on-failure - expose: - - '25' # smtp server - environment: - - MAILDEV_SMTP_PORT=25 - - MAILDEV_MAIL_DIRECTORY=/mail - networks: - - dataverse - tmpfs: - - /mail:mode=770,size=128M,uid=1000,gid=1000 - - bootstrap: - container_name: 'bootstrap' - hostname: 'bootstrap' - image: ${CONFIGBAKER_IMAGE} - restart: 'no' - networks: - - dataverse - volumes: - - ./dv/bootstrap.exposed.env:/.env - command: - - sh - - -c - - 'bootstrap.sh -e /.env dev' - depends_on: - dataverse: - condition: service_healthy - -networks: - dataverse: - driver: bridge From 7c026613210b995697f7a014fb5f731c567ad24c Mon Sep 17 00:00:00 2001 From: Jan Range Date: Fri, 12 Apr 2024 00:06:34 +0200 Subject: [PATCH 6/9] split flavors for individual use cases --- docker/docker-compose-base.yml | 137 +++++++++++++++++++++++++++++ docker/docker-compose-test-all.yml | 31 +++++++ 2 files changed, 168 insertions(+) create mode 100644 docker/docker-compose-base.yml create mode 100644 docker/docker-compose-test-all.yml diff --git a/docker/docker-compose-base.yml b/docker/docker-compose-base.yml new file mode 100644 index 0000000..196a1a3 --- /dev/null +++ b/docker/docker-compose-base.yml @@ -0,0 +1,137 @@ +version: "2.4" +name: pydataverse +services: + dataverse: + container_name: "dataverse" + hostname: dataverse + image: ${DATAVERSE_IMAGE} + restart: on-failure + user: payara + environment: + - DATAVERSE_DB_HOST=postgres + - DATAVERSE_DB_USER=${DATAVERSE_DB_USER} + - DATAVERSE_DB_PASSWORD=${DATAVERSE_DB_PASSWORD} + - JVM_ARGS=-Ddataverse.pid.providers=fake + -Ddataverse.pid.default-provider=fake + -Ddataverse.pid.fake.type=FAKE + -Ddataverse.pid.fake.label=FakeDOIProvider + -Ddataverse.pid.fake.authority=10.5072 + -Ddataverse.pid.fake.shoulder=FK2/ + ports: + - "8080:8080" + networks: + - dataverse + depends_on: + postgres: + condition: service_started + solr: + condition: service_started + dv_initializer: + condition: service_completed_successfully + volumes: + - ${PWD}/dv/data:/dv + - ${PWD}:/secrets + tmpfs: + - /dumps:mode=770,size=2052M,uid=1000,gid=1000 + - /tmp:mode=770,size=2052M,uid=1000,gid=1000 + mem_limit: 2147483648 # 2 GiB + mem_reservation: 1024m + privileged: false + healthcheck: + test: curl --fail http://dataverse:8080/api/info/version || exit 1 + interval: 10s + retries: 20 + start_period: 20s + timeout: 240s + + dv_initializer: + container_name: "dv_initializer" + image: ${CONFIGBAKER_IMAGE} + restart: "no" + command: + - sh + - -c + - "fix-fs-perms.sh dv" + volumes: + - ${PWD}/dv/data:/dv + + postgres: + container_name: "postgres" + hostname: postgres + image: postgres:${POSTGRES_VERSION} + restart: on-failure + environment: + - POSTGRES_USER=${DATAVERSE_DB_USER} + - POSTGRES_PASSWORD=${DATAVERSE_DB_PASSWORD} + ports: + - "5432:5432" + networks: + - dataverse + + solr_initializer: + container_name: "solr_initializer" + image: ${CONFIGBAKER_IMAGE} + restart: "no" + command: + - sh + - -c + - "fix-fs-perms.sh solr && cp -a /template/* /solr-template" + volumes: + - ${PWD}/solr/data:/var/solr + - ${PWD}/solr/conf:/solr-template + + solr: + container_name: "solr" + hostname: "solr" + image: solr:${SOLR_VERSION} + depends_on: + solr_initializer: + condition: service_completed_successfully + restart: on-failure + ports: + - "8983:8983" + networks: + - dataverse + command: + - "solr-precreate" + - "collection1" + - "/template" + volumes: + - ${PWD}/solr/data:/var/solr + - ${PWD}/solr/conf:/template + + smtp: + container_name: "smtp" + hostname: "smtp" + image: maildev/maildev:2.0.5 + restart: on-failure + expose: + - "25" # smtp server + environment: + - MAILDEV_SMTP_PORT=25 + - MAILDEV_MAIL_DIRECTORY=/mail + networks: + - dataverse + tmpfs: + - /mail:mode=770,size=128M,uid=1000,gid=1000 + + bootstrap: + container_name: "bootstrap" + hostname: "bootstrap" + image: ${CONFIGBAKER_IMAGE} + restart: "no" + networks: + - dataverse + volumes: + - ${PWD}/dv/bootstrap.exposed.env:/.env + command: + - sh + - -c + - "bootstrap.sh -e /.env dev" + depends_on: + dataverse: + condition: service_healthy + +networks: + dataverse: + driver: bridge diff --git a/docker/docker-compose-test-all.yml b/docker/docker-compose-test-all.yml new file mode 100644 index 0000000..22274a2 --- /dev/null +++ b/docker/docker-compose-test-all.yml @@ -0,0 +1,31 @@ +version: "2.4" +services: + unit-tests: + container_name: unit-tests + image: python:${PYTHON_VERSION}-slim + environment: + BASE_URL: http://dataverse:8080 + DV_VERSION: 6.2 + networks: + - dataverse + volumes: + - ${PWD}:/pydataverse + - ../dv:/dv + command: + - sh + - -c + - | + # Fetch the API Token from the local file + export $(grep "API_TOKEN" "dv/bootstrap.exposed.env") + export API_TOKEN_SUPERUSER=$$API_TOKEN + cd /pydataverse + + # Run the unit tests + python3 -m pip install --upgrade pip + python3 -m pip install pytest pytest-cov + python3 -m pip install -e . + python3 -m pytest > /dv/unit-tests.log + + depends_on: + bootstrap: + condition: service_completed_successfully From 3b8be90563960dcaa771c372dd7c017f17815e51 Mon Sep 17 00:00:00 2001 From: Jan Range Date: Fri, 12 Apr 2024 00:06:46 +0200 Subject: [PATCH 7/9] adapt to multiple compose files --- run-tests.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/run-tests.sh b/run-tests.sh index 8ea6c23..8c28614 100644 --- a/run-tests.sh +++ b/run-tests.sh @@ -45,7 +45,9 @@ printf "\nšŸš€ Preparing containers\n" printf " Using PYTHON_VERSION=${p}\n\n" # Run all containers -docker compose -f ./docker-compose-test.yml \ +docker compose \ + -f docker/docker-compose-base.yml \ + -f ./docker/docker-compose-test-all.yml \ --env-file local-test.env \ up -d @@ -63,7 +65,11 @@ if [ "$(docker inspect -f '{{.State.ExitCode}}' unit-tests)" -ne 0 ]; then printf "\nāŒ Unit tests failed. Printing logs...\n" docker logs unit-tests printf "\n Stopping containers\n" - docker compose -f ./docker-compose-test.yml --env-file local-test.env down + docker compose \ + -f docker/docker-compose-base.yml \ + -f ./docker/docker-compose-test-all.yml \ + --env-file local-test.env \ + down exit 1 fi @@ -73,5 +79,9 @@ cat dv/unit-tests.log printf "\n\nāœ… Unit tests passed\n\n" # Stop all containers -docker compose -f ./docker-compose-test.yml --env-file local-test.env down +docker compose \ + -f docker/docker-compose-base.yml \ + -f ./docker/docker-compose-test-all.yml \ + --env-file local-test.env \ + down printf "\nšŸŽ‰ Done\n\n" From 830e7d726114745504d92a69893b5a300d89b97f Mon Sep 17 00:00:00 2001 From: Jan Range Date: Fri, 12 Apr 2024 00:06:58 +0200 Subject: [PATCH 8/9] extend documentation --- README.md | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0ed53cc..64b88ba 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![PyPI](https://img.shields.io/pypi/v/pyDataverse.svg)](https://pypi.org/project/pyDataverse/) ![Build Status](https://github.com/gdcc/pyDataverse/actions/workflows/test_build.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/gdcc/pyDataverse/badge.svg)](https://coveralls.io/github/gdcc/pyDataverse) [![Documentation Status](https://readthedocs.org/projects/pydataverse/badge/?version=latest)](https://pydataverse.readthedocs.io/en/latest) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pydataverse.svg) [![GitHub](https://img.shields.io/github/license/gdcc/pydataverse.svg)](https://opensource.org/licenses/MIT) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4664557.svg)](https://doi.org/10.5281/zenodo.4664557) +[![PyPI](https://img.shields.io/pypi/v/pyDataverse.svg)](https://pypi.org/project/pyDataverse/) ![Build Status](https://github.com/gdcc/pyDataverse/actions/workflows/test_build.yml/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/gdcc/pyDataverse/badge.svg)](https://coveralls.io/github/gdcc/pyDataverse) [![Documentation Status](https://readthedocs.org/projects/pydataverse/badge/?version=latest)](https://pydataverse.readthedocs.io/en/latest) PyPI - Python Version [![GitHub](https://img.shields.io/github/license/gdcc/pydataverse.svg)](https://opensource.org/licenses/MIT) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4664557.svg)](https://doi.org/10.5281/zenodo.4664557) # pyDataverse @@ -9,18 +9,46 @@ It helps to access the Dataverse [API's](http://guides.dataverse.org/en/latest/a **Find out more: [Read the Docs](https://pydataverse.readthedocs.io/en/latest/)** -## Running the tests +# Running tests -To run pyDataverse's tests locally, you need to install docker and docker-compose. This will spin up a local Dataverse instance and run the tests against it. You can run the tests with: +In order to run the tests, you need to have a Dataverse instance running. We have prepared a shell script that will start a Dataverse instance using Docker that runs all tests in a clean environment. To run the tests, execute the following command: ```bash -sh run_tests.sh +# Defaults to Python 3.11 +./run_tests.sh + +# To run the tests with a specific Python version +./run_tests.sh -p 3.8 +``` + +Once finished, you can find the test results in the `dv/unit-tests.log` file and in the terminal. + +## Manual setup + +If you want to run single tests you need to manually set up the environment and set up the necessary environment variables. Please follow the instructions below. + +## 1. Start the Dataverse instance + +```bash +docker compose \ + -f ./docker/docker-compose-base.yml \ + --env-file local-test.env \ + up -d +``` + +## 2. Set up the environment variables + +```bash +export BASE_URL=http://localhost:8080 +export DV_VERSION=6.2 # or any other version +export $(grep "API_TOKEN" "dv/bootstrap.exposed.env") +export API_TOKEN_SUPERUSER=$API_TOKEN ``` -By default local tests are using the python `3.11` slim image. However, you can change the python version by providing a valid version via the `-p` keyword argument. For example, to run the tests with python `3.9`: +## 3. Run the test(s) with pytest ```bash -sh run_tests.sh -p 3.9 +python -m pytest -v ``` ## Chat with us! From a8ede2cf2eb85740e37026c6922ee8c4e9967555 Mon Sep 17 00:00:00 2001 From: Jan Range <30547301+JR-1991@users.noreply.github.com> Date: Fri, 12 Apr 2024 02:02:08 +0200 Subject: [PATCH 9/9] use bold instead of headings --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 64b88ba..75c97c2 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Once finished, you can find the test results in the `dv/unit-tests.log` file and If you want to run single tests you need to manually set up the environment and set up the necessary environment variables. Please follow the instructions below. -## 1. Start the Dataverse instance +**1. Start the Dataverse instance** ```bash docker compose \ @@ -36,7 +36,7 @@ docker compose \ up -d ``` -## 2. Set up the environment variables +**2. Set up the environment variables** ```bash export BASE_URL=http://localhost:8080 @@ -45,7 +45,7 @@ export $(grep "API_TOKEN" "dv/bootstrap.exposed.env") export API_TOKEN_SUPERUSER=$API_TOKEN ``` -## 3. Run the test(s) with pytest +**3. Run the test(s) with pytest** ```bash python -m pytest -v