Skip to content

Commit c6ae58d

Browse files
mbodeSergeyPirogov
authored andcommitted
Fix OracleDbContainer (#41)
1 parent f76891a commit c6ae58d

File tree

8 files changed

+233
-184
lines changed

8 files changed

+233
-184
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ sqlalchemy = "*"
2121
pymysql = "*"
2222
google-cloud-pubsub = "*"
2323
psycopg2-binary = "*"
24+
cx-oracle = "*"

Pipfile.lock

Lines changed: 193 additions & 169 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Currently available features:
1313
* Selenium Standalone containers
1414
* MySql Db container
1515
* MariaDb container
16+
* OracleDb container
1617
* PostgreSQL Db container
1718
* Generic docker containers
1819

@@ -28,6 +29,7 @@ The **testcontainers** module is available from PyPI at:
2829
and can be installed using ``pip``, depending on which containers you need:
2930

3031
pip install testcontainers[mysql]
32+
pip install testcontainers[oracle]
3133
pip install testcontainers[postgresql]
3234
pip install testcontainers[selenium]
3335
# or with multiple

docs/database.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@ Oracle XE
5454
oracle = OracleDbContainer()
5555

5656
with oracle:
57-
e = sqlalchemy.create_engine(mysql.get_connection_url())
57+
e = sqlalchemy.create_engine(oracle.get_connection_url())
5858
result = e.execute("select 1 from dual")
5959

60-
It uses **https://hub.docker.com/r/wnameless/oracle-xe-11g/** docker image.
60+
It uses **https://hub.docker.com/r/wnameless/oracle-xe-11g-r2/** docker image.
6161

62-
Connection detail for Oracle DB.
62+
Necessary to use it:
6363

64+
- ``cx_Oracle``
65+
- `Oracle client libraries <https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html>`_
66+
=======
6467
::
6568

6669
hostname: localhost
@@ -77,3 +80,4 @@ Elasticsearch
7780
es = ElasticSearchContainer()
7881
with es:
7982
es.get_url() # gives you the http URL to connect to Elasticsearch
83+

docs/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Currently available features:
1212

1313
- Selenim Standalone containers
1414
- MySql db container
15+
- Oracle db container
1516
- PostgreSQL db container
1617
- Google Cloud PubSub emulator container
1718
- Elasticsearch container
@@ -28,6 +29,7 @@ and can be installed using pip, depending on which containers you need:
2829
::
2930

3031
pip install testcontainers[mysql]
32+
pip install testcontainers[oracle]
3133
pip install testcontainers[postgresql]
3234
pip install testcontainers[selenium]
3335
pip install testcontainers[google-cloud-pubsub]

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
extras_require={
5050
'docker-compose': ['docker-compose'],
5151
'mysql': ['sqlalchemy', 'pymysql'],
52+
'oracle': ['sqlalchemy', 'cx_Oracle'],
5253
'postgresql': ['sqlalchemy', 'psycopg2-binary'],
5354
'selenium': ['selenium==2.53.1'],
5455
'google-cloud-pubsub': ['google-cloud-pubsub'],

testcontainers/oracle.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33

44
class OracleDbContainer(DbContainer):
5-
def __init__(self, image="wnameless/oracle-xe-11g:latest"):
6-
super(OracleDbContainer, self).__init__(image=image,
7-
username="system",
8-
password="oracle",
9-
db_name="xe",
10-
dialect="oracle",
11-
port=1521)
12-
self.host_port = 49161
5+
def __init__(self, image="wnameless/oracle-xe-11g-r2:latest"):
6+
super(OracleDbContainer, self).__init__(image=image)
137
self.container_port = 1521
14-
self.host_ssh_port = 49160
15-
self.container_ssh_port = 22
16-
self.dialect = "oracle"
8+
self.with_exposed_ports(self.container_port)
179

1810
def _configure(self):
1911
self.with_env("ORACLE_ALLOW_REMOTE", "true")
12+
13+
def get_connection_url(self):
14+
return super()._create_connection_url(dialect="oracle",
15+
username="system",
16+
password="oracle",
17+
port=self.container_port,
18+
db_name="xe")

tests/test_db_containers.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import pytest
12
import sqlalchemy
23
from pymongo import MongoClient
34

45
from testcontainers.core.generic import GenericContainer
5-
from testcontainers.core.waiting_utils import wait_for
6+
from testcontainers.core.waiting_utils import wait_for
67
from testcontainers.mysql import MySqlContainer, MariaDbContainer
8+
from testcontainers.oracle import OracleDbContainer
79
from testcontainers.postgres import PostgresContainer
810

911

@@ -34,6 +36,20 @@ def test_docker_run_mariadb():
3436
assert row[0] == '10.2.9-MariaDB-10.2.9+maria~jessie'
3537

3638

39+
@pytest.mark.skip(reason="needs oracle client libraries unavailable on Travis")
40+
def test_docker_run_oracle():
41+
oracledb_container = OracleDbContainer()
42+
with oracledb_container as oracledb:
43+
e = sqlalchemy.create_engine(oracledb.get_connection_url())
44+
result = e.execute("select * from V$VERSION")
45+
versions = {'Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production',
46+
'PL/SQL Release 11.2.0.2.0 - Production',
47+
'CORE\t11.2.0.2.0\tProduction',
48+
'TNS for Linux: Version 11.2.0.2.0 - Production',
49+
'NLSRTL Version 11.2.0.2.0 - Production'}
50+
assert {row[0] for row in result} == versions
51+
52+
3753
def test_docker_generic_db():
3854
mongo_container = GenericContainer("mongo:latest")
3955
mongo_container.with_bind_ports(27017, 27017)

0 commit comments

Comments
 (0)