Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: testcontainers/testcontainers-python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: testcontainers-v4.3.0
Choose a base ref
...
head repository: testcontainers/testcontainers-python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: testcontainers-v4.3.1
Choose a head ref
  • 3 commits
  • 6 files changed
  • 3 contributors

Commits on Apr 2, 2024

  1. fix: Pin MongoDB images and improve test coverage for maintained vers…

    …ions (#448)
    
    for some reason this causes an issue, see #401 for details
    
    ---------
    
    Co-authored-by: Vemund Santi <vemund@santi.no>
    alexanderankin and santi authored Apr 2, 2024

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    b5c7a1b View commit details
  2. fix(core): env vars not being respected due to constructor call (#524)

    fix #521
    alexanderankin authored Apr 2, 2024

    Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    4872ea5 View commit details
  3. chore(main): release testcontainers 4.3.1 (#522)

    🤖 I have created a release *beep* *boop*
    ---
    
    
    ##
    [4.3.1](testcontainers-v4.3.0...testcontainers-v4.3.1)
    (2024-04-02)
    
    
    ### Bug Fixes
    
    * **core:** env vars not being respected due to constructor call
    ([#524](#524))
    ([4872ea5](4872ea5)),
    closes
    [#521](#521)
    * Pin MongoDB images and improve test coverage for maintained versions
    ([#448](#448))
    ([b5c7a1b](b5c7a1b))
    
    ---
    This PR was generated with [Release
    Please](https://github.com/googleapis/release-please). See
    [documentation](https://github.com/googleapis/release-please#release-please).
    
    Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
    github-actions[bot] authored Apr 2, 2024
    Copy the full SHA
    0fb4aef View commit details
2 changes: 1 addition & 1 deletion .github/.release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.3.0"
".": "4.3.1"
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## [4.3.1](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.3.0...testcontainers-v4.3.1) (2024-04-02)


### Bug Fixes

* **core:** env vars not being respected due to constructor call ([#524](https://github.com/testcontainers/testcontainers-python/issues/524)) ([4872ea5](https://github.com/testcontainers/testcontainers-python/commit/4872ea5759347e10150c0d80e4e7bbce3d59c410)), closes [#521](https://github.com/testcontainers/testcontainers-python/issues/521)
* Pin MongoDB images and improve test coverage for maintained versions ([#448](https://github.com/testcontainers/testcontainers-python/issues/448)) ([b5c7a1b](https://github.com/testcontainers/testcontainers-python/commit/b5c7a1b95af5470ee1b5109ed1fb8e1b3af52cf7))

## [4.3.0](https://github.com/testcontainers/testcontainers-python/compare/testcontainers-v4.2.0...testcontainers-v4.3.0) (2024-04-01)


3 changes: 2 additions & 1 deletion core/testcontainers/core/docker_client.py
Original file line number Diff line number Diff line change
@@ -41,7 +41,8 @@ def __init__(self, **kwargs) -> None:

if docker_host:
LOGGER.info(f"using host {docker_host}")
self.client = docker.DockerClient(base_url=docker_host)
os.environ["DOCKER_HOST"] = docker_host
self.client = docker.from_env(**kwargs)
else:
self.client = docker.from_env(**kwargs)
self.client.api.headers["x-tc-sid"] = SESSION_ID
23 changes: 9 additions & 14 deletions modules/mongodb/testcontainers/mongodb/__init__.py
Original file line number Diff line number Diff line change
@@ -30,25 +30,20 @@ class MongoDbContainer(DbContainer):
>>> from testcontainers.mongodb import MongoDbContainer
>>> with MongoDbContainer("mongo:latest") as mongo:
>>> with MongoDbContainer("mongo:7.0.7") as mongo:
... db = mongo.get_connection_client().test
... # Insert a database entry
... result = db.restaurants.insert_one(
... {
... "address": {
... "street": "2 Avenue",
... "zipcode": "10075",
... "building": "1480",
... "coord": [-73.9557413, 40.7720266]
... },
... "borough": "Manhattan",
... "cuisine": "Italian",
... "name": "Vella",
... "restaurant_id": "41704620"
... "cuisine": "Italian",
... "restaurant_id": "123456"
... }
... )
... # Find the restaurant document
... cursor = db.restaurants.find({"borough": "Manhattan"})
... result = db.restaurants.find_one({"name": "Vella"})
... result["restaurant_id"]
'123456'
"""

def __init__(
@@ -62,9 +57,9 @@ def __init__(
) -> None:
raise_for_deprecated_parameter(kwargs, "port_to_expose", "port")
super().__init__(image=image, **kwargs)
self.username = username or os.environ.get("MONGO_INITDB_ROOT_USERNAME", "test")
self.password = password or os.environ.get("MONGO_INITDB_ROOT_PASSWORD", "test")
self.dbname = dbname or os.environ.get("MONGO_DB", "test")
self.username = username if username else os.environ.get("MONGO_INITDB_ROOT_USERNAME", "test")
self.password = password if password else os.environ.get("MONGO_INITDB_ROOT_PASSWORD", "test")
self.dbname = dbname if dbname else os.environ.get("MONGO_DB", "test")
self.port = port
self.with_exposed_ports(self.port)

48 changes: 6 additions & 42 deletions modules/mongodb/tests/test_mongodb.py
Original file line number Diff line number Diff line change
@@ -2,42 +2,12 @@
from pymongo import MongoClient
from pymongo.errors import OperationFailure

from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_for
from testcontainers.mongodb import MongoDbContainer


def test_docker_generic_db():
with DockerContainer("mongo:latest").with_bind_ports(27017, 27017) as mongo_container:

def connect():
host = mongo_container.get_container_host_ip()
port = mongo_container.get_exposed_port(27017)
return MongoClient(f"mongodb://{host}:{port}")

db = wait_for(connect).primer
result = db.restaurants.insert_one(
{
"address": {
"street": "2 Avenue",
"zipcode": "10075",
"building": "1480",
"coord": [-73.9557413, 40.7720266],
},
"borough": "Manhattan",
"cuisine": "Italian",
"name": "Vella",
"restaurant_id": "41704620",
}
)
assert result.inserted_id
cursor = db.restaurants.find({"borough": "Manhattan"})
for document in cursor:
assert document


def test_docker_run_mongodb():
with MongoDbContainer("mongo:latest") as mongo:
@pytest.mark.parametrize("version", ["7.0.7", "6.0.14", "5.0.26"])
def test_docker_run_mongodb(version: str):
with MongoDbContainer(f"mongo:{version}") as mongo:
db = mongo.get_connection_client().test
doc = {
"address": {
@@ -51,14 +21,8 @@ def test_docker_run_mongodb():
"name": "Vella",
"restaurant_id": "41704620",
}
db.restaurants.insert_one(doc)
result = db.restaurants.insert_one(doc)
assert result.inserted_id

cursor = db.restaurants.find({"borough": "Manhattan"})
assert cursor.next()["restaurant_id"] == doc["restaurant_id"]


def test_docker_run_mongodb_connect_without_credentials():
with MongoDbContainer() as mongo:
connection_url = f"mongodb://{mongo.get_container_host_ip()}:" f"{mongo.get_exposed_port(mongo.port)}"
db = MongoClient(connection_url).test
with pytest.raises(OperationFailure):
db.restaurants.insert_one({})
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "testcontainers"
version = "4.3.0" # auto-incremented by release-please
version = "4.3.1" # auto-incremented by release-please
description = "Python library for throwaway instances of anything that can run in a Docker container"
authors = ["Sergey Pirogov <automationremarks@gmail.com>"]
maintainers = [