def test___init__(self): source = relations_psycopg2.Source("unit", "init", connection="corkneckshurn") self.assertFalse(source.created) self.assertEqual(source.name, "unit") self.assertEqual(source.database, "init") self.assertIsNone(source.schema) self.assertEqual(source.connection, "corkneckshurn") self.assertEqual(relations.SOURCES["unit"], source) source = relations_psycopg2.Source("test", "init", schema="private", extra="stuff") self.assertTrue(source.created) self.assertEqual(source.name, "test") self.assertEqual(source.database, "init") self.assertEqual(source.schema, "private") self.assertEqual(source.connection, psycopg2.connect.return_value) self.assertEqual(relations.SOURCES["test"], source) psycopg2.connect.assert_called_once_with( cursor_factory=psycopg2.extras.RealDictCursor, dbname="init", extra="stuff")
def test___del__(self): source = relations_psycopg2.Source("test", "init", schema="private", extra="stuff") source.connection = None del relations.SOURCES["test"] psycopg2.connect.return_value.close.assert_not_called() relations_psycopg2.Source("test", "init", schema="private", extra="stuff") del relations.SOURCES["test"] psycopg2.connect.return_value.close.assert_called_once_with()
def setUp(self): self.connection = psycopg2.connect( user="******", host=os.environ["POSTGRES_HOST"], port=int(os.environ["POSTGRES_PORT"]), cursor_factory=psycopg2.extras.RealDictCursor) self.connection.autocommit = True cursor = self.connection.cursor() cursor.execute('DROP DATABASE IF EXISTS "test_source"') cursor.execute('CREATE DATABASE "test_source"') self.source = relations_psycopg2.Source( "PsycoPg2Source", "test_source", schema="test_source", user="******", host=os.environ["POSTGRES_HOST"], port=int(os.environ["POSTGRES_PORT"])) self.source.connection.cursor().execute('CREATE SCHEMA "test_source"') shutil.rmtree("ddl", ignore_errors=True) os.makedirs("ddl", exist_ok=True)
def setUp(self): self.connection = psycopg2.connect( user="******", host=os.environ["POSTGRES_HOST"], port=int(os.environ["POSTGRES_PORT"]), cursor_factory=psycopg2.extras.RealDictCursor ) self.connection.autocommit = True cursor = self.connection.cursor() cursor.execute('DROP DATABASE IF EXISTS "test_source"') cursor.execute('CREATE DATABASE "test_source"') self.source = relations_psycopg2.Source( "PsycoPg2Source", "test_source", user="******", host=os.environ["POSTGRES_HOST"], port=int(os.environ["POSTGRES_PORT"]) )