Skip to content

Commit

Permalink
Merge pull request #1486 from dandi/gh-1484
Browse files Browse the repository at this point in the history
Dump audit table to file specified by `DANDI_TESTS_AUDIT_CSV` envvar
  • Loading branch information
yarikoptic authored Aug 15, 2024
2 parents 649d89d + 9abc18f commit 44e097f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,17 @@ jobs:
- name: Run Dandi API tests only
if: matrix.mode == 'dandi-api'
run: |
export DANDI_TESTS_AUDIT_CSV=/tmp/audit.csv
python -m pytest -s -v --cov=dandi --cov-report=xml --dandi-api dandi
if [ ! -e /tmp/audit.csv ]
then echo Audit file not created
exit 1
fi
lines="$(wc -l /tmp/audit.csv | awk '{print $1}')"
if [ "$lines" -lt 100 ]
then echo Audit file shorter than expected - only "$lines" lines
exit 1
fi
- name: Dump Docker Compose logs
if: failure() && startsWith(matrix.os, 'ubuntu')
Expand Down
21 changes: 21 additions & 0 deletions dandi/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,27 @@ def docker_compose_setup() -> Iterator[dict[str, str]]:
raise RuntimeError("Django container did not start up in time")
yield {"django_api_key": django_api_key}
finally:
if auditfile := os.environ.get("DANDI_TESTS_AUDIT_CSV", ""):
with open(auditfile, "wb") as fp:
run(
[
"docker",
"compose",
"exec",
"postgres",
"psql",
"-U",
"postgres",
"-d",
"django",
"--csv",
"-c",
"SELECT * FROM api_auditrecord;",
],
stdout=fp,
cwd=str(LOCAL_DOCKER_DIR),
check=True,
)
if persist in (None, "0"):
run(
["docker", "compose", "down", "-v"],
Expand Down

0 comments on commit 44e097f

Please sign in to comment.