这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ refs:
- run:
name: Ensure databases are present
environment:
DATABASE_URL: 'postgres://gql_test:@localhost:5432/gql_test'
# sqlalchemy throws warnings with postgres://
DATABASE_URL: 'postgresql://gql_test:@localhost:5432/gql_test'
command: |
psql "$DATABASE_URL" -c "SELECT 1 FROM pg_database WHERE datname = 'gql_test2'" | grep -q -F '(1 row)' || psql "$DATABASE_URL" -c 'CREATE DATABASE gql_test2;'
- run:
Expand All @@ -106,8 +107,8 @@ refs:
# Setting default number of threads to 2
# since circleci allocates 2 cpus per test container
GHCRTS: -N2
HASURA_GRAPHQL_DATABASE_URL: 'postgres://gql_test:@localhost:5432/gql_test'
HASURA_GRAPHQL_DATABASE_URL_2: 'postgres://gql_test:@localhost:5432/gql_test2'
HASURA_GRAPHQL_DATABASE_URL: 'postgresql://gql_test:@localhost:5432/gql_test'
HASURA_GRAPHQL_DATABASE_URL_2: 'postgresql://gql_test:@localhost:5432/gql_test2'
GRAPHQL_ENGINE: '/build/_server_output/graphql-engine'
GRAPHQL_ENGINE_TESTS: '/build/_server_output/graphql-engine-tests'
command: |
Expand Down Expand Up @@ -432,7 +433,7 @@ jobs:
docker:
- image: hasura/graphql-engine-upgrade-tester:v0.5
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://gql_test:@localhost:5432/gql_test
HASURA_GRAPHQL_DATABASE_URL: postgresql://gql_test:@localhost:5432/gql_test
- image: circleci/postgres:10-alpine
environment:
POSTGRES_USER: gql_test
Expand Down
3 changes: 2 additions & 1 deletion server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ release-image: $(project).cabal
# assumes this is built in circleci
ci-binary:
mkdir -p packaging/build/rootfs
stack $(STACK_FLAGS) build --test --no-run-tests --ghc-options=-Werror $(BUILD_FLAGS)
# --no-terminal for a cleaner output in circleci
stack $(STACK_FLAGS) build --no-terminal --test --no-run-tests --ghc-options=-Werror $(BUILD_FLAGS)
mkdir -p $(build_output)
cp $(build_dir)/$(project)/$(project) $(build_dir)/graphql-engine-tests/graphql-engine-tests $(build_output)
echo "$(VERSION)" > $(build_output)/version.txt
Expand Down
5 changes: 4 additions & 1 deletion server/tests-py/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
import time
from context import HGECtx, HGECtxError, EvtsWebhookServer, HGECtxGQLServer, GQLWsClient
from context import HGECtx, HGECtxError, EvtsWebhookServer, HGECtxGQLServer, GQLWsClient, PytestConf
import threading
import random
from datetime import datetime
Expand Down Expand Up @@ -101,6 +101,9 @@ def pytest_cmdline_preparse(config, args):


def pytest_configure(config):
# Pytest has removed the global pytest.config
# As a solution we are going to store it in PytestConf.config
PytestConf.config = config
if is_master(config):
if not config.getoption('--hge-urls'):
print("hge-urls should be specified")
Expand Down
4 changes: 4 additions & 0 deletions server/tests-py/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import graphql_server
import graphql

# pytest has removed the global pytest.config
# As a solution to this we are going to store it in PyTestConf.config
class PytestConf():
pass

class HGECtxError(Exception):
pass
Expand Down
4 changes: 3 additions & 1 deletion server/tests-py/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ idna==2.8
importlib-metadata==0.23
jsondiff==1.2.0
more-itertools==7.2.0
packaging==19.2
pluggy==0.13.0
promise==2.2.1
psycopg2-binary==2.8.4
py==1.8.0
pycparser==2.19
PyJWT==1.7.1
pytest==4.5.0
pyparsing==2.4.5
pytest==5.3.1
pytest-forked==1.1.3
pytest-xdist==1.30.0
PyYAML==5.1.2
Expand Down
6 changes: 4 additions & 2 deletions server/tests-py/test_allowlist_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import pytest
from validate import check_query_f
from super_classes import DefaultTestSelectQueries
from context import PytestConf

