graphql-engine/server/tests-py/test_graphql_read_only_source.py
Samir Talwar 43f179688c server/tests-py: Run test_graphql_read_only_source.py in parallel.
This requires making it add its own source, rather than expecting one to be provided.

[NDAT-537]: https://hasurahq.atlassian.net/browse/NDAT-537?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8745
GitOrigin-RevId: 65c818e4f065e9f98e9cfd65c158eff5d768ae31
2023-04-12 14:37:21 +00:00

65 lines
2.1 KiB
Python

import os
import pytest
import sqlalchemy
from typing import Optional
import urllib.parse
from context import HGECtx, PytestConf
import fixtures.postgres
from validate import check_query_f
# Mark that all tests in this module can be run as server upgrade tests
pytestmark = pytest.mark.allow_server_upgrade_test
usefixtures = pytest.mark.usefixtures
@pytest.mark.parametrize('transport', ['http', 'websocket'])
@pytest.mark.backend('postgres', 'citus')
@pytest.mark.admin_secret
@pytest.mark.hge_env('HASURA_GRAPHQL_ADMIN_INTERNAL_ERRORS', 'false')
@usefixtures('setup_schema_externally')
class TestGraphQLOnReadOnlySource:
@classmethod
def dir(cls):
return 'queries/graphql_query/read_only_source'
setup_metadata_api_version = 'v2'
def test_query_aves(self, hge_ctx, transport):
check_query_f(hge_ctx, self.dir() + '/select_query_aves.yaml', transport)
# graphql-engine's websocket response is different than in http on execution
# errors; so this test is run only on http
def test_mutation_aves(self, hge_ctx, transport):
if transport != 'http':
pytest.skip('This test should only run over HTTP.')
check_query_f(hge_ctx, self.dir() + '/update_query_aves.yaml', transport)
# As this is a read-only test, we can't create the schema/tables as part of the
# HGE metadata. Hence, we create it as a separate fixture, where we execute the
# DDLs directly on the database.
@pytest.fixture(scope='class')
def setup_schema_externally(
owner_engine: sqlalchemy.engine.Engine,
hge_ctx: HGECtx,
add_source,
):
source = 'read_only'
backend = add_source(source, read_only = True)
with fixtures.postgres.switch_schema(owner_engine, backend.name).connect() as connection:
connection.execute("CREATE TABLE aves (id serial PRIMARY KEY, name TEXT)")
connection.execute("INSERT INTO aves (name) VALUES ('Booted Eagle'), ('Hooded Merganser')")
hge_ctx.v1metadataq({
'type': 'pg_track_table',
'args': {
'source': source,
'table': {
'name': 'aves',
},
},
})