|  | 
|  | 1 | +import pytest | 
|  | 2 | +import sqlalchemy | 
|  | 3 | + | 
|  | 4 | +from testcontainers.core.utils import is_arm | 
|  | 5 | +from testcontainers.oracle import OracleDbContainer | 
|  | 6 | + | 
|  | 7 | + | 
|  | 8 | +@pytest.mark.skipif(is_arm(), reason="oracle-free container not available for ARM") | 
|  | 9 | +def test_docker_run_oracle_with_system_password(): | 
|  | 10 | +    with OracleDbContainer(oracle_password="test") as oracledb: | 
|  | 11 | +        engine = sqlalchemy.create_engine(oracledb.get_connection_url()) | 
|  | 12 | +        with engine.begin() as connection: | 
|  | 13 | +            test_val = 1 | 
|  | 14 | +            result = connection.execute(sqlalchemy.text("SELECT {} FROM dual".format(test_val))) | 
|  | 15 | +            for row in result: | 
|  | 16 | +                assert row[0] == test_val | 
|  | 17 | + | 
|  | 18 | + | 
|  | 19 | +@pytest.mark.skipif(is_arm(), reason="oracle-free container not available for ARM") | 
|  | 20 | +def test_docker_run_oracle_with_username_password(): | 
|  | 21 | +    with OracleDbContainer(username="test", password="test") as oracledb: | 
|  | 22 | +        engine = sqlalchemy.create_engine(oracledb.get_connection_url()) | 
|  | 23 | +        with engine.begin() as connection: | 
|  | 24 | +            test_val = 1 | 
|  | 25 | +            result = connection.execute(sqlalchemy.text("SELECT {} FROM dual".format(test_val))) | 
|  | 26 | +            for row in result: | 
|  | 27 | +                assert row[0] == test_val | 
|  | 28 | + | 
|  | 29 | + | 
|  | 30 | +@pytest.mark.skipif(is_arm(), reason="oracle-free container not available for ARM") | 
|  | 31 | +def test_docker_run_oracle_with_custom_db_and_system_username_password(): | 
|  | 32 | +    with OracleDbContainer(oracle_password="coolpassword", dbname="myTestPDB") as oracledb: | 
|  | 33 | +        engine = sqlalchemy.create_engine(oracledb.get_connection_url()) | 
|  | 34 | +        with engine.begin() as connection: | 
|  | 35 | +            test_val = 1 | 
|  | 36 | +            result = connection.execute(sqlalchemy.text("SELECT {} FROM dual".format(test_val))) | 
|  | 37 | +            for row in result: | 
|  | 38 | +                assert row[0] == test_val | 
|  | 39 | + | 
|  | 40 | + | 
|  | 41 | +@pytest.mark.skipif(is_arm(), reason="oracle-free container not available for ARM") | 
|  | 42 | +def test_docker_run_oracle_with_custom_db_and_app_username_password(): | 
|  | 43 | +    with OracleDbContainer(username="mycooluser", password="123connect", dbname="anotherPDB") as oracledb: | 
|  | 44 | +        engine = sqlalchemy.create_engine(oracledb.get_connection_url()) | 
|  | 45 | +        with engine.begin() as connection: | 
|  | 46 | +            test_val = 1 | 
|  | 47 | +            result = connection.execute(sqlalchemy.text("SELECT {} FROM dual".format(test_val))) | 
|  | 48 | +            for row in result: | 
|  | 49 | +                assert row[0] == test_val | 
|  | 50 | + | 
|  | 51 | + | 
|  | 52 | +@pytest.mark.skipif(is_arm(), reason="oracle-free container not available for ARM") | 
|  | 53 | +def test_docker_run_oracle_with_default_db_and_app_username_password(): | 
|  | 54 | +    with OracleDbContainer(username="mycooluser", password="123connect") as oracledb: | 
|  | 55 | +        engine = sqlalchemy.create_engine(oracledb.get_connection_url()) | 
|  | 56 | +        with engine.begin() as connection: | 
|  | 57 | +            test_val = 1 | 
|  | 58 | +            result = connection.execute(sqlalchemy.text("SELECT {} FROM dual".format(test_val))) | 
|  | 59 | +            for row in result: | 
|  | 60 | +                assert row[0] == test_val | 
|  | 61 | + | 
|  | 62 | + | 
|  | 63 | +@pytest.mark.skipif(is_arm(), reason="oracle-free container not available for ARM") | 
|  | 64 | +def test_docker_run_oracle_with_cdb_and_system_username(): | 
|  | 65 | +    with OracleDbContainer(oracle_password="MyOraclePWD1", dbname="free") as oracledb: | 
|  | 66 | +        engine = sqlalchemy.create_engine(oracledb.get_connection_url()) | 
|  | 67 | +        with engine.begin() as connection: | 
|  | 68 | +            test_val = 1 | 
|  | 69 | +            result = connection.execute(sqlalchemy.text("SELECT {} FROM dual".format(test_val))) | 
|  | 70 | +            for row in result: | 
|  | 71 | +                assert row[0] == test_val | 
|  | 72 | + | 
|  | 73 | + | 
|  | 74 | +@pytest.mark.skipif(is_arm(), reason="oracle-free container not available for ARM") | 
|  | 75 | +def test_doctest(): | 
|  | 76 | +    with OracleDbContainer() as oracle: | 
|  | 77 | +        print(oracle.get_connection_url()) | 
|  | 78 | +        engine = sqlalchemy.create_engine(oracle.get_connection_url()) | 
|  | 79 | +        with engine.begin() as connection: | 
|  | 80 | +            result = connection.execute(sqlalchemy.text("SELECT 1 FROM dual")) | 
|  | 81 | +            assert result.fetchall() == [(1,)] | 
0 commit comments