if not PytestConf.config.getoption("--test-allowlist-queries"):
pytest.skip("flag --test-allowlist-queries is not set. Cannot runt tests for allowlist queries", allow_module_level=True)

@pytest.mark.skipif(not pytest.config.getoption("--test-allowlist-queries"),
reason="flag --test-allowlist-queries is not set. Cannot runt tests for allowlist queries")
@pytest.mark.parametrize("transport", ['http','websocket'])
class TestAllowlistQueries(DefaultTestSelectQueries):

Expand Down
11 changes: 7 additions & 4 deletions server/tests-py/test_apis_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from validate import check_query, check_query_f
from context import PytestConf

def check_post_404(hge_ctx,url):
return check_query(hge_ctx, {
Expand All @@ -10,8 +11,10 @@ def check_post_404(hge_ctx,url):
'query': {}
})[0]

metadata_api_disabled = PytestConf.config.getoption("--test-metadata-disabled")
graphql_api_disabled = PytestConf.config.getoption("--test-graphql-disabled")

@pytest.mark.skipif(not pytest.config.getoption("--test-metadata-disabled"),
@pytest.mark.skipif(not metadata_api_disabled,
reason="flag --test-metadata-disabled is not set. Cannot run tests for metadata disabled")
class TestMetadataDisabled:

Expand All @@ -25,7 +28,7 @@ def test_metadata_api_1_disabled(self, hge_ctx):
check_post_404(hge_ctx,'/api/1/table/foo/select')


@pytest.mark.skipif(not pytest.config.getoption("--test-graphql-disabled"),
@pytest.mark.skipif(not graphql_api_disabled,
reason="--test-graphql-disabled is not set. Cannot run GraphQL disabled tests")
class TestGraphQLDisabled:

Expand All @@ -36,15 +39,15 @@ def test_graphql_explain_disabled(self, hge_ctx):
check_post_404(hge_ctx, '/v1/graphql/explain')


@pytest.mark.skipif(pytest.config.getoption("--test-graphql-disabled"),
@pytest.mark.skipif(graphql_api_disabled,
reason="--test-graphql-disabled is set. Cannot run GraphQL enabled tests")
class TestGraphQLEnabled:

def test_graphql_introspection(self, hge_ctx):
check_query_f(hge_ctx, "queries/graphql_introspection/introspection_only_kind_of_queryType.yaml")


@pytest.mark.skipif(pytest.config.getoption("--test-metadata-disabled"),
@pytest.mark.skipif(metadata_api_disabled,
reason="--test-metadata-disabled is set. Cannot run metadata enabled tests")
class TestMetadataEnabled:

Expand Down
3 changes: 2 additions & 1 deletion server/tests-py/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from context import PytestConf

if not pytest.config.getoption("--hge-key"):
if not PytestConf.config.getoption("--hge-key"):
pytest.skip("--hge-key flag is missing, skipping tests", allow_module_level=True)

def v1qCompat(hge_ctx, q, headers = {}):
Expand Down
3 changes: 2 additions & 1 deletion server/tests-py/test_cors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from context import PytestConf

if not pytest.config.getoption("--test-cors"):
if not PytestConf.config.getoption("--test-cors"):
pytest.skip("--test-cors flag is missing, skipping tests", allow_module_level=True)


Expand Down
5 changes: 3 additions & 2 deletions server/tests-py/test_horizontal_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import ruamel.yaml as yaml
import time
import jsondiff
from context import PytestConf


if not pytest.config.getoption("--test-hge-scale-url"):
if not PytestConf.config.getoption("--test-hge-scale-url"):
pytest.skip("--test-hge-scale-url flag is missing, skipping tests", allow_module_level=True)


Expand All @@ -24,7 +25,7 @@ def test_horizontal_scale_basic(self, hge_ctx):
with open(self.dir() + "/steps.yaml") as c:
conf = yaml.safe_load(c)

assert isinstance(conf, list) == True, 'Not an list'
assert isinstance(conf, list) == True, 'Not a list'
for _, step in enumerate(conf):
# execute operation
response = hge_ctx.http.post(
Expand Down
5 changes: 3 additions & 2 deletions server/tests-py/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
from cryptography.hazmat.primitives import serialization

from validate import check_query
from context import PytestConf


if not pytest.config.getoption('--hge-jwt-key-file'):
if not PytestConf.config.getoption('--hge-jwt-key-file'):
pytest.skip('--hge-jwt-key-file is missing, skipping JWT tests', allow_module_level=True)

if not pytest.config.getoption('--hge-jwt-conf'):
if not PytestConf.config.getoption('--hge-jwt-conf'):
pytest.skip('--hge-jwt-key-conf is missing, skipping JWT tests', allow_module_level=True)

def get_claims_fmt(raw_conf):
Expand Down
3 changes: 2 additions & 1 deletion server/tests-py/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import time

import pytest
from context import PytestConf

if not pytest.config.getoption("--test-logging"):
if not PytestConf.config.getoption("--test-logging"):
pytest.skip("--test-logging missing, skipping tests", allow_module_level=True)

class TestLogging():
Expand Down
3 changes: 2 additions & 1 deletion server/tests-py/test_webhook_insecure.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest
from validate import check_query_f
from super_classes import DefaultTestSelectQueries
from context import PytestConf

if not pytest.config.getoption("--test-webhook-insecure"):
if not PytestConf.config.getoption("--test-webhook-insecure"):
pytest.skip("--test-webhook-https-insecure flag is missing, skipping tests", allow_module_level=True)

class TestHTTPSWebhookInsecure(DefaultTestSelectQueries):
Expand Down
3 changes: 2 additions & 1 deletion server/tests-py/test_websocket_init_cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import websocket
import pytest
from validate import check_query
from context import PytestConf

if not pytest.config.getoption("--test-ws-init-cookie"):
if not PytestConf.config.getoption("--test-ws-init-cookie"):
pytest.skip("--test-ws-init-cookie flag is missing, skipping tests", allow_module_level=True)


Expand Down
8 changes: 4 additions & 4 deletions server/tests-py/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import time
import warnings

from context import GQLWsClient
from context import GQLWsClient, PytestConf

def check_keys(keys, obj):
for k in keys:
Expand Down Expand Up @@ -254,7 +254,7 @@ def assert_graphql_resp_expected(resp_orig, exp_response_orig, query):
exp_response = collapse_order_not_selset(exp_response_orig, query)
matched = equal_CommentedMap(resp, exp_response)

if pytest.config.getoption("--accept"):
if PytestConf.config.getoption("--accept"):
print('skipping assertion since we chose to --accept new output')
else:
yml = yaml.YAML()
Expand Down Expand Up @@ -309,7 +309,7 @@ def check_query_f(hge_ctx, f, transport='http', add_auth=True):
if isinstance(conf, list):
for ix, sconf in enumerate(conf):
actual_resp, matched = check_query(hge_ctx, sconf, transport, add_auth)
if pytest.config.getoption("--accept") and not matched:
if PytestConf.config.getoption("--accept") and not matched:
conf[ix]['response'] = actual_resp
should_write_back = True
else:
Expand All @@ -318,7 +318,7 @@ def check_query_f(hge_ctx, f, transport='http', add_auth=True):
actual_resp, matched = check_query(hge_ctx, conf, transport, add_auth)
# If using `--accept` write the file back out with the new expected
# response set to the actual response we got:
if pytest.config.getoption("--accept") and not matched:
if PytestConf.config.getoption("--accept") and not matched:
conf['response'] = actual_resp
should_write_back = True

Expand Down