Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ In order to run the tests, you need to have a Dataverse instance running. We hav
./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.
Once finished, you can find the test results in the `dv/unit-tests.log` file and in the terminal. The Dataverse logs are saved in the `dv/dataverse-logs.log` file and can be helpful in cases of internal server errors. If you happen to encounter such an error, please share the logs with us at the [Zulip](https://dataverse.zulipchat.com/#narrow/stream/377090-python) so we can investigate the issue.

## Manual setup

Expand All @@ -45,7 +45,16 @@ export $(grep "API_TOKEN" "dv/bootstrap.exposed.env")
export API_TOKEN_SUPERUSER=$API_TOKEN
```

**3. Run the test(s) with pytest**
**3. Install test dependencies

```
python3 -m venv venv # or conda create -n pydataverse
source venv/bin/activate
pip install -e .
python3 -m pip install pytest pytest-cov pytest-asyncio tox selenium
```

**4. Run the test(s) with pytest**

```bash
python -m pytest -v
Expand Down
48 changes: 23 additions & 25 deletions docker/docker-compose-base.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
version: "2.4"
name: pydataverse
services:
dataverse:
container_name: "dataverse"
container_name: 'dataverse'
hostname: dataverse
image: ${DATAVERSE_IMAGE}
restart: on-failure
Expand All @@ -18,7 +17,7 @@ services:
-Ddataverse.pid.fake.authority=10.5072
-Ddataverse.pid.fake.shoulder=FK2/
ports:
- "8080:8080"
- '8080:8080'
networks:
- dataverse
depends_on:
Expand All @@ -30,7 +29,6 @@ services:
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
Expand All @@ -45,68 +43,68 @@ services:
timeout: 240s

dv_initializer:
container_name: "dv_initializer"
container_name: 'dv_initializer'
image: ${CONFIGBAKER_IMAGE}
restart: "no"
restart: 'no'
command:
- sh
- -c
- "fix-fs-perms.sh dv"
- 'fix-fs-perms.sh dv'
volumes:
- ${PWD}/dv/data:/dv

postgres:
container_name: "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"
- '5432:5432'
networks:
- dataverse

solr_initializer:
container_name: "solr_initializer"
container_name: 'solr_initializer'
image: ${CONFIGBAKER_IMAGE}
restart: "no"
restart: 'no'
command:
- sh
- -c
- "fix-fs-perms.sh solr && cp -a /template/* /solr-template"
- '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"
container_name: 'solr'
hostname: 'solr'
image: solr:${SOLR_VERSION}
depends_on:
solr_initializer:
condition: service_completed_successfully
restart: on-failure
ports:
- "8983:8983"
- '8983:8983'
networks:
- dataverse
command:
- "solr-precreate"
- "collection1"
- "/template"
- 'solr-precreate'
- 'collection1'
- '/template'
volumes:
- ${PWD}/solr/data:/var/solr
- ${PWD}/solr/conf:/template

smtp:
container_name: "smtp"
hostname: "smtp"
container_name: 'smtp'
hostname: 'smtp'
image: maildev/maildev:2.0.5
restart: on-failure
expose:
- "25" # smtp server
- '25' # smtp server
environment:
- MAILDEV_SMTP_PORT=25
- MAILDEV_MAIL_DIRECTORY=/mail
Expand All @@ -116,18 +114,18 @@ services:
- /mail:mode=770,size=128M,uid=1000,gid=1000

bootstrap:
container_name: "bootstrap"
hostname: "bootstrap"
container_name: 'bootstrap'
hostname: 'bootstrap'
image: ${CONFIGBAKER_IMAGE}
restart: "no"
restart: 'no'
networks:
- dataverse
volumes:
- ${PWD}/dv/bootstrap.exposed.env:/.env
command:
- sh
- -c
- "bootstrap.sh -e /.env dev"
- 'bootstrap.sh -e /.env dev'
depends_on:
dataverse:
condition: service_healthy
Expand Down
37 changes: 28 additions & 9 deletions docker/docker-compose-test-all.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,49 @@
version: "2.4"
services:
unit-tests:
container_name: unit-tests
image: python:${PYTHON_VERSION}-slim
environment:
BASE_URL: http://dataverse:8080
DV_VERSION: 6.3
networks:
- dataverse
volumes:
- ${PWD}:/pydataverse
- ../dv:/dv
- ${PWD}/dv:/dv
command:
- sh
- -c
- -ceu
- |
set -o pipefail

# Install curl
apt-get update && apt-get install -y curl

# Wait for Dataverse to be ready
echo "⏳ Waiting for Dataverse to be ready..."
until curl -f http://dataverse:8080/api/info/version >/dev/null 2>&1; do
echo " Waiting for Dataverse API..."
sleep 5
done
echo "✅ Dataverse is ready!"

# Fetch Dataverse version dynamically
echo "🔍 Fetching Dataverse version..."
export DV_VERSION=$$(curl -s http://dataverse:8080/api/info/version | grep -o '"version":"[^"]*"' | cut -d'"' -f4)
echo " Detected Dataverse version: $$DV_VERSION"

# Fetch the API Token from the local file
export $(grep "API_TOKEN" "dv/bootstrap.exposed.env")
export $$(grep "API_TOKEN" "dv/bootstrap.exposed.env")
export API_TOKEN_SUPERUSER=$$API_TOKEN

cd /pydataverse

# Run the unit tests
# Install Poetry and dependencies
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
python3 -m pip install .
python3 -m pip install pytest pytest-cov pytest-asyncio tox selenium

echo "🧪 Starting pytest with DV_VERSION=${DV_VERSION}..."
python3 -m pytest -vv --tb=short 2>&1 | tee /dv/unit-tests.log

depends_on:
bootstrap:
Expand Down
5 changes: 4 additions & 1 deletion local-test.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ CONFIGBAKER_IMAGE=docker.io/gdcc/configbaker:unstable

# Services
POSTGRES_VERSION=15
SOLR_VERSION=9.3.0
SOLR_VERSION=9.8.0

# Default Dataverse version (will be dynamically detected in tests)
DV_VERSION=6.7.1
54 changes: 44 additions & 10 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,54 @@ export PYTHON_VERSION=${p}
printf "\n🚀 Preparing containers\n"
printf " Using PYTHON_VERSION=${p}\n\n"

# Run all containers
# Start all containers (infrastructure + tests)
printf "\n🚀 Starting all containers...\n"
printf " The test container will wait for Dataverse and fetch the version automatically\n\n"

docker compose \
-f docker/docker-compose-base.yml \
-f ./docker/docker-compose-test-all.yml \
--env-file local-test.env \
up -d

printf "\n🔎 Running pyDataverse tests\n"
printf " Logs will be printed once finished...\n\n"
printf " Test container will handle version detection and testing...\n\n"

# Check if "unit-test" container has finished
WAIT_COUNT=0
while [ -n "$(docker ps -f "name=unit-tests" -f "status=running" -q)" ]; do
printf " Waiting for unit-tests container to finish...\n"
WAIT_COUNT=$((WAIT_COUNT + 1))
printf " ⏳ Waiting for tests to complete... (${WAIT_COUNT})\n"
sleep 5
done

# 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"
EXIT_CODE=$(docker inspect -f '{{.State.ExitCode}}' unit-tests 2>/dev/null)

if [ -z "$EXIT_CODE" ]; then
printf "\n❌ Unit tests container not found or failed to start\n"
EXIT_CODE=1
else
printf "\n📋 Unit tests completed with exit code: ${EXIT_CODE}\n"
fi

# Capture Dataverse logs after tests complete
printf "\n📝 Capturing Dataverse logs...\n"
docker logs dataverse > dv/dataverse-logs.log 2>&1

if [ "${EXIT_CODE}" -ne 0 ]; then
printf "\n❌ Unit tests failed. Showing test results...\n\n"
printf "=== PYTEST OUTPUT ===\n"
if [ -f "dv/unit-tests.log" ]; then
cat dv/unit-tests.log
else
printf "⚠️ Test log file not found, showing container logs instead:\n"
docker logs unit-tests
fi
printf "\n=== END PYTEST OUTPUT ===\n"


printf "\n🧹 Stopping containers...\n"
docker compose \
-f docker/docker-compose-base.yml \
-f ./docker/docker-compose-test-all.yml \
Expand All @@ -74,11 +101,18 @@ if [ "$(docker inspect -f '{{.State.ExitCode}}' unit-tests)" -ne 0 ]; then
fi

# Print test results
printf "\n"
cat dv/unit-tests.log
printf "\n\n✅ Unit tests passed\n\n"
printf "\n✅ Unit tests passed! Showing results...\n\n"
printf "=== PYTEST RESULTS ===\n"
if [ -f "dv/unit-tests.log" ]; then
cat dv/unit-tests.log
else
printf "⚠️ Test log file not found, showing container logs:\n"
docker logs unit-tests
fi
printf "\n=== END PYTEST RESULTS ===\n"

# Stop all containers
printf "\n🧹 Stopping containers...\n"
docker compose \
-f docker/docker-compose-base.yml \
-f ./docker/docker-compose-test-all.yml \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting this error:

pdurbin@beamish pyDataverse % ./run-tests.sh

⚠️  No Python version specified falling back to '3.11'

🚀 Preparing containers
   Using PYTHON_VERSION=3.11


🚀 Starting all containers...
   The test container will wait for Dataverse and fetch the version automatically

[+] Running 10/10
 ✔ Network pydataverse_dataverse  Created                                                                      0.0s 
 ✔ Network pydataverse_default    Created                                                                      0.0s 
 ✔ Container dv_initializer       Exited                                                                       1.4s 
 ✔ Container solr_initializer     Exited                                                                       0.8s 
 ✔ Container postgres             Started                                                                      0.3s 
 ✔ Container smtp                 Started                                                                      0.3s 
 ✔ Container solr                 Started                                                                      0.9s 
 ✔ Container dataverse            Healthy                                                                     31.9s 
 ✔ Container bootstrap            Exited                                                                      47.0s 
 ✔ Container unit-tests           Started                                                                     47.0s 

🔎 Running pyDataverse tests
   Test container will handle version detection and testing...

   ⏳ Waiting for tests to complete... (1)
   ⏳ Waiting for tests to complete... (2)
   ⏳ Waiting for tests to complete... (3)
   ⏳ Waiting for tests to complete... (4)
   ⏳ Waiting for tests to complete... (5)
   ⏳ Waiting for tests to complete... (6)
   ⏳ Waiting for tests to complete... (7)
   ⏳ Waiting for tests to complete... (8)

📋 Unit tests completed with exit code: 1

❌ Unit tests failed. Showing test results...

=== PYTEST OUTPUT ===
============================= test session starts ==============================
platform linux -- Python 3.11.13, pytest-8.4.2, pluggy-1.6.0 -- /usr/local/bin/python3
cachedir: .pytest_cache
rootdir: /pydataverse
configfile: pyproject.toml
plugins: asyncio-1.2.0, cov-7.0.0, anyio-4.11.0
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collecting ... collected 82 items

tests/api/test_access.py::TestDataAccess::test_get_data_by_id PASSED     [  1%]
tests/api/test_access.py::TestDataAccess::test_get_data_by_pid PASSED    [  2%]
tests/api/test_api.py::TestApiConnect::test_api_connect PASSED           [  3%]
tests/api/test_api.py::TestApiConnect::test_api_connect_base_url_wrong PASSED [  4%]
tests/api/test_api.py::TestApiTokenAndAuthBehavior::test_api_token_none_and_auth_none PASSED [  6%]
tests/api/test_api.py::TestApiTokenAndAuthBehavior::test_api_token_none_and_auth PASSED [  7%]
tests/api/test_api.py::TestApiTokenAndAuthBehavior::test_api_token_and_auth PASSED [  8%]
tests/api/test_api.py::TestApiTokenAndAuthBehavior::test_api_token_and_auth_none PASSED [  9%]
tests/api/test_api.py::TestApiRequests::test_get_request PASSED          [ 10%]
tests/api/test_api.py::TestApiRequests::test_get_dataverse PASSED        [ 12%]
tests/api/test_api.py::TestApiToken::test_token_missing PASSED           [ 13%]
tests/api/test_api.py::TestApiToken::test_token_empty_string PASSED      [ 14%]
tests/api/test_api.py::TestApiToken::test_token_right_create_dataset_rights FAILED [ 15%]
tests/api/test_api.py::TestApiToken::test_token_should_not_be_exposed_on_error PASSED [ 17%]
tests/api/test_api.py::TestApiToken::test_using_auth_on_individual_requests_is_deprecated[True] PASSED [ 18%]
tests/api/test_api.py::TestApiToken::test_using_auth_on_individual_requests_is_deprecated[False] PASSED [ 19%]
tests/api/test_api.py::TestApiToken::test_using_auth_on_individual_requests_is_deprecated[api-token] PASSED [ 20%]
tests/api/test_api.py::TestApiToken::test_using_auth_on_individual_requests_is_deprecated[auth3] PASSED [ 21%]
tests/api/test_api.py::TestApiToken::test_using_auth_on_individual_requests_is_deprecated_unauthorized[True] PASSED [ 23%]
tests/api/test_api.py::TestApiToken::test_using_auth_on_individual_requests_is_deprecated_unauthorized[False] PASSED [ 24%]
tests/api/test_api.py::TestApiToken::test_using_auth_on_individual_requests_is_deprecated_unauthorized[api-token] PASSED [ 25%]
tests/api/test_api.py::TestApiToken::test_using_auth_on_individual_requests_is_deprecated_unauthorized[auth3] PASSED [ 26%]
tests/api/test_api.py::TestApiToken::test_sword_api_requires_http_basic_auth PASSED [ 28%]
tests/api/test_api.py::TestApiToken::test_sword_api_can_authenticate PASSED [ 29%]
tests/api/test_api.py::TestApiToken::test_sword_api_cannot_authenticate_without_token PASSED [ 30%]
tests/api/test_async_api.py::TestAsyncAPI::test_async_api PASSED         [ 31%]
tests/api/test_edit.py::TestEditDatasetMetadata::test_edit_dataset_metadata_replace PASSED [ 32%]
tests/api/test_edit.py::TestEditDatasetMetadata::test_edit_dataset_metadata_add PASSED [ 34%]
tests/api/test_upload.py::TestFileUpload::test_file_upload PASSED        [ 35%]
tests/api/test_upload.py::TestFileUpload::test_file_upload_without_metadata PASSED [ 36%]
tests/api/test_upload.py::TestFileUpload::test_bulk_file_upload PASSED   [ 37%]
tests/api/test_upload.py::TestFileUpload::test_file_replacement_wo_metadata FAILED [ 39%]
tests/api/test_upload.py::TestFileUpload::test_file_replacement_w_metadata FAILED [ 40%]
tests/auth/test_auth.py::TestApiTokenAuth::test_token_header_is_added_during_auth_flow PASSED [ 41%]
tests/auth/test_auth.py::TestApiTokenAuth::test_raise_if_token_is_not_str[123_0] PASSED [ 42%]
tests/auth/test_auth.py::TestApiTokenAuth::test_raise_if_token_is_not_str[non_str_token1] PASSED [ 43%]
tests/auth/test_auth.py::TestApiTokenAuth::test_raise_if_token_is_not_str[<lambda>] PASSED [ 45%]
tests/auth/test_auth.py::TestApiTokenAuth::test_raise_if_token_is_not_str[1.423] PASSED [ 46%]
tests/auth/test_auth.py::TestApiTokenAuth::test_raise_if_token_is_not_str[123_1] PASSED [ 47%]
tests/auth/test_auth.py::TestApiTokenAuth::test_raise_if_token_is_not_str[non_str_token5] PASSED [ 48%]
tests/auth/test_auth.py::TestBearerTokenAuth::test_authorization_header_is_added_during_auth_flow PASSED [ 50%]
tests/auth/test_auth.py::TestBearerTokenAuth::test_raise_if_token_is_not_str[123_0] PASSED [ 51%]
tests/auth/test_auth.py::TestBearerTokenAuth::test_raise_if_token_is_not_str[non_str_token1] PASSED [ 52%]
tests/auth/test_auth.py::TestBearerTokenAuth::test_raise_if_token_is_not_str[<lambda>] PASSED [ 53%]
tests/auth/test_auth.py::TestBearerTokenAuth::test_raise_if_token_is_not_str[1.423] PASSED [ 54%]
tests/auth/test_auth.py::TestBearerTokenAuth::test_raise_if_token_is_not_str[123_1] PASSED [ 56%]
tests/auth/test_auth.py::TestBearerTokenAuth::test_raise_if_token_is_not_str[non_str_token5] PASSED [ 57%]
tests/models/test_datafile.py::TestDatafileGeneric::test_datafile_set_and_get_valid PASSED [ 58%]
tests/models/test_datafile.py::TestDatafileGeneric::test_datafile_set_invalid PASSED [ 59%]
tests/models/test_datafile.py::TestDatafileGeneric::test_datafile_from_json_valid PASSED [ 60%]
tests/models/test_datafile.py::TestDatafileGeneric::test_datafile_from_json_invalid PASSED [ 62%]
tests/models/test_datafile.py::TestDatafileGeneric::test_datafile_to_json_valid PASSED [ 63%]
tests/models/test_datafile.py::TestDatafileGeneric::test_datafile_to_json_invalid PASSED [ 64%]
tests/models/test_datafile.py::TestDatafileGeneric::test_datafile_validate_json_valid PASSED [ 65%]
tests/models/test_datafile.py::TestDatafileGeneric::test_datafile_validate_json_invalid PASSED [ 67%]
tests/models/test_datafile.py::TestDatafileSpecific::test_datafile_init_valid PASSED [ 68%]
tests/models/test_datafile.py::TestDatafileSpecific::test_datafile_init_invalid PASSED [ 69%]
tests/models/test_datafile.py::TestDatafileGenericTravisNot::test_dataverse_from_json_to_json_valid PASSED [ 70%]
tests/models/test_dataset.py::TestDatasetGeneric::test_dataset_set_and_get_valid PASSED [ 71%]
tests/models/test_dataset.py::TestDatasetGeneric::test_dataset_set_invalid PASSED [ 73%]
tests/models/test_dataset.py::TestDatasetGeneric::test_dataset_validate_json_valid PASSED [ 74%]
tests/models/test_dataset.py::TestDatasetSpecific::test_dataset_from_json_valid PASSED [ 75%]
tests/models/test_dataset.py::TestDatasetSpecific::test_dataset_to_json_valid PASSED [ 76%]
tests/models/test_dataset.py::TestDatasetSpecific::test_dataset_init_valid PASSED [ 78%]
tests/models/test_dataset.py::TestDatasetSpecific::test_dataset_init_invalid PASSED [ 79%]
tests/models/test_dataset.py::TestDatasetSpecific::test_dataset_from_json_invalid PASSED [ 80%]
tests/models/test_dataset.py::TestDatasetSpecific::test_dataset_to_json_invalid PASSED [ 81%]
tests/models/test_dataset.py::TestDatasetSpecific::test_dataset_validate_json_invalid PASSED [ 82%]
tests/models/test_dataset.py::TestDatasetSpecificTravisNot::test_dataset_to_json_from_json_valid PASSED [ 84%]
tests/models/test_dataverse.py::TestDataverseGeneric::test_dataverse_set_and_get_valid PASSED [ 85%]
tests/models/test_dataverse.py::TestDataverseGeneric::test_dataverse_set_invalid PASSED [ 86%]
tests/models/test_dataverse.py::TestDataverseGeneric::test_dataverse_from_json_valid PASSED [ 87%]
tests/models/test_dataverse.py::TestDataverseGeneric::test_dataverse_from_json_invalid PASSED [ 89%]
tests/models/test_dataverse.py::TestDataverseGeneric::test_dataverse_to_json_valid PASSED [ 90%]
tests/models/test_dataverse.py::TestDataverseGeneric::test_dataverse_to_json_invalid PASSED [ 91%]
tests/models/test_dataverse.py::TestDataverseGeneric::test_dataverse_validate_json_valid PASSED [ 92%]
tests/models/test_dataverse.py::TestDataverseGeneric::test_dataverse_validate_json_invalid PASSED [ 93%]
tests/models/test_dataverse.py::TestDataverseSpecific::test_dataverse_init_valid PASSED [ 95%]
tests/models/test_dataverse.py::TestDataverseSpecific::test_dataverse_init_invalid PASSED [ 96%]
tests/models/test_dataverse.py::TestDataverseGenericTravisNot::test_dataverse_from_json_to_json_valid PASSED [ 97%]
tests/models/test_dvobject.py::TestDVObject::test_dataverse_init PASSED  [ 98%]
tests/utils/test_utils.py::TestUtilsSaveTreeData::test_dataverse_tree_walker_valid_default PASSED [100%]

=================================== FAILURES ===================================
_____________ TestApiToken.test_token_right_create_dataset_rights ______________
tests/api/test_api.py:184: in test_token_right_create_dataset_rights
    assert resp.json()["status"] == "OK"
E   AssertionError: assert 'ERROR' == 'OK'
E     
E     - OK
E     + ERROR
----------------------------- Captured stdout call -----------------------------
Dataset with pid 'doi:10.5072/FK2/AMR3PV' created.
_______________ TestFileUpload.test_file_replacement_wo_metadata _______________
tests/api/test_upload.py:186: in test_file_replacement_wo_metadata
    file_id = response.json()["data"]["files"][0]["dataFile"]["id"]
              ^^^^^^^^^^^^^^^^^^^^^^^
E   KeyError: 'data'
_______________ TestFileUpload.test_file_replacement_w_metadata ________________
tests/api/test_upload.py:248: in test_file_replacement_w_metadata
    file_id = response.json()["data"]["files"][0]["dataFile"]["id"]
              ^^^^^^^^^^^^^^^^^^^^^^^
E   KeyError: 'data'
=============================== warnings summary ===============================
tests/api/test_api.py: 3 warnings
tests/api/test_upload.py: 56 warnings
  /pydataverse/pyDataverse/api.py:244: DeprecationWarning: The auth parameter is deprecated. Please pass your auth arguments to the __init__ method instead.
    warn(

tests/api/test_api.py::TestApiToken::test_token_right_create_dataset_rights
  /pydataverse/pyDataverse/api.py:374: DeprecationWarning: The auth parameter is deprecated. Please pass your auth arguments to the __init__ method instead.
    warn(

tests/api/test_api.py::TestApiToken::test_sword_api_requires_http_basic_auth
tests/api/test_api.py::TestApiToken::test_sword_api_can_authenticate
  /pydataverse/pyDataverse/api.py:127: UserWarning: You provided both, an api_token and a custom auth method. We will only use the auth method.
    warn(

tests/api/test_api.py::TestApiToken::test_sword_api_can_authenticate
tests/api/test_api.py::TestApiToken::test_sword_api_cannot_authenticate_without_token
tests/api/test_edit.py::TestEditDatasetMetadata::test_edit_dataset_metadata_replace
tests/api/test_edit.py::TestEditDatasetMetadata::test_edit_dataset_metadata_add
  /pydataverse/pyDataverse/api.py:182: DeprecationWarning: The auth parameter is deprecated. Please pass your auth arguments to the __init__ method instead.
    warn(

tests/api/test_edit.py::TestEditDatasetMetadata::test_edit_dataset_metadata_replace
tests/api/test_edit.py::TestEditDatasetMetadata::test_edit_dataset_metadata_add
  /pydataverse/pyDataverse/api.py:312: DeprecationWarning: The auth parameter is deprecated. Please pass your auth arguments to the __init__ method instead.
    warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================ tests coverage ================================
_______________ coverage: platform linux, python 3.11.13-final-0 _______________

Name                        Stmts   Miss  Cover
-----------------------------------------------
pyDataverse/__init__.py         9      0   100%
pyDataverse/api.py            579    334    42%
pyDataverse/auth.py            19      0   100%
pyDataverse/exceptions.py      20      0   100%
pyDataverse/models.py         521     71    86%
pyDataverse/utils.py          216    140    35%
-----------------------------------------------
TOTAL                        1364    545    60%
=========================== short test summary info ============================
FAILED tests/api/test_api.py::TestApiToken::test_token_right_create_dataset_rights - AssertionError: assert 'ERROR' == 'OK'
  
  - OK
  + ERROR
FAILED tests/api/test_upload.py::TestFileUpload::test_file_replacement_wo_metadata - KeyError: 'data'
FAILED tests/api/test_upload.py::TestFileUpload::test_file_replacement_w_metadata - KeyError: 'data'
================== 3 failed, 79 passed, 68 warnings in 9.87s ===================

=== END PYTEST OUTPUT ===

🧹 Stopping containers...
[+] Running 10/10
 ✔ Container unit-tests           Removed                                                                      0.1s 
 ✔ Container smtp                 Removed                                                                      0.1s 
 ✔ Container bootstrap            Removed                                                                      0.0s 
 ✔ Container dataverse            Removed                                                                     10.2s 
 ✔ Container postgres             Removed                                                                      0.2s 
 ✔ Container solr                 Removed                                                                      0.6s 
 ✔ Container dv_initializer       Removed                                                                      0.0s 
 ✔ Container solr_initializer     Removed                                                                      0.0s 
 ✔ Network pydataverse_dataverse  Removed                                                                      0.2s 
 ✔ Network pydataverse_default    Removed                                                                      0.4s 
pdurbin@beamish pyDataverse %

Expand Down
14 changes: 11 additions & 3 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,22 @@ def test_token_right_create_dataset_rights(self):
)
)
resp = api_su.create_dataset(":root", ds.json())
pid = resp.json()["data"]["persistentId"]
assert resp.json()["status"] == "OK"
resp.raise_for_status()

resp = resp.json()
pid = resp["data"]["persistentId"]

if resp["status"] != "OK":
raise Exception(resp["message"])

# with pytest.raises(ApiAuthorizationError):
# resp = api_nru.get_dataset(pid)

resp = api_su.delete_dataset(pid)
assert resp.json()["status"] == "OK"
resp.raise_for_status()
resp = resp.json()
if resp["status"] != "OK":
raise Exception(resp["message"])

def test_token_should_not_be_exposed_on_error(self):
BASE_URL = os.getenv("BASE_URL")
Expand Down
11 changes: 11 additions & 0 deletions tests/api/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def test_file_replacement_wo_metadata(self):
json_str=df.json(),
)

response.raise_for_status()

# Retrieve file ID
file_id = response.json()["data"]["files"][0]["dataFile"]["id"]

Expand All @@ -182,6 +184,9 @@ def test_file_replacement_wo_metadata(self):
is_filepid=False,
)

if not response.is_success:
raise Exception(response.json()["message"])

# Assert
file_id = response.json()["data"]["files"][0]["dataFile"]["id"]
content = data_api.get_datafile(file_id, is_pid=False).text
Expand Down Expand Up @@ -218,6 +223,9 @@ def test_file_replacement_w_metadata(self):
json_str=df.json(),
)

if not response.is_success:
raise Exception(response.json()["message"])

# Retrieve file ID
file_id = response.json()["data"]["files"][0]["dataFile"]["id"]

Expand All @@ -244,6 +252,9 @@ def test_file_replacement_w_metadata(self):
is_filepid=False,
)

if not response.is_success:
raise Exception(response.json()["message"])

# Assert
file_id = response.json()["data"]["files"][0]["dataFile"]["id"]
data_file = api.get_dataset(pid).json()["data"]["latestVersion"]["files"][0]
Expand Down