Beispiel #1
0
    def test_setup_skeleton(self):
        database_import.setup_database_skeleton(f'dbname={self.DBNAME}')

        # Check that all extensions are set up.
        with self.conn() as conn:
            with conn.cursor() as cur:
                cur.execute(
                    'CREATE TABLE t (h HSTORE, geom GEOMETRY(Geometry, 4326))')
def test_setup_skeleton(src_dir, nonexistant_db, no_partitions):
    database_import.setup_database_skeleton('dbname=' + nonexistant_db,
                                            src_dir / 'data', no_partitions)

    conn = psycopg2.connect(database=nonexistant_db)

    try:
        with conn.cursor() as cur:
            cur.execute("SELECT distinct partition FROM country_name")
            partitions = set([r[0] for r in list(cur)])
            if no_partitions:
                assert partitions == set([0])
            else:
                assert len(partitions) > 10
    finally:
        conn.close()
Beispiel #3
0
def test_setup_skeleton_already_exists(temp_db):
    with pytest.raises(UsageError):
        database_import.setup_database_skeleton(f'dbname={temp_db}')
Beispiel #4
0
    def test_setup_extensions_old_postgis(self, monkeypatch):
        monkeypatch.setattr(database_import, 'POSTGIS_REQUIRED_VERSION',
                            (50, 50))

        with pytest.raises(UsageError, match='PostGIS is too old.'):
            database_import.setup_database_skeleton(f'dbname={self.DBNAME}')
Beispiel #5
0
 def test_create_db_missing_ro_user(self):
     with pytest.raises(UsageError, match='Missing read-only user.'):
         database_import.setup_database_skeleton(
             f'dbname={self.DBNAME}', rouser='******')
Beispiel #6
0
    def test_unsupported_pg_version(self, monkeypatch):
        monkeypatch.setattr(database_import, 'POSTGRESQL_REQUIRED_VERSION',
                            (100, 4))

        with pytest.raises(UsageError, match='PostgreSQL server is too old.'):
            database_import.setup_database_skeleton(f'dbname={self.DBNAME}')
Beispiel #7
0
 def test_create_db_explicit_ro_user(self):
     database_import.setup_database_skeleton(f'dbname={self.DBNAME}',
                                             rouser='******')