这是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
8 changes: 8 additions & 0 deletions server/tests-py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def pytest_addoption(parser):
help="Run testcases for logging"
)

parser.addoption(
"--accept",
action="store_true",
default=False,
required=False,
help="Accept any failing test cases from YAML files as correct, and write the new files out to disk."
)


#By default,
#1) Set default parallelism to one
Expand Down
19 changes: 14 additions & 5 deletions server/tests-py/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from http import HTTPStatus
from urllib.parse import urlparse
from ruamel.yaml.comments import CommentedMap as OrderedDict # to avoid '!!omap' in yaml
# from collections import OrderedDict
# import socketserver
import threading
import http.server
Expand All @@ -14,7 +16,7 @@
import string
import random

import yaml
import ruamel.yaml as yaml
import requests
import websocket
from sqlalchemy import create_engine
Expand Down Expand Up @@ -128,7 +130,9 @@ def _on_open(self):
self.connected_event.set()

def _on_message(self, message):
json_msg = json.loads(message)
# NOTE: make sure we preserve key ordering so we can test the ordering
# properties in the graphql spec properly
json_msg = json.loads(message, object_pairs_hook=OrderedDict)
if 'id' in json_msg:
query_id = json_msg['id']
if json_msg.get('type') == 'stop':
Expand Down Expand Up @@ -279,7 +283,9 @@ def anyq(self, u, q, h):
json=q,
headers=h
)
return resp.status_code, resp.json()
# NOTE: make sure we preserve key ordering so we can test the ordering
# properties in the graphql spec properly
return resp.status_code, resp.json(object_pairs_hook=OrderedDict)

def sql(self, q):
conn = self.engine.connect()
Expand All @@ -296,11 +302,14 @@ def v1q(self, q, headers = {}):
json=q,
headers=h
)
return resp.status_code, resp.json()
# NOTE: make sure we preserve key ordering so we can test the ordering
# properties in the graphql spec properly
return resp.status_code, resp.json(object_pairs_hook=OrderedDict)

def v1q_f(self, fn):
with open(fn) as f:
return self.v1q(yaml.safe_load(f))
# NOTE: preserve ordering with RoundTripLoader:
return self.v1q(yaml.load(f, yaml.RoundTripLoader))

