Skip to content

Instantly share code, notes, and snippets.

@alexanderankin
Last active November 6, 2023 15:47
Show Gist options
  • Save alexanderankin/7b774080707ebc27632a41e8a0430df9 to your computer and use it in GitHub Desktop.
Save alexanderankin/7b774080707ebc27632a41e8a0430df9 to your computer and use it in GitHub Desktop.
updating the image used in tc-python
.venv/
__pycache__/
.idea/
#!/usr/bin/env bash
python -m venv .venv && . .venv/bin/activate
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()
testcontainers
oracledb
sqlalchemy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment