2022-11-15 22:07:34 +03:00
|
|
|
import os
|
2022-02-21 12:59:02 +03:00
|
|
|
import pytest
|
2022-11-15 22:07:34 +03:00
|
|
|
import sqlalchemy
|
|
|
|
from typing import Optional
|
|
|
|
import urllib.parse
|
|
|
|
|
|
|
|
from context import HGECtx, PytestConf
|
|
|
|
import fixtures.postgres
|
2022-02-21 12:59:02 +03:00
|
|
|
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'])
|
2022-08-02 22:32:46 +03:00
|
|
|
@pytest.mark.backend('postgres', 'citus')
|
2022-11-15 22:07:34 +03:00
|
|
|
@pytest.mark.admin_secret
|
|
|
|
@pytest.mark.hge_env('HASURA_GRAPHQL_ADMIN_INTERNAL_ERRORS', 'false')
|
|
|
|
@usefixtures('setup_schema_externally')
|
2022-02-21 12:59:02 +03:00
|
|
|
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):
|
2023-04-12 17:35:50 +03:00
|
|
|
if transport != 'http':
|
|
|
|
pytest.skip('This test should only run over HTTP.')
|
|
|
|
check_query_f(hge_ctx, self.dir() + '/update_query_aves.yaml', transport)
|
2022-02-21 12:59:02 +03:00
|
|
|
|
|
|
|
|
|
|
|
# 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')
|
2022-11-15 22:07:34 +03:00
|
|
|
def setup_schema_externally(
|
|
|
|
owner_engine: sqlalchemy.engine.Engine,
|
|
|
|
hge_ctx: HGECtx,
|
2023-04-12 17:35:50 +03:00
|
|
|
add_source,
|
2022-11-15 22:07:34 +03:00
|
|
|
):
|
2023-04-12 17:35:50 +03:00
|
|
|
source = 'read_only'
|
|
|
|
backend = add_source(source, read_only = True)
|
2022-11-15 22:07:34 +03:00
|
|
|
|
2023-04-12 17:35:50 +03:00
|
|
|
with fixtures.postgres.switch_schema(owner_engine, backend.name).connect() as connection:
|
2022-11-15 22:07:34 +03:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|