| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 904c5bc commit 508abe9
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,16 +1,14 @@ | |||
| 1 | - import logging | ||
| 2 | - | ||
| 3 | 1 | import crayons | |
| 4 | 2 | ||
| 5 | 3 | from testcontainers.core.docker_client import DockerClient | |
| 6 | 4 | ||
| 7 | 5 | ||
| 8 | 6 | class DockerContainer(object): | |
| 9 | - def __init__(self, image, version): | ||
| 7 | + def __init__(self, image): | ||
| 10 | 8 | self.env = {} | |
| 11 | 9 | self.ports = {} | |
| 12 | 10 | self._docker = DockerClient() | |
| 13 | - self.image = "{}:{}".format(image, version) | ||
| 11 | + self.image = image | ||
| 14 | 12 | self._container = None | |
| 15 | 13 | ||
| 16 | 14 | def add_env(self, key, value): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,13 +17,12 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | class DbContainer(DockerContainer): | |
| 20 | - def __init__(self, image, version, dialect, | ||
| 20 | + def __init__(self, image, dialect, | ||
| 21 | 21 | username, | |
| 22 | 22 | password, | |
| 23 | 23 | port, | |
| 24 | 24 | db_name): | |
| 25 | - super(DbContainer, self).__init__(image, | ||
| 26 | - version) | ||
| 25 | + super(DbContainer, self).__init__(image) | ||
| 27 | 26 | self.dialect = dialect | |
| 28 | 27 | self.username = username | |
| 29 | 28 | self.password = password | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,9 +14,8 @@ | |||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | 16 | class MySqlContainer(DbContainer): | |
| 17 | - def __init__(self, image="mysql", version="latest"): | ||
| 17 | + def __init__(self, image="mysql:latest"): | ||
| 18 | 18 | super(MySqlContainer, self).__init__(image, | |
| 19 | - version, | ||
| 20 | 19 | dialect="mysql+pymysql", | |
| 21 | 20 | username="test", | |
| 22 | 21 | password="test", | |
@@ -33,5 +32,5 @@ def _configure(self): | |||
| 33 | 32 | ||
| 34 | 33 | ||
| 35 | 34 | class MariaDbContainer(MySqlContainer): | |
| 36 | - def __init__(self, image="mariadb", version="latest"): | ||
| 37 | - super(MariaDbContainer, self).__init__(image, version) | ||
| 35 | + def __init__(self, image="mariadb:latest"): | ||
| 36 | + super(MariaDbContainer, self).__init__(image) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,9 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | class OracleDbContainer(DbContainer): | |
| 5 | - def __init__(self, image="wnameless/oracle-xe-11g", version="latest"): | ||
| 5 | + def __init__(self, image="wnameless/oracle-xe-11g:latest"): | ||
| 6 | 6 | super(OracleDbContainer, self).__init__(image=image, | |
| 7 | - version=version, | ||
| 8 | 7 | username="system", | |
| 9 | 8 | password="oracle", | |
| 10 | 9 | db_name="xe", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,9 +15,8 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | class PostgresContainer(DbContainer): | |
| 18 | - def __init__(self, image="postgres", version="latest"): | ||
| 18 | + def __init__(self, image="postgres:latest"): | ||
| 19 | 19 | super(PostgresContainer, self).__init__(image=image, | |
| 20 | - version=version, | ||
| 21 | 20 | dialect="postgresql+psycopg2", | |
| 22 | 21 | username="test", | |
| 23 | 22 | password="test", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,8 +17,8 @@ | |||
| 17 | 17 | from testcontainers.core.waiting_utils import wait_container_is_ready | |
| 18 | 18 | ||
| 19 | 19 | IMAGES = { | |
| 20 | - "firefox": "selenium/standalone-firefox-debug", | ||
| 21 | - "chrome": "selenium/standalone-chrome-debug" | ||
| 20 | + "firefox": "selenium/standalone-firefox-debug:latest", | ||
| 21 | + "chrome": "selenium/standalone-chrome-debug:latest" | ||
| 22 | 22 | } | |
| 23 | 23 | ||
| 24 | 24 | ||
@@ -27,13 +27,13 @@ def get_image_name(capabilities): | |||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 | class BrowserWebDriverContainer(DockerContainer): | |
| 30 | - | ||
| 31 | - def __init__(self, capabilities, version="latest"): | ||
| 30 | + def __init__(self, capabilities, image=None): | ||
| 32 | 31 | self.capabilities = capabilities | |
| 33 | - self.image = get_image_name(capabilities) | ||
| 32 | + if not image: | ||
| 33 | + self.image = get_image_name(capabilities) | ||
| 34 | 34 | self.host_port = 4444 | |
| 35 | 35 | self.host_vnc_port = 5900 | |
| 36 | - super(BrowserWebDriverContainer, self).__init__(image=self.image, version=version) | ||
| 36 | + super(BrowserWebDriverContainer, self).__init__(image=self.image) | ||
| 37 | 37 | ||
| 38 | 38 | def _configure(self): | |
| 39 | 39 | self.add_env("no_proxy", "localhost") | |
@@ -47,10 +47,16 @@ def _connect(self): | |||
| 47 | 47 | command_executor=(self.get_connection_url()), | |
| 48 | 48 | desired_capabilities=self.capabilities) | |
| 49 | 49 | ||
| 50 | - def get_driver(self) -> WebDriver: | ||
| 51 | - return self._connect() | ||
| 50 | + def get_driver(self) -> | ||
| 51 | + | ||
| 52 | + WebDriver: | ||
| 53 | + return self._connect() | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + def get_connection_url(self) -> | ||
| 57 | + | ||
| 52 | 58 | ||
| 53 | - def get_connection_url(self) -> str: | ||
| 54 | - ip = self.get_container_host_ip() | ||
| 55 | - port = self.get_exposed_port(self.host_port) | ||
| 56 | - return 'http://{}:{}/wd/hub'.format(ip, port) | ||
| 59 | + str: | ||
| 60 | + ip = self.get_container_host_ip() | ||
| 61 | + port = self.get_exposed_port(self.host_port) | ||
| 62 | + return 'http://{}:{}/wd/hub'.format(ip, port) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | def test_docker_run_mysql(): | |
| 11 | - config = MySqlContainer(version='5.7.17') | ||
| 11 | + config = MySqlContainer('mysql:5.7.17') | ||
| 12 | 12 | with config as mysql: | |
| 13 | 13 | e = sqlalchemy.create_engine(mysql.get_connection_url()) | |
| 14 | 14 | result = e.execute("select version()") | |
@@ -17,7 +17,7 @@ def test_docker_run_mysql(): | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | def test_docker_run_postgress(): | |
| 20 | - postgres_container = PostgresContainer(version="9.5") | ||
| 20 | + postgres_container = PostgresContainer("postgres:9.5") | ||
| 21 | 21 | with postgres_container as postgres: | |
| 22 | 22 | e = sqlalchemy.create_engine(postgres.get_connection_url()) | |
| 23 | 23 | result = e.execute("select version()") | |
@@ -27,7 +27,7 @@ def test_docker_run_postgress(): | |||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | 29 | def test_docker_run_mariadb(): | |
| 30 | - mariadb_container = MariaDbContainer() | ||
| 30 | + mariadb_container = MariaDbContainer("mariadb:latest") | ||
| 31 | 31 | with mariadb_container as mariadb: | |
| 32 | 32 | e = sqlalchemy.create_engine(mariadb.get_connection_url()) | |
| 33 | 33 | result = e.execute("select version()") | |
@@ -36,7 +36,7 @@ def test_docker_run_mariadb(): | |||
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | 38 | def test_docker_generic_db(): | |
| 39 | - mongo_container = DockerContainer("mongo", "latest") | ||
| 39 | + mongo_container = DockerContainer("mongo:latest") | ||
| 40 | 40 | mongo_container.expose_port(27017, 27017) | |
| 41 | 41 | ||
| 42 | 42 | with mongo_container: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments