mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
987b55f981
We have a lot of `assert st_code == 200` scattered about. This is a problem because (a) it makes the code harder to parse and (b) the error message is lacking; I have seen a few flaky tests which were impossible to diagnose because I didn't know what the response _should_ be. This reduces the number of places in which we perform this assertion (moving most of them to `HGECtx.execute_query`), so that we can have a better chance of seeing a useful error message on test failure. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4957 GitOrigin-RevId: 3ff388bccf49f96569aa6b7db85266a0c5ee27ea
68 lines
1.9 KiB
Python
68 lines
1.9 KiB
Python
import pytest
|
|
from abc import ABC, abstractmethod
|
|
import os
|
|
|
|
class DefaultTestQueries(ABC):
|
|
|
|
def do_setup(self, setup_ctrl, hge_ctx):
|
|
if not setup_ctrl['setupDone']:
|
|
hge_ctx.v1q_f(self.dir() + '/setup.yaml')
|
|
setup_ctrl['setupDone'] = True
|
|
|
|
def do_teardown(self, setup_ctrl, hge_ctx):
|
|
if setup_ctrl['setupDone'] and not hge_ctx.may_skip_test_teardown:
|
|
hge_ctx.v1q_f(self.dir() + '/teardown.yaml')
|
|
setup_ctrl['setupDone'] = False
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def transact(self, setup_ctrl, hge_ctx):
|
|
self.do_setup(setup_ctrl, hge_ctx)
|
|
yield
|
|
self.do_teardown(setup_ctrl, hge_ctx);
|
|
|
|
@abstractmethod
|
|
def dir(self) -> str:
|
|
pass
|
|
|
|
class DefaultTestMutations(ABC):
|
|
|
|
@pytest.fixture(scope='class')
|
|
def schema_transact(self, request, hge_ctx):
|
|
hge_ctx.v1q_f(self.dir() + '/schema_setup.yaml')
|
|
yield
|
|
hge_ctx.v1q_f(self.dir() + '/schema_teardown.yaml')
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def init_values_transact(self, schema_transact, hge_ctx):
|
|
setupValFile = self.dir() + '/values_setup.yaml'
|
|
if os.path.isfile(setupValFile):
|
|
hge_ctx.v1q_f(setupValFile)
|
|
yield
|
|
hge_ctx.v1q_f(self.dir() + '/values_teardown.yaml')
|
|
|
|
@abstractmethod
|
|
def dir(self) -> str:
|
|
pass
|
|
|
|
|
|
# Any test which has a setup and a teardown
|
|
# Ideally, DefaultTestSelectQueries should just be this
|
|
class GraphQLEngineTest(ABC):
|
|
|
|
@pytest.fixture(scope='class')
|
|
def transact(self, request, hge_ctx):
|
|
hge_ctx.v1q_f(self.dir() + '/setup.yaml')
|
|
yield
|
|
hge_ctx.v1q_f(self.dir() + '/teardown.yaml')
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def ensure_transact(self, transact):
|
|
pass
|
|
|
|
@abstractmethod
|
|
def dir(self) -> str:
|
|
pass
|
|
|
|
class DefaultTestSelectQueries(GraphQLEngineTest):
|
|
pass
|