2018-09-18 09:21:57 +03:00
|
|
|
import pytest
|
2018-10-04 15:44:15 +03:00
|
|
|
import time
|
2018-09-18 09:21:57 +03:00
|
|
|
from context import HGECtx, HGECtxError
|
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
|
2018-09-18 09:21:57 +03:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption(
|
|
|
|
"--hge-url", metavar="HGE_URL", help="url for graphql-engine", required=True
|
|
|
|
)
|
|
|
|
parser.addoption(
|
|
|
|
"--pg-url", metavar="PG_URL", help="url for connecting to Postgres directly", required=True
|
|
|
|
)
|
2018-10-28 21:27:49 +03:00
|
|
|
parser.addoption(
|
2019-02-14 12:37:47 +03:00
|
|
|
"--hge-key", metavar="HGE_KEY", help="admin secret key for graphql-engine", required=False
|
2018-10-28 21:27:49 +03:00
|
|
|
)
|
|
|
|
parser.addoption(
|
|
|
|
"--hge-webhook", metavar="HGE_WEBHOOK", help="url for graphql-engine's access control webhook", required=False
|
|
|
|
)
|
|
|
|
parser.addoption(
|
|
|
|
"--test-webhook-insecure", action="store_true",
|
|
|
|
help="Run Test cases for insecure https webhook"
|
|
|
|
)
|
|
|
|
parser.addoption(
|
|
|
|
"--hge-jwt-key-file", metavar="HGE_JWT_KEY_FILE", help="File containting the private key used to encode jwt tokens using RS512 algorithm", required=False
|
|
|
|
)
|
2019-02-05 15:04:16 +03:00
|
|
|
parser.addoption(
|
|
|
|
"--hge-jwt-conf", metavar="HGE_JWT_CONF", help="The JWT conf", required=False
|
|
|
|
)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2019-02-14 08:58:38 +03:00
|
|
|
parser.addoption(
|
|
|
|
"--test-cors", action="store_true",
|
|
|
|
required=False,
|
|
|
|
help="Run testcases for CORS configuration"
|
|
|
|
)
|
|
|
|
|
2019-02-28 16:53:03 +03:00
|
|
|
parser.addoption(
|
|
|
|
"--test-metadata-disabled", action="store_true",
|
|
|
|
help="Run Test cases with metadata queries being disabled"
|
|
|
|
)
|
|
|
|
|
|
|
|
parser.addoption(
|
|
|
|
"--test-graphql-disabled", action="store_true",
|
|
|
|
help="Run Test cases with GraphQL queries being disabled"
|
|
|
|
)
|
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
|
2018-09-18 09:21:57 +03:00
|
|
|
@pytest.fixture(scope='session')
|
|
|
|
def hge_ctx(request):
|
2018-10-30 12:21:58 +03:00
|
|
|
print("create hge_ctx")
|
2018-09-18 09:21:57 +03:00
|
|
|
hge_url = request.config.getoption('--hge-url')
|
|
|
|
pg_url = request.config.getoption('--pg-url')
|
2018-10-28 21:27:49 +03:00
|
|
|
hge_key = request.config.getoption('--hge-key')
|
|
|
|
hge_webhook = request.config.getoption('--hge-webhook')
|
|
|
|
webhook_insecure = request.config.getoption('--test-webhook-insecure')
|
|
|
|
hge_jwt_key_file = request.config.getoption('--hge-jwt-key-file')
|
2019-02-05 15:04:16 +03:00
|
|
|
hge_jwt_conf = request.config.getoption('--hge-jwt-conf')
|
2019-02-14 08:58:38 +03:00
|
|
|
test_cors = request.config.getoption('--test-cors')
|
2019-02-28 16:53:03 +03:00
|
|
|
metadata_disabled = request.config.getoption('--test-metadata-disabled')
|
2018-09-18 09:21:57 +03:00
|
|
|
try:
|
2019-02-05 15:04:16 +03:00
|
|
|
hge_ctx = HGECtx(
|
|
|
|
hge_url=hge_url,
|
|
|
|
pg_url=pg_url,
|
|
|
|
hge_key=hge_key,
|
|
|
|
hge_webhook=hge_webhook,
|
|
|
|
webhook_insecure=webhook_insecure,
|
|
|
|
hge_jwt_key_file=hge_jwt_key_file,
|
2019-02-28 16:53:03 +03:00
|
|
|
hge_jwt_conf=hge_jwt_conf,
|
|
|
|
metadata_disabled=metadata_disabled
|
2019-02-05 15:04:16 +03:00
|
|
|
)
|
2018-09-18 09:21:57 +03:00
|
|
|
except HGECtxError as e:
|
|
|
|
pytest.exit(str(e))
|
2019-02-14 08:58:38 +03:00
|
|
|
|
2018-09-18 09:21:57 +03:00
|
|
|
yield hge_ctx # provide the fixture value
|
|
|
|
print("teardown hge_ctx")
|
|
|
|
hge_ctx.teardown()
|
2018-10-04 15:44:15 +03:00
|
|
|
time.sleep(2)
|
2018-10-28 21:27:49 +03:00
|
|
|
|
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def setup_ctrl(request, hge_ctx):
|
|
|
|
"""
|
|
|
|
This fixure is used to store the state of test setup in some test classes.
|
|
|
|
Used primarily when teardown is skipped in some test cases in the class where the test is not expected to change the database state.
|
|
|
|
"""
|
|
|
|
setup_ctrl = { "setupDone" : False }
|
|
|
|
yield setup_ctrl
|
|
|
|
hge_ctx.may_skip_test_teardown = False
|
|
|
|
request.cls().do_teardown(setup_ctrl, hge_ctx)
|