Skip to content

Mark redundant classes and methods as deprecated. #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions testcontainers/core/container.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from deprecation import deprecated
from docker.models.containers import Container

from testcontainers.core.docker_client import DockerClient
Expand All @@ -8,7 +9,7 @@


class DockerContainer(object):
def __init__(self, image, **kargs):
def __init__(self, image, **kwargs):
self.env = {}
self.ports = {}
self.volumes = {}
Expand All @@ -17,7 +18,7 @@ def __init__(self, image, **kargs):
self._container = None
self._command = None
self._name = None
self._kargs = kargs
self._kwargs = kwargs

def with_env(self, key: str, value: str) -> 'DockerContainer':
self.env[key] = value
Expand All @@ -33,8 +34,12 @@ def with_exposed_ports(self, *ports) -> 'DockerContainer':
self.ports[port] = None
return self

@deprecated(details='Use `with_kwargs`.')
def with_kargs(self, **kargs) -> 'DockerContainer':
self._kargs = kargs
return self.with_kwargs(**kargs)

def with_kwargs(self, **kwargs) -> 'DockerContainer':
self._kwargs = kwargs
return self

def start(self):
Expand All @@ -47,7 +52,7 @@ def start(self):
ports=self.ports,
name=self._name,
volumes=self.volumes,
**self._kargs
**self._kwargs
)
logger.info("Container started: %s", self._container.short_id)
return self
Expand Down
2 changes: 1 addition & 1 deletion testcontainers/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def _configure(self):


class GenericContainer(DockerContainer):
@deprecated(details="use plain DockerContainer instead")
@deprecated(details="Use `DockerContainer`.")
def __init__(self, image):
super(GenericContainer, self).__init__(image)
4 changes: 3 additions & 1 deletion testcontainers/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from deprecation import deprecated
from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_container_is_ready
import urllib
Expand Down Expand Up @@ -51,4 +52,5 @@ def start(self):
return self


ElasticsearchContainer = ElasticSearchContainer
ElasticsearchContainer = deprecated(details='Use `ElasticSearchContainer` with a capital S instead '
'of `ElasticsearchContainer`.')(ElasticSearchContainer)
2 changes: 1 addition & 1 deletion testcontainers/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


class TestContainer(DockerContainer):
@deprecated(details="use plain DockerContainer instead")
@deprecated(details="Use `DockerContainer`.")
def __init__(self, image, port_to_expose=None):
super(TestContainer, self).__init__(image)
if port_to_expose:
Expand Down
4 changes: 2 additions & 2 deletions testcontainers/google/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
# License for the specific language governing permissions and limitations
# under the License.

from ..core.generic import GenericContainer
from ..core.container import DockerContainer


class PubSubContainer(GenericContainer):
class PubSubContainer(DockerContainer):
"""
PubSub container for testing managed message queues.

Expand Down
2 changes: 2 additions & 0 deletions testcontainers/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from deprecation import deprecated
from os import environ

from testcontainers.core.generic import DbContainer
Expand Down Expand Up @@ -81,5 +82,6 @@ class MariaDbContainer(MySqlContainer):
e = sqlalchemy.create_engine(mariadb.get_connection_url())
result = e.execute("select version()")
"""
@deprecated(details="Use `MySqlContainer` with 'mariadb:latest' image.")
def __init__(self, image="mariadb:latest", **kwargs):
super(MariaDbContainer, self).__init__(image, **kwargs)
6 changes: 4 additions & 2 deletions testcontainers/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from testcontainers.core.generic import GenericContainer
from deprecation import deprecated
from testcontainers.core.container import DockerContainer


class NginxContainer(GenericContainer):
class NginxContainer(DockerContainer):
@deprecated(details="Use `DockerContainer` with 'nginx:latest' image and expose port 80.")
def __init__(self, image="nginx:latest", port_to_expose=80):
super(NginxContainer, self).__init__(image)
self.port_to_expose = port_to_expose
Expand Down
11 changes: 5 additions & 6 deletions tests/test_db_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from pymongo import MongoClient
from pymongo.errors import OperationFailure

from testcontainers.core.generic import GenericContainer
from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_for
from testcontainers.mongodb import MongoDbContainer
from testcontainers.mssql import SqlServerContainer
from testcontainers.mysql import MySqlContainer, MariaDbContainer
from testcontainers.mysql import MySqlContainer
from testcontainers.neo4j import Neo4jContainer
from testcontainers.oracle import OracleDbContainer
from testcontainers.postgres import PostgresContainer
Expand All @@ -32,7 +32,7 @@ def test_docker_run_postgress():


def test_docker_run_mariadb():
mariadb_container = MariaDbContainer("mariadb:10.2.9")
mariadb_container = MySqlContainer("mariadb:10.2.9")
with mariadb_container as mariadb:
e = sqlalchemy.create_engine(mariadb.get_connection_url())
result = e.execute("select version()")
Expand Down Expand Up @@ -76,8 +76,7 @@ def test_docker_run_mongodb():


def test_docker_run_mongodb_connect_without_credentials():
mongo_container = MongoDbContainer()
with mongo_container as mongo:
with MongoDbContainer() as mongo:
connection_url = "mongodb://{}:{}".format(mongo.get_container_host_ip(),
mongo.get_exposed_port(mongo.port_to_expose))
db = MongoClient(connection_url).test
Expand Down Expand Up @@ -120,7 +119,7 @@ def test_docker_run_neo4j_latest():


def test_docker_generic_db():
mongo_container = GenericContainer("mongo:latest")
mongo_container = DockerContainer("mongo:latest")
mongo_container.with_bind_ports(27017, 27017)

with mongo_container:
Expand Down
5 changes: 2 additions & 3 deletions tests/test_elasticsearch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import json
import urllib

from testcontainers.elasticsearch import ElasticsearchContainer
from testcontainers.elasticsearch import ElasticSearchContainer


def test_docker_run_elasticsearch():
config = ElasticsearchContainer()
with config as es:
with ElasticSearchContainer() as es:
resp = urllib.request.urlopen(es.get_url())
assert json.loads(resp.read().decode())['version']['number'] == '7.5.0'
12 changes: 6 additions & 6 deletions tests/test_new_docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from testcontainers import mysql

from testcontainers.core.generic import GenericContainer
from testcontainers.core.container import DockerContainer
from importlib import reload


Expand All @@ -14,7 +14,7 @@ def setup_module(m):


def test_docker_custom_image():
container = GenericContainer("mysql:5.7.17")
container = DockerContainer("mysql:5.7.17")
container.with_exposed_ports(3306)
container.with_env("MYSQL_ROOT_PASSWORD", "root")

Expand All @@ -34,15 +34,15 @@ def test_docker_env_variables():
assert re.match(pattern, url)


def test_docker_kargs():
def test_docker_kwargs():
code_dir = Path(__file__).parent
container_first = GenericContainer("nginx:latest")
container_first = DockerContainer("nginx:latest")
container_first.with_volume_mapping(code_dir, '/code')

container_second = GenericContainer("nginx:latest")
container_second = DockerContainer("nginx:latest")

with container_first:
container_second.with_kargs(volumes_from=[container_first._container.short_id])
container_second.with_kwargs(volumes_from=[container_first._container.short_id])
with container_second:
files_first = container_first.exec('ls /code').output.decode('utf-8').strip()
files_second = container_second.exec('ls /code').output.decode('utf-8').strip()
Expand Down