Skip to content

Commit 9bbb514

Browse files
authored
Merge branch 'main' into ports_refactor
2 parents 08c7908 + f7922d7 commit 9bbb514

File tree

6 files changed

+38
-48
lines changed

6 files changed

+38
-48
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "4.8.1"
2+
".": "4.8.2"
33
}

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [4.8.2](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.8.1...testcontainers-v4.8.2) (2024-09-27)
4+
5+
6+
### Bug Fixes
7+
8+
* **core:** Reorganize core tests and improve ([#693](https://github.com/testcontainers/testcontainers-python/issues/693)) ([f1665f3](https://github.com/testcontainers/testcontainers-python/commit/f1665f3aa66eff443923d897ec553e09e47f6a78))
9+
* **core:** Typing in auth ([#691](https://github.com/testcontainers/testcontainers-python/issues/691)) ([66726b6](https://github.com/testcontainers/testcontainers-python/commit/66726b656ab8fd18a69771ff2ee2a3fd8ca959b0))
10+
* **core:** Typing in config + utils ([#692](https://github.com/testcontainers/testcontainers-python/issues/692)) ([794a22e](https://github.com/testcontainers/testcontainers-python/commit/794a22e22362227ccfc0b2acd18130196e25775d))
11+
* **keycloak:** Add support for Keycloak version >=25 ([#694](https://github.com/testcontainers/testcontainers-python/issues/694)) ([62bd0de](https://github.com/testcontainers/testcontainers-python/commit/62bd0debffdb762714de853a069e3b63414fa789))
12+
* mysql typo ([#705](https://github.com/testcontainers/testcontainers-python/issues/705)) ([85d6078](https://github.com/testcontainers/testcontainers-python/commit/85d6078f9bcc99050c0173e459208402aa4f5026)), closes [#689](https://github.com/testcontainers/testcontainers-python/issues/689)
13+
* **opensearch:** add support for admin_password in >= 2.12 ([#697](https://github.com/testcontainers/testcontainers-python/issues/697)) ([935693e](https://github.com/testcontainers/testcontainers-python/commit/935693e01686fea9bf3201cd8c70b3e617bda2ee))
14+
* postgres use psql instead of logs ([#704](https://github.com/testcontainers/testcontainers-python/issues/704)) ([4365754](https://github.com/testcontainers/testcontainers-python/commit/436575410a2906a695b96af66ff55c9ccb8e09a7))
15+
* **tests:** Missing artifacts (include-hidden-files) ([#699](https://github.com/testcontainers/testcontainers-python/issues/699)) ([8f1165d](https://github.com/testcontainers/testcontainers-python/commit/8f1165dd79ee0dcf16f37f2d186cbc3d47bc11bc))
16+
317
## [4.8.1](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.8.0...testcontainers-v4.8.1) (2024-08-18)
418

519

modules/mysql/testcontainers/mysql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class MySqlContainer(DbContainer):
4646
4747
The optional :code:`seed` parameter enables arbitrary SQL files to be loaded.
4848
This is perfect for schema and sample data. This works by mounting the seed to
49-
`/docker-entrypoint-initdb./d`, which containerized MySQL are set up to load
49+
`/docker-entrypoint-initdb.d/`, which containerized MySQL are set up to load
5050
automatically.
5151
5252
.. doctest::

modules/postgres/testcontainers/postgres/__init__.py

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
1313
import os
14-
from time import sleep
1514
from typing import Optional
1615

17-
from testcontainers.core.config import testcontainers_config as c
1816
from testcontainers.core.generic import DbContainer
1917
from testcontainers.core.utils import raise_for_deprecated_parameter
20-
from testcontainers.core.waiting_utils import wait_container_is_ready, wait_for_logs
18+
from testcontainers.core.waiting_utils import wait_container_is_ready
2119

2220
_UNSET = object()
2321

@@ -91,45 +89,13 @@ def get_connection_url(self, host: Optional[str] = None, driver: Optional[str] =
9189

9290
@wait_container_is_ready()
9391
def _connect(self) -> None:
94-
# postgres itself logs these messages to the standard error stream:
95-
#
96-
# $ /opt/homebrew/opt/postgresql@14/bin/postgres -D /opt/homebrew/var/postgresql@14 \
97-
# > | grep -o -a -m 1 -h 'database system is ready to accept connections'
98-
# 2024-08-03 00:13:02.799 EDT [70226] LOG: starting PostgreSQL 14.11 (Homebrew) ....
99-
# 2024-08-03 00:13:02.804 EDT [70226] LOG: listening on IPv4 address "127.0.0.1", port 5432
100-
# ...
101-
# ^C2024-08-03 00:13:04.226 EDT [70226] LOG: received fast shutdown request
102-
# ...
103-
#
104-
# $ /opt/homebrew/opt/postgresql@14/bin/postgres -D /opt/homebrew/var/postgresql@14 2>&1 \
105-
# > | grep -o -a -m 1 -h 'database system is ready to accept connections'
106-
# database system is ready to accept connections
107-
#
108-
# and the setup script inside docker library postgres
109-
# uses pg_ctl:
110-
# https://github.com/docker-library/postgres/blob/66da3846b40396249936938ee17e9684e6968a57/16/alpine3.20/docker-entrypoint.sh#L261-L282
111-
# which prints logs to stdout:
112-
# https://www.postgresql.org/docs/current/app-pg-ctl.html#:~:text=the%20server%27s%20standard%20output%20and%20standard%20error%20are%20sent%20to%20pg_ctl%27s%20standard%20output
113-
#
114-
# so we must wait for both the setup and real startup:
115-
predicate_streams_and = True
116-
117-
wait_for_logs(
118-
self,
119-
".*database system is ready to accept connections.*",
120-
c.max_tries,
121-
c.sleep_time,
122-
predicate_streams_and=predicate_streams_and,
123-
#
92+
escaped_single_password = self.password.replace("'", "'\"'\"'")
93+
result = self.exec(
94+
[
95+
"sh",
96+
"-c",
97+
f"PGPASSWORD='{escaped_single_password}' psql --username {self.username} --dbname {self.dbname} --host 127.0.0.1 -c 'select version();'",
98+
]
12499
)
125-
126-
count = 0
127-
while count < c.max_tries:
128-
status, _ = self.exec(f"pg_isready -hlocalhost -p{self.port} -U{self.username}")
129-
if status == 0:
130-
return
131-
132-
sleep(c.sleep_time)
133-
count += 1
134-
135-
raise RuntimeError("Postgres could not get into a ready state")
100+
if result.exit_code:
101+
raise ConnectionError("pg_isready is not ready yet")

modules/postgres/tests/test_postgres.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from pathlib import Path
22

33
import pytest
4+
import sqlalchemy
45

56
from testcontainers.postgres import PostgresContainer
6-
import sqlalchemy
77

88

99
# https://www.postgresql.org/support/versioning/
@@ -46,6 +46,16 @@ def test_docker_run_postgres_with_driver_pg8000():
4646
connection.execute(sqlalchemy.text("select 1=1"))
4747

4848

49+
def test_password_with_quotes():
50+
postgres_container = PostgresContainer("postgres:9.5", password="'''''")
51+
with postgres_container as postgres:
52+
engine = sqlalchemy.create_engine(postgres.get_connection_url())
53+
with engine.begin() as connection:
54+
result = connection.execute(sqlalchemy.text("select version()"))
55+
for row in result:
56+
assert row[0].lower().startswith("postgresql 9.5")
57+
58+
4959
# This is a feature in the generic DbContainer class
5060
# but it can't be tested on its own
5161
# so is tested in various database modules:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "testcontainers"
3-
version = "4.8.1" # auto-incremented by release-please
3+
version = "4.8.2" # auto-incremented by release-please
44
description = "Python library for throwaway instances of anything that can run in a Docker container"
55
authors = ["Sergey Pirogov <[email protected]>"]
66
maintainers = [

0 commit comments

Comments
 (0)