Beispiel #1
0
class TestPyEmbedPg(unittest.TestCase):
    def setUp(self):
        self.port = 15433
        self.embedpg = PyEmbedPg('9.4.0')
        self.postgres = self.embedpg.start(self.port)
        self.postgres.create_user('scott', 'tiger')
        self.postgres.create_database('testdb', 'scott')

    def test_simple_run(self):
        # Postgres is initialized, now run some queries
        with psycopg2.connect(database='postgres',
                              user='******',
                              password='******',
                              host='localhost',
                              port=self.port) as conn:
            with conn.cursor() as cursor:
                cursor.execute(
                    'CREATE TABLE employee(name VARCHAR(32), age INT)')
                cursor.execute("INSERT INTO employee VALUES ('John', 32)")
                cursor.execute("INSERT INTO employee VALUES ('Mary', 22)")
                cursor.execute('SELECT * FROM employee ORDER BY age')
                assert cursor.fetchall() == [('Mary', 22), ('John', 32)]

        # Test that the version is installed locally
        assert self.embedpg.get_latest_local_version() is not None

    def tearDown(self):
        self.postgres.shutdown()
Beispiel #2
0
def postgres(request):
    def endup():
        print("Database shutdown")
        pg.shutdown()

    request.addfinalizer(endup)

    pg = PyEmbedPg(POSTGRES_VERSION,
                   config_options='--with-python').start(15432)
    pg.create_database('testdb')

    bin_dir = os.path.dirname(pg._postgres_cmd)
    # add bin dir to path to find the local pg_config
    env = os.environ.copy()
    env['PATH'] = '{}:{}'.format(bin_dir, env['PATH'])

    # install dependencies
    install_postgis(env)
    install_pointcloud(env)
    # install li3ds extension inside temp database
    subprocess.check_output(['make', 'install'], env=env, cwd=EXTENSION_DIR)

    load_extensions(pg)

    return pg
    def __init__(self, *args, **kw):
        if self.db_name is None:
            self.db_name = 'testdb%s' % "%012x" % random.getrandbits(48)

        postgres = PyEmbedPg(self.pg_version)
        runner = postgres.start(self.db_port_range)
        try:
            runner.create_user(self.db_user, self.db_pass)
        except psycopg2.errors.DuplicateObject:
            pass

        self.db_port = runner.running_port

        self.dsn = self.get_dsn(self.db_name)
        self.postgres = runner
    def test_simple_run(self):
        pg = PyEmbedPg('9.4.0')
        with pg.start(self.port) as postgres:
            postgres.create_user('scott', 'tiger')
            postgres.create_database('testdb', 'scott')

            # Postgres is initialized, now run some queries
            with psycopg2.connect(database='postgres', user='******', password='******', host='localhost', port=self.port) as conn:
                with conn.cursor() as cursor:
                    cursor.execute('CREATE TABLE employee(name VARCHAR(32), age INT)')
                    cursor.execute("INSERT INTO employee VALUES ('John', 32)")
                    cursor.execute("INSERT INTO employee VALUES ('Mary', 22)")
                    cursor.execute('SELECT * FROM employee ORDER BY age')
                    assert cursor.fetchall() == [('Mary', 22), ('John', 32)]

        # Test that the version is installed locally
        assert pg.get_latest_local_version() is not None
Beispiel #5
0
def postgres(request):
    def endup():
        print("Database shutdown")
        pg.shutdown()
    request.addfinalizer(endup)

    pg = PyEmbedPg(POSTGRES_VERSION, config_options='--with-python').start(15432)
    pg.create_database('testdb')

    bin_dir = os.path.dirname(pg._postgres_cmd)
    # add bin dir to path to find the local pg_config
    env = os.environ.copy()
    env['PATH'] = '{}:{}'.format(bin_dir, env['PATH'])

    # install dependencies
    install_postgis(env)
    install_pointcloud(env)
    # install li3ds extension inside temp database
    subprocess.check_output(['make', 'install'], env=env, cwd=EXTENSION_DIR)

    load_extensions(pg)

    return pg
 def test_get_remote_version(self):
     pg = PyEmbedPg('test')
     last_version = pg.get_latest_remote_version()
     # can be 9.5.alpha1
     assert re.match('\d+\.[\w\.]+', last_version)
Beispiel #7
0
 def setUp(self):
     self.port = 15433
     self.embedpg = PyEmbedPg('9.4.0')
     self.postgres = self.embedpg.start(self.port)
     self.postgres.create_user('scott', 'tiger')
     self.postgres.create_database('testdb', 'scott')
Beispiel #8
0
 def setUp(self):
     self.port = 15433
     self.embedpg = PyEmbedPg('9.4.0')
     self.postgres = self.embedpg.start(self.port)
     self.postgres.create_user('scott', 'tiger')
     self.postgres.create_database('testdb', 'scott')