Skip to content

Commit

Permalink
Update tox config for tox-docker 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Oct 30, 2024
1 parent aaa4cac commit 8cb3237
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
24 changes: 22 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ class CannotSendEmail(Exception):
pass


def _url_from_environment(environment_variable: str) -> str | None:
url = os.environ.get(environment_variable)
if url is not None:
return url

# Try loading the URL in pieces. This is necessary in CI.
scheme = os.environ.get(environment_variable + "_SCHEME")
host = os.environ.get(environment_variable + "_HOST")
port = os.environ.get(environment_variable + "_PORT")
user = os.environ.get(environment_variable + "_USER")
password = os.environ.get(environment_variable + "_PASSWORD")

if scheme and host and port:
if user and password:
host = f"{user}:{password}@" + host
return f"{scheme}://{host}:{port}"

return None


class Configuration:
DATADIR = Path(os.path.dirname(__file__)) / "data"

Expand Down Expand Up @@ -95,7 +115,7 @@ def database_url(cls, test=False):
else:
environment_variable = cls.DATABASE_PRODUCTION_ENVIRONMENT_VARIABLE

url = os.environ.get(environment_variable)
url = _url_from_environment(environment_variable)
if not url:
raise CannotLoadConfiguration(
"Database URL was not defined in environment variable (%s) or configuration file."
Expand Down Expand Up @@ -137,7 +157,7 @@ def aws_config(cls) -> "AWSConfig":
"""Return the AWS configurations setup in the environment"""
return AWSConfig(
bucket_name=os.environ.get(cls.AWS_S3_BUCKET_NAME),
endpoint_url=os.environ.get(cls.AWS_S3_ENDPOINT_URL),
endpoint_url=_url_from_environment(cls.AWS_S3_ENDPOINT_URL),
)


Expand Down
7 changes: 3 additions & 4 deletions tests/util/test_file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ def test_write_and_delete(self):
data = io.BytesIO(b"abcdefghijk")
fobj = storage.write("test-file-1", data)

aws_config = Configuration.aws_config()

# Assert the link created is as expected
link = storage.get_link(fobj)
assert (
link
== f"{os.environ[Configuration.AWS_S3_ENDPOINT_URL]}/{storage._bucket_name}/test-file-1"
)
assert link == f"{aws_config.endpoint_url}/{aws_config.bucket_name}/test-file-1"

# Link should work for downloads, without auth
response = requests.get(link)
Expand Down
20 changes: 13 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ passenv =
SIMPLIFIED_*
CI
setenv =
docker: SIMPLIFIED_TEST_DATABASE=postgresql://simplified_test:test@localhost:9015/simplified_registry_test
docker: SIMPLIFIED_TEST_DATABASE_SCHEME=postgresql
docker: SIMPLIFIED_TEST_DATABASE_USER=palace
docker: SIMPLIFIED_TEST_DATABASE_PASSWORD=test
docker: AWS_ACCESS_KEY_ID=TEST
docker: AWS_SECRET_ACCESS_KEY=testpassword
docker: SIMPLIFIED_AWS_S3_ENDPOINT_URL=http://localhost:9004
docker: SIMPLIFIED_AWS_S3_ENDPOINT_URL_SCHEME=http
docker: SIMPLIFIED_AWS_S3_BUCKET_NAME=registry-tox-test
docker =
docker: db-registry
Expand All @@ -24,10 +26,12 @@ allowlist_externals = poetry
[docker:db-registry]
image = postgis/postgis:16-3.5
environment =
POSTGRES_USER=simplified_test
POSTGRES_USER=palace
POSTGRES_PASSWORD=test
POSTGRES_DB=simplified_registry_test
ports = 9015:5432/tcp
expose =
SIMPLIFIED_TEST_DATABASE_PORT=5432/tcp
host_var =
SIMPLIFIED_TEST_DATABASE_HOST
healthcheck_cmd = pg_isready
healthcheck_interval = 5
healthcheck_retries = 10
Expand All @@ -38,8 +42,10 @@ environment =
MINIO_ACCESS_KEY=TEST
MINIO_SECRET_KEY=testpassword
MINIO_DEFAULT_BUCKETS=registry-tox-test:download
ports =
9004:9000/tcp
expose =
SIMPLIFIED_AWS_S3_ENDPOINT_URL_PORT=9000/tcp
host_var =
SIMPLIFIED_AWS_S3_ENDPOINT_URL_HOST


[gh-actions]
Expand Down

0 comments on commit 8cb3237

Please sign in to comment.