def teardown(self):
self.http.close()
Expand Down
4 changes: 4 additions & 0 deletions server/tests-py/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[pytest]
norecursedirs = queries webhook
; Turn any expected failures that pass ("xpassed") into hard failures. This
; lets us use 'xfail' to create test cases that validate other tests, and also
; means we're sure to notice if e.g. a known bug is fixed.
xfail_strict = true
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ response:
delete_resident:
affected_rows: 1
returning:
- age: 25
id: 1
- id: 1
name: Griffin
age: 25
headers:
X-Hasura-Role: agent
X-Hasura-Allowed-Resident-Ids: '{1,2}'
query:
query: |
mutation{
delete_resident(
where: {id: {_eq: 1}}
){
affected_rows
returning {
id
name
age
}
}
}
mutation{
delete_resident(
where: {id: {_eq: 1}}
){
affected_rows
returning {
id
name
age
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ response:
delete_article:
affected_rows: 1
returning:
- author_id: 1
id: 1
- id: 1
title: Article 1
content: Sample article content 1
author_id: 1
query:
query: |
mutation delete_article {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@
data:
insert_article:
returning:
- content: Sample article content
id: 1
- id: 1
title: Article 1
- content: Sample article content
id: 2
content: Sample article content
- id: 2
title: Article 2
- content: Sample article content
id: 3
content: Sample article content
- id: 3
title: Article 3
content: Sample article content
status: 200
query:
query: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,46 @@
returning:
- id: 1
name: Baz
type: river
location: &loc1
coordinates: [43.75049, 11.03207]
type: Point
crs: &crs
location:
crs:
type: name
properties:
name: 'urn:ogc:def:crs:EPSG::4326'
name: urn:ogc:def:crs:EPSG::4326
type: Point
coordinates:
- 43.75049
- 11.03207
type: river
- id: 2
name: Foo Bar
type: park
location: &loc2
coordinates: [43.76417, 11.25869]
location:
crs:
type: name
properties:
name: urn:ogc:def:crs:EPSG::4326
type: Point
crs: *crs
coordinates:
- 43.76417
- 11.25869
type: park
query:
variables:
landmarks:
- name: Baz
type: river
location: *loc1
location:
coordinates: [43.75049, 11.03207]
type: Point
crs: &crs
type: name
properties:
name: urn:ogc:def:crs:EPSG::4326
- name: Foo Bar
type: park
location: *loc2
location:
coordinates: [43.76417, 11.25869]
type: Point
crs: *crs
query: |
mutation insertLandmark($landmarks: [landmark_insert_input!]!) {
insert_landmark(objects: $landmarks) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ description: Insert article and it's author via nested mutation
url: /v1/graphql
status: 200
query:
query: |
query: |-
mutation article_author{
insert_article(
objects: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ description: Insert author and it's articles via nested mutation
url: /v1/graphql
status: 200
query:
query: |
query: |-
mutation nested_author_insert {
insert_author(
objects: [
{
name: "Author 3",
name: "Author 3",
articles: {
data: [
{
title: "Article 1 by Author 3",
content: "Content for Article 1 by Author 3",
title: "Article 1 by Author 3",
content: "Content for Article 1 by Author 3",
is_published: false
},
{
title: "Article 2 by Author 3",
content: "Content for Article 2 by Author 3",
title: "Article 2 by Author 3",
content: "Content for Article 2 by Author 3",
is_published: false
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
description: Upserts article data via GraphQL mutation
url: /v1/graphql
response:
data:
insert_article:
returning:
- content: Updated Article 1 content
title: Article 1
- content: Updated Article 2 content
title: Article 2
data:
insert_article:
returning:
- title: Article 1
content: Updated Article 1 content
- title: Article 2
content: Updated Article 2 content
status: 200
query:
query: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ response:
data:
insert_article:
returning:
- content: Sample article content 4
title: Article 4
- title: Article 4
content: Sample article content 4
query:
query: |
mutation insert_article {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: 200
response:
data:
insert_article:
affected_rows: 4
returning:
- author_simple:
name: Author 1
Expand All @@ -17,9 +18,8 @@ response:
content: Article content for article by author 2
id: 2
title: Article by author 2
affected_rows: 4
query:
query: |
query: |-
mutation article_author_simple{
insert_article(
objects: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ description: Update mutation on author
url: /v1/graphql
response:
data:
update_author:
affected_rows: 1
returning:
- articles: []
id: 1
name: Jane
update_author:
affected_rows: 1
returning:
- id: 1
name: Jane
articles: []
status: 200
query:
query: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ status: 200
response:
data:
update_person:
affected_rows: 1
returning:
- details:
- id: 2
details:
- address:
country: Denmark
city: Copenhagen
Expand All @@ -15,8 +17,6 @@ response:
- address:
country: Australia
city: Sydney
id: 2
affected_rows: 1
query:
variables:
value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ response:
update_person:
affected_rows: 1
returning:
- details:
address:
city: Sydney
country: Australia
- id: 1
details:
name:
first: John
last: Taylor
id: 1

first: John
address:
country: Australia
city: Sydney
query:
variables:
value:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ url: /v1/graphql
response:
data:
update_person:
affected_rows: 1
returning:
- details:
- id: 2
details:
- address:
country: United Kingdom
city: Canterbury
id: 2
affected_rows: 1
status: 200
query:
query: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ status: 200
response:
data:
update_person:
affected_rows: 1
returning:
- details:
- id: 1
details:
name:
first: John
id: 1
affected_rows: 1
query:
query: |
mutation update_person($value: jsonb) {
Expand Down
Loading