2018-10-28 21:27:49 +03:00
|
|
|
import pytest
|
|
|
|
from abc import ABC, abstractmethod
|
2019-04-08 10:22:38 +03:00
|
|
|
import os
|
2018-10-28 21:27:49 +03:00
|
|
|
|
|
|
|
class DefaultTestQueries(ABC):
|
|
|
|
|
|
|
|
def do_setup(self, setup_ctrl, hge_ctx):
|
|
|
|
if not setup_ctrl['setupDone']:
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(self.dir() + '/setup.yaml')
|
2018-10-28 21:27:49 +03:00
|
|
|
setup_ctrl['setupDone'] = True
|
|
|
|
|
|
|
|
def do_teardown(self, setup_ctrl, hge_ctx):
|
|
|
|
if setup_ctrl['setupDone'] and not hge_ctx.may_skip_test_teardown:
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(self.dir() + '/teardown.yaml')
|
2018-10-28 21:27:49 +03:00
|
|
|
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
|
2022-07-05 21:00:08 +03:00
|
|
|
def dir(self) -> str:
|
2018-10-28 21:27:49 +03:00
|
|
|
pass
|
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
class DefaultTestMutations(ABC):
|
|
|
|
|
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def schema_transact(self, request, hge_ctx):
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(self.dir() + '/schema_setup.yaml')
|
2019-04-08 10:22:38 +03:00
|
|
|
yield
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(self.dir() + '/schema_teardown.yaml')
|
2019-04-08 10:22:38 +03:00
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def init_values_transact(self, schema_transact, hge_ctx):
|
|
|
|
setupValFile = self.dir() + '/values_setup.yaml'
|
|
|
|
if os.path.isfile(setupValFile):
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(setupValFile)
|
2019-04-08 10:22:38 +03:00
|
|
|
yield
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(self.dir() + '/values_teardown.yaml')
|
2019-04-08 10:22:38 +03:00
|
|
|
|
|
|
|
@abstractmethod
|
2022-07-05 21:00:08 +03:00
|
|
|
def dir(self) -> str:
|
2019-04-08 10:22:38 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-04-24 10:49:39 +03:00
|
|
|
# Any test which has a setup and a teardown
|
|
|
|
# Ideally, DefaultTestSelectQueries should just be this
|
|
|
|
class GraphQLEngineTest(ABC):
|
2018-10-28 21:27:49 +03:00
|
|
|
|
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def transact(self, request, hge_ctx):
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(self.dir() + '/setup.yaml')
|
2018-10-28 21:27:49 +03:00
|
|
|
yield
|
2022-07-05 21:00:08 +03:00
|
|
|
hge_ctx.v1q_f(self.dir() + '/teardown.yaml')
|
2018-10-28 21:27:49 +03:00
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def ensure_transact(self, transact):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2022-07-05 21:00:08 +03:00
|
|
|
def dir(self) -> str:
|
2018-10-28 21:27:49 +03:00
|
|
|
pass
|
2019-04-24 10:49:39 +03:00
|
|
|
|
|
|
|
class DefaultTestSelectQueries(GraphQLEngineTest):
|
|
|
|
pass
|