def test_create_db_missing_ro_user(nonexistant_db):
    with pytest.raises(UsageError, match='Missing read-only user.'):
        database_import.create_db('dbname=' + nonexistant_db,
                                  rouser='******')
def test_create_db_already_exists(temp_db):
    with pytest.raises(UsageError):
        database_import.create_db('dbname=' + temp_db)
def test_create_db_unsupported_version(nonexistant_db, monkeypatch):
    monkeypatch.setattr(database_import, 'POSTGRESQL_REQUIRED_VERSION',
                        (100, 4))

    with pytest.raises(UsageError, match='PostgreSQL server is too old.'):
        database_import.create_db('dbname=' + nonexistant_db)
def test_create_db_success(nonexistant_db):
    database_import.create_db('dbname=' + nonexistant_db, rouser='******')

    conn = psycopg2.connect(database=nonexistant_db)
    conn.close()