server/tests-py: Set up postgis extensions using a fixture.

Let's put it in one place.

This is a precursor to moving database provisioning into the Python
integration tests.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5453
GitOrigin-RevId: 5920b0b1177d94496485fcb4e178b946534ee4eb
This commit is contained in:
Samir Talwar 2022-08-15 16:29:02 +02:00 committed by hasura-bot
parent 57025ef3b3
commit a0176c215f
24 changed files with 58 additions and 132 deletions

View File

@ -1,12 +1,15 @@
import pytest
import time
from context import HGECtx, HGECtxError, ActionsWebhookServer, EvtsWebhookServer, HGECtxGQLServer, GQLWsClient, PytestConf, GraphQLWSClient
import threading
import random
from datetime import datetime
import sys
import os
from collections import OrderedDict
from datetime import datetime
import os
import pytest
import random
import re
import sqlalchemy
import sys
import threading
import time
from context import HGECtx, HGECtxError, ActionsWebhookServer, EvtsWebhookServer, HGECtxGQLServer, GQLWsClient, PytestConf, GraphQLWSClient
def pytest_addoption(parser):
parser.addoption(
@ -332,7 +335,16 @@ def per_backend_test_class(request: pytest.FixtureRequest):
def per_backend_test_function(request: pytest.FixtureRequest):
return per_backend_tests_fixture(request)
@pytest.fixture(scope='module')
@pytest.fixture(scope='class')
def postgis(hge_ctx):
with sqlalchemy.create_engine(hge_ctx.pg_url).connect() as connection:
connection.execute('CREATE EXTENSION IF NOT EXISTS postgis')
connection.execute('CREATE EXTENSION IF NOT EXISTS postgis_topology')
postgis_version = connection.execute('SELECT PostGIS_lib_version() as postgis_version').fetchone()['postgis_version']
if re.match('^3\\.', postgis_version):
connection.execute('CREATE EXTENSION IF NOT EXISTS postgis_raster')
@pytest.fixture(scope='class')
def hge_ctx(request):
config = request.config
print("create hge_ctx")
@ -369,7 +381,7 @@ def evts_webhook(request):
webhook_httpd.server_close()
web_server.join()
@pytest.fixture(scope='module')
@pytest.fixture(scope='class')
def actions_fixture(hge_ctx):
if hge_ctx.is_default_backend:
pg_version = hge_ctx.pg_version

View File

@ -4,15 +4,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
CREATE TABLE "user"(
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL,

View File

@ -3,7 +3,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
create table test_table(
first_name text,
last_name text,

View File

@ -4,8 +4,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
create table hge_tests.test_bigint(
id bigint,
name text

View File

@ -6,14 +6,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
create table author(
id serial primary key,
name text unique,

View File

@ -5,14 +5,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
CREATE TABLE drone_3d_location (
drone_id INTEGER PRIMARY KEY,
location GEOGRAPHY(Pointz)

View File

@ -6,14 +6,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
create table author(
id serial primary key,
name text unique,

View File

@ -4,14 +4,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
CREATE TABLE geom_table(
id SERIAL PRIMARY KEY,
type TEXT NOT NULL,

View File

@ -6,15 +6,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
CREATE TABLE dummy_rast(
rid serial primary key,
rast raster

View File

@ -59,15 +59,6 @@ args:
END;
$$ LANGUAGE plpgsql STABLE;
CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
CREATE TABLE locations
(
id uuid NOT NULL DEFAULT gen_random_uuid(),

View File

@ -80,17 +80,6 @@ args:
INSERT INTO books (id, author_name, book_name, published_on)
VALUES (1, 'J.K. Rowling', 'Harry Porter', '1997-06-26');
CREATE EXTENSION IF NOT EXISTS postgis;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
CREATE TABLE geom_table(
id SERIAL PRIMARY KEY,
type TEXT NOT NULL,

View File

@ -5,7 +5,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
create table author(
id SERIAL PRIMARY KEY,
name TEXT UNIQUE,

View File

@ -4,14 +4,6 @@ args:
- type: run_sql
args:
sql: |
CREATE EXTENSION IF NOT EXISTS postgis;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
CREATE TABLE geom_table(
id SERIAL PRIMARY KEY,
type TEXT NOT NULL,

View File

@ -20,14 +20,7 @@ args:
is_published BOOLEAN NOT NULL default FALSE,
published_on TIMESTAMP
);
CREATE EXTENSION IF NOT EXISTS postgis;
DO $$
BEGIN
IF PostGIS_lib_version() ~ '^3.*' THEN
CREATE EXTENSION IF NOT EXISTS postgis_raster;
END IF;
END$$;
CREATE EXTENSION IF NOT EXISTS postgis_topology;
CREATE TABLE geom_table(
id SERIAL PRIMARY KEY,
type TEXT NOT NULL,

View File

@ -798,7 +798,7 @@ class TestCreateActionNestedTypeWithRelation:
def test_create_sync_action_with_nested_output_and_nested_relation(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/create_sync_action_with_nested_output_and_nested_relation.yaml')
@pytest.mark.usefixtures('per_class_tests_db_state')
@pytest.mark.usefixtures('postgis', 'per_class_tests_db_state')
class TestSetCustomTypes:
@classmethod

View File

@ -6,7 +6,7 @@ from context import PytestConf
import redis
@pytest.mark.parametrize("transport", ['http'])
@pytest.mark.usefixtures('per_class_tests_db_state')
@pytest.mark.usefixtures('postgis', 'per_class_tests_db_state')
class TestCustomEndpoints:
def flushRedis(self):
# TODO: Move this into setup/teardown

View File

@ -260,7 +260,7 @@ class TestEventFloodPostgresMSSQL(object):
ns.sort()
assert ns == list(payload)
@usefixtures("per_class_tests_db_state")
@usefixtures('postgis', 'per_class_tests_db_state')
class TestEventDataFormat(object):
@classmethod

View File

@ -290,6 +290,7 @@ class TestGraphqlInsertNullPrefixedColumnOnConflict:
@use_mutation_fixtures
@usefixtures('postgis')
class TestGraphqlInsertGeoJson:
def test_insert_point_landmark(self, hge_ctx):
@ -414,6 +415,7 @@ class TestGraphqlInsertViews:
@use_mutation_fixtures
@usefixtures('postgis')
class TestGraphqlUpdateBasic:
def test_set_author_name(self, hge_ctx):
@ -570,6 +572,7 @@ class TestGraphqlUpdatePermissionsMSSQL:
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@use_mutation_fixtures
@usefixtures('postgis')
class TestGraphqlDeleteBasic:
def test_article_delete(self, hge_ctx, transport):
@ -596,7 +599,7 @@ class TestGraphqlDeleteBasic:
@pytest.mark.backend('mssql')
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('per_method_tests_db_state')
@usefixtures('per_method_tests_db_state', 'postgis')
class TestGraphqlDeleteBasicMSSQL:
def test_article_delete(self, hge_ctx, transport):

View File

@ -489,7 +489,7 @@ class TestGraphQLQueryBoolExpBasicMSSQL:
return 'queries/graphql_query/boolexp/basic'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
@usefixtures('postgis', 'per_class_tests_db_state')
class TestGraphqlQueryPermissions:
def test_user_select_unpublished_articles(self, hge_ctx, transport):
@ -760,7 +760,7 @@ class TestGraphQLQueryBoolExpJsonB:
return 'queries/graphql_query/boolexp/jsonb'
@pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription'])
@usefixtures('per_class_tests_db_state')
@usefixtures('postgis', 'per_class_tests_db_state')
class TestGraphQLQueryBoolExpPostGIS:
def test_query_using_point(self, hge_ctx, transport):
@ -792,7 +792,7 @@ class TestGraphQLQueryBoolExpPostGIS:
return 'queries/graphql_query/boolexp/postgis'
@pytest.mark.parametrize("transport", ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
@usefixtures('postgis', 'per_class_tests_db_state')
class TestGraphQLQueryBoolExpRaster:
def test_query_st_intersects_geom_nband(self, hge_ctx, transport):
@ -984,7 +984,7 @@ class TestGraphQLQueryEnums:
check_query_f(hge_ctx, self.dir() + '/select_where_enum_eq_without_enum_table_visibility.yaml', transport)
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@usefixtures('per_class_tests_db_state')
@usefixtures('postgis', 'per_class_tests_db_state')
class TestGraphQLQueryComputedFields:
@classmethod
def dir(cls):

View File

@ -119,7 +119,7 @@ class TestJWTExpirySkew():
}
@pytest.fixture(scope='class')
def setup(self, request, hge_ctx):
def setup(self, postgis, hge_ctx):
self.dir = 'queries/graphql_query/permissions'
hge_ctx.v1q_f(self.dir + '/setup.yaml')
yield
@ -388,7 +388,7 @@ class TestJWTBasic():
}
@pytest.fixture(scope='class')
def setup(self, request, hge_ctx):
def setup(self, postgis, hge_ctx):
self.dir = 'queries/graphql_query/permissions'
hge_ctx.v1q_f(self.dir + '/setup.yaml')
yield
@ -512,7 +512,7 @@ class TestJwtAudienceCheck():
}
@pytest.fixture(scope='class')
def setup(self, request, hge_ctx):
def setup(self, postgis, hge_ctx):
self.dir = 'queries/graphql_query/permissions'
hge_ctx.v1q_f(self.dir + '/setup.yaml')
yield
@ -592,7 +592,7 @@ class TestJwtIssuerCheck():
}
@pytest.fixture(scope='class')
def setup(self, request, hge_ctx):
def setup(self, postgis, hge_ctx):
self.dir = 'queries/graphql_query/permissions'
hge_ctx.v1q_f(self.dir + '/setup.yaml')
yield

View File

@ -198,7 +198,7 @@ class TestJWTClaimsMapBasic():
}
@pytest.fixture(scope='class')
def setup(self, request, hge_ctx):
def setup(self, postgis, hge_ctx):
self.dir = 'queries/graphql_query/permissions'
hge_ctx.v1q_f(self.dir + '/setup.yaml')
yield
@ -280,7 +280,7 @@ class TestJWTClaimsMapWithStaticHasuraClaimsMapValues():
}
@pytest.fixture(scope='class')
def setup(self, request, hge_ctx):
def setup(self, postgis, hge_ctx):
self.dir = 'queries/graphql_query/permissions'
hge_ctx.v1q_f(self.dir + '/setup.yaml')
yield

View File

@ -14,7 +14,7 @@ from ruamel.yaml.comments import CommentedMap
usefixtures = pytest.mark.usefixtures
@usefixtures("per_class_tests_db_state")
@usefixtures('postgis', 'per_class_tests_db_state')
class TestTests1:
"""
Test various things about our test framework code. Validate that tests work
@ -44,7 +44,7 @@ class TestTests1:
"""We can detect bad ordering of selection set"""
check_query_f(hge_ctx, 'test_tests/select_query_author_by_pkey_bad_ordering.yaml', 'http')
#
# E AssertionError:
# E AssertionError:
# E expected:
# E data:
# E author_by_pk:
@ -64,7 +64,7 @@ class TestTests1:
return 'queries/graphql_query/basic'
@usefixtures('per_class_tests_db_state')
@usefixtures('postgis', 'per_class_tests_db_state')
class TestTests2:
"""
Test various things about our test framework code. Validate that tests work
@ -77,7 +77,7 @@ class TestTests2:
"""We can detect bad ordering of selection set"""
check_query_f(hge_ctx, 'test_tests/user_can_query_jsonb_values_filter_bad_order.yaml', 'http')
#
# E AssertionError:
# E AssertionError:
# E expected:
# E data:
# E jsonb_table:
@ -113,15 +113,15 @@ class TestTests2:
# (CommentedMap is ruamel.yaml's OrderedMap that also preserves
# format):
fully_ordered_result = \
CommentedMap([('data',
CommentedMap([('data',
CommentedMap([
('thing1', "thing1"),
('jsonb_table', [
CommentedMap([
('id', 1),
('id', 1),
('jsonb_col', CommentedMap([('age', 7), ('name', 'Hasura')]))]),
CommentedMap([
('id', 2),
('id', 2),
('jsonb_col', CommentedMap([('age', 8), ('name', 'Rawkz')]))]),
]),
('thing2', CommentedMap([("a",1), ("b",2), ("c",3)])),
@ -131,15 +131,15 @@ class TestTests2:
# We expect to have discarded ordering of leaves not in selset:
relevant_ordered_result_expected = \
dict([('data',
dict([('data',
CommentedMap([
('thing1', "thing1"),
('jsonb_table', [
CommentedMap([
('id', 1),
('id', 1),
('jsonb_col', dict([('age', 7), ('name', 'Hasura')]))]),
CommentedMap([
('id', 2),
('id', 2),
('jsonb_col', dict([('age', 8), ('name', 'Rawkz')]))]),
]),
('thing2', dict([("a",1), ("b",2), ("c",3)])),
@ -166,7 +166,7 @@ class TestTests2:
@classmethod
def dir(cls):
return 'queries/graphql_query/permissions'
@usefixtures("per_class_tests_db_state")
class TestTests3:
@ -194,7 +194,7 @@ class TestTests3:
print("FAIL!")
assert 0, "Test failure, occurs as expected"
# It reaches here only if the exception wasn't caught, in which case
# this current test should fail
# this current test should fail
"""
This test case is about testing validate_http_anyq_with_allowed_responses
@ -246,8 +246,8 @@ class TestTests3:
except:
print("FAIL!")
assert 0, "Test failed, as expected"
# Re-use setup and teardown from where we adapted this test case:
@classmethod

View File

@ -223,7 +223,7 @@ class TestV1SelectBoolExpJSONB:
def dir(cls):
return 'queries/v1/select/boolexp/jsonb'
@usefixtures('per_class_tests_db_state')
@usefixtures('postgis', 'per_class_tests_db_state')
class TestV1SelectBoolExpPostGIS:
def test_query_st_equals(self, hge_ctx):
@ -263,7 +263,7 @@ class TestV1SelectBoolExpPostGIS:
def dir(cls):
return 'queries/v1/select/boolexp/postgis'
@usefixtures('per_class_tests_db_state')
@usefixtures('postgis', 'per_class_tests_db_state')
class TestV1SelectPermissions:
def test_user_select_unpublished_articles(self, hge_ctx):
@ -690,7 +690,7 @@ class TestSetTableIsEnum:
def test_relationship_with_inconsistent_enum_table(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/relationship_with_inconsistent_enum_table.yaml')
def test_custom_enum_table_name(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/custom_enum_table_name.yaml')

View File

@ -5,7 +5,7 @@ from validate import check_query_f
# graphql parser can't seem to parse {where: null}, disabling
# websocket till then
@pytest.mark.parametrize("transport", ['http'])
@pytest.mark.usefixtures('per_method_tests_db_state')
@pytest.mark.usefixtures('postgis', 'per_method_tests_db_state')
class TestGraphQLValidation:
def test_null_value(self, hge_ctx, transport):