def test_docker_generic_db(): mongo_container = DockerContainer("mongo:latest") mongo_container.with_bind_ports(27017, 27017) with mongo_container: def connect(): return MongoClient("mongodb://{}:{}".format( mongo_container.get_container_host_ip(), mongo_container.get_exposed_port(27017))) 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" }) print(result.inserted_id) cursor = db.restaurants.find({"borough": "Manhattan"}) for document in cursor: print(document)
def test_add_map_entry_override_non_mapping_value(): code_dir = Path(__file__).parent container = DockerContainer("nginx:latest", something='initial-value-is-not-a-map') container._with_map_entry('something', 'is', 'arbitrary') container._with_map_entry('something', 'also', 'arbitrary') container.with_bind_ports(8080, 80) container.with_exposed_ports(8000) container.with_env('test', 'value') container.with_volume_mapping(code_dir, '/code') assert container._kwargs['something'] == { 'also': 'arbitrary', 'is': 'arbitrary' } assert container._kwargs['ports'] == {8000: None, 8080: 80} assert container._kwargs['environment'] == {'test': 'value'} assert container._kwargs['volumes'] == { code_dir: { 'bind': '/code', 'mode': 'ro' } }