MINOR: use archive instead of volume for postgres test (#16245)

* using archive instead of volume for postgres test

* format

* remove usage of request
This commit is contained in:
Imri Paran 2024-05-14 11:11:16 +02:00 committed by GitHub
parent 2e52475b68
commit c277233ef1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,5 @@
import os
import tarfile
import zipfile
from subprocess import CalledProcessError
@ -11,9 +12,10 @@ def postgres_container(tmp_path_factory):
data_dir = tmp_path_factory.mktemp("data")
dvd_rental_zip = os.path.join(os.path.dirname(__file__), "data", "dvdrental.zip")
zipfile.ZipFile(dvd_rental_zip, "r").extractall(str(data_dir))
with tarfile.open(data_dir / "dvdrental_data.tar", "w") as tar:
tar.add(data_dir / "dvdrental.tar", arcname="dvdrental.tar")
container = PostgresContainer("postgres:15", dbname="dvdrental")
container.volumes = {str(data_dir): {"bind": "/data"}}
container._command = [
"-c",
"shared_preload_libraries=pg_stat_statements",
@ -25,6 +27,10 @@ def postgres_container(tmp_path_factory):
with container as container:
docker_container = container.get_wrapped_container()
docker_container.exec_run(["mkdir", "/data"])
docker_container.put_archive(
"/data/", open(data_dir / "dvdrental_data.tar", "rb")
)
for query in (
"CREATE USER postgres SUPERUSER;",
"CREATE EXTENSION pg_stat_statements;",