Skip to content

Commit 44e097f

Browse files
authored
Merge pull request #1486 from dandi/gh-1484
Dump audit table to file specified by `DANDI_TESTS_AUDIT_CSV` envvar
2 parents 649d89d + 9abc18f commit 44e097f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

.github/workflows/test.yml

+10
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,17 @@ jobs:
110110
- name: Run Dandi API tests only
111111
if: matrix.mode == 'dandi-api'
112112
run: |
113+
export DANDI_TESTS_AUDIT_CSV=/tmp/audit.csv
113114
python -m pytest -s -v --cov=dandi --cov-report=xml --dandi-api dandi
115+
if [ ! -e /tmp/audit.csv ]
116+
then echo Audit file not created
117+
exit 1
118+
fi
119+
lines="$(wc -l /tmp/audit.csv | awk '{print $1}')"
120+
if [ "$lines" -lt 100 ]
121+
then echo Audit file shorter than expected - only "$lines" lines
122+
exit 1
123+
fi
114124
115125
- name: Dump Docker Compose logs
116126
if: failure() && startsWith(matrix.os, 'ubuntu')

dandi/tests/fixtures.py

+21
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,27 @@ def docker_compose_setup() -> Iterator[dict[str, str]]:
488488
raise RuntimeError("Django container did not start up in time")
489489
yield {"django_api_key": django_api_key}
490490
finally:
491+
if auditfile := os.environ.get("DANDI_TESTS_AUDIT_CSV", ""):
492+
with open(auditfile, "wb") as fp:
493+
run(
494+
[
495+
"docker",
496+
"compose",
497+
"exec",
498+
"postgres",
499+
"psql",
500+
"-U",
501+
"postgres",
502+
"-d",
503+
"django",
504+
"--csv",
505+
"-c",
506+
"SELECT * FROM api_auditrecord;",
507+
],
508+
stdout=fp,
509+
cwd=str(LOCAL_DOCKER_DIR),
510+
check=True,
511+
)
491512
if persist in (None, "0"):
492513
run(
493514
["docker", "compose", "down", "-v"],

0 commit comments

Comments
 (0)