Last active
November 6, 2023 15:47
-
-
Save alexanderankin/7b774080707ebc27632a41e8a0430df9 to your computer and use it in GitHub Desktop.
updating the image used in tc-python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.venv/ | |
__pycache__/ | |
.idea/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
python -m venv .venv && . .venv/bin/activate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from unittest import TestCase | |
from testcontainers.core.container import DockerContainer | |
from testcontainers.core.waiting_utils import wait_for_logs | |
class Demo(TestCase): | |
def setUp(self): | |
self.db: DockerContainer = DockerContainer("gvenzl/oracle-xe:21.3.0-slim") \ | |
.with_env("ORACLE_PASSWORD", "password") \ | |
.with_exposed_ports(1521) | |
self.db.start() | |
self.db.get_connection_url = lambda *args, **kwargs: \ | |
f'oracle+oracledb://system:password@localhost:{self.db.get_exposed_port(1521)}/?service_name=XE' | |
wait_for_logs(self.db, '.*DATABASE IS READY TO USE.*', timeout=60) | |
def test_it(self): | |
from sqlalchemy import create_engine, text | |
print(self.db.get_connection_url()) | |
engine = create_engine(self.db.get_connection_url()) | |
con = engine.connect() | |
con.execute(text('create table abc(name varchar(500))')) | |
con.execute(text("insert into abc(name) values('alice')")) | |
for i in con.execute(text('select * from abc')).fetchall(): | |
print(i) | |
con.close() | |
del engine | |
if __name__ == "__main__": | |
import unittest | |
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testcontainers | |
oracledb | |
sqlalchemy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment