Skip to content

Commit 596bccd

Browse files
nizar-mshahidhk
authored andcommitted
add python based tests, remove haskell tests
this does not generate coverage report yet
1 parent b07d04a commit 596bccd

File tree

183 files changed

+6696
-96
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

183 files changed

+6696
-96
lines changed

.circleci/config.yml

-15
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,6 @@ workflows:
331331
<<: *filter_only_vtags
332332
requires:
333333
- check_build_worthiness
334-
- test_server_pg_10.4:
335-
<<: *filter_only_vtags
336-
requires:
337-
- build_server
338-
- test_server_pg_9.6:
339-
<<: *filter_only_vtags
340-
requires:
341-
- build_server
342-
- test_server_pg_9.5:
343-
<<: *filter_only_vtags
344-
requires:
345-
- build_server
346334
- pytest_server_pg_10.4:
347335
<<: *filter_only_vtags
348336
requires:
@@ -358,9 +346,6 @@ workflows:
358346
- all_server_tests_pass:
359347
<<: *filter_only_vtags
360348
requires:
361-
- test_server_pg_10.4
362-
- test_server_pg_9.6
363-
- test_server_pg_9.5
364349
- pytest_server_pg_10.4
365350
- pytest_server_pg_9.6
366351
- pytest_server_pg_9.5

server/tests-py/conftest.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import time
23
from context import HGECtx, HGECtxError
34

45
def pytest_addoption(parser):
@@ -21,3 +22,4 @@ def hge_ctx(request):
2122
yield hge_ctx # provide the fixture value
2223
print("teardown hge_ctx")
2324
hge_ctx.teardown()
25+
time.sleep(2)

server/tests-py/context.py

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def __init__(self, resp_queue, error_queue, server_address):
4848
self.error_queue = error_queue
4949
super().__init__(server_address, WebhookHandler)
5050

51+
def server_bind(self):
52+
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
53+
self.socket.bind(self.server_address)
54+
5155
class HGECtx:
5256
def __init__(self, hge_url, pg_url):
5357
server_address = ('0.0.0.0', 5592)
@@ -127,5 +131,7 @@ def teardown(self):
127131
self.http.close()
128132
self.engine.dispose()
129133
self.httpd.shutdown()
134+
self.httpd.server_close()
135+
self.ws.close()
130136
self.web_server.join()
131137
self.wst.join()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
type: bulk
2+
args:
3+
4+
#Author table
5+
- type: run_sql
6+
args:
7+
sql: |
8+
create table author(
9+
id serial primary key,
10+
name text unique
11+
);
12+
- type: track_table
13+
args:
14+
schema: public
15+
name: author
16+
17+
#Article table
18+
- type: run_sql
19+
args:
20+
sql: |
21+
CREATE TABLE article (
22+
id SERIAL PRIMARY KEY,
23+
title TEXT,
24+
content TEXT,
25+
author_id INTEGER NOT NULL REFERENCES author(id),
26+
is_published BOOLEAN,
27+
published_on TIMESTAMP
28+
)
29+
- type: track_table
30+
args:
31+
schema: public
32+
name: article
33+
34+
#Object relationship
35+
- type: create_object_relationship
36+
args:
37+
table: article
38+
name: author
39+
using:
40+
foreign_key_constraint_on: author_id
41+
42+
#Array relationship
43+
- type: create_array_relationship
44+
args:
45+
table: author
46+
name: articles
47+
using:
48+
foreign_key_constraint_on:
49+
table: article
50+
column: author_id
51+
52+
#Insert Author table data
53+
- type: insert
54+
args:
55+
table: author
56+
objects:
57+
- name: Author 1
58+
- name: Author 2
59+
60+
#Insert aticle table data
61+
- type: insert
62+
args:
63+
table: article
64+
objects:
65+
- content: Sample article content 1
66+
title: Article 1
67+
author_id: 1
68+
- content: Sample article content 2
69+
title: Article 2
70+
author_id: 1
71+
- content: Sample article content 3
72+
author_id: 1
73+
title: Article 3
74+
- content: Sample article content 4
75+
author_id: 2
76+
title: Article 4
77+
- content: Sample article content 5
78+
author_id: 2
79+
title: Article 5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type: bulk
2+
args:
3+
#Drop relationship first
4+
- type: drop_relationship
5+
args:
6+
relationship: articles
7+
table:
8+
schema: public
9+
name: author
10+
11+
- type: run_sql
12+
args:
13+
sql: |
14+
drop table article
15+
- type: run_sql
16+
args:
17+
sql: |
18+
drop table author
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
description: A user can delete his articles
2+
url: /v1alpha1/graphql
3+
status: 200
4+
headers:
5+
X-Hasura-Role: user
6+
X-Hasura-User-Id: '1'
7+
response:
8+
data:
9+
delete_article:
10+
affected_rows: 1
11+
returning:
12+
- author_id: 1
13+
id: 1
14+
title: Article 1
15+
content: Sample article content 1
16+
query:
17+
query: |
18+
mutation delete_article {
19+
delete_article (
20+
where: {id: {_eq: 1}}
21+
) {
22+
affected_rows
23+
returning{
24+
id
25+
title
26+
content
27+
author_id
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
description: A user cannot delete other users articles
2+
url: /v1alpha1/graphql
3+
status: 200
4+
headers:
5+
X-Hasura-Role: user
6+
X-Hasura-User-Id: '5'
7+
response:
8+
data:
9+
delete_article:
10+
affected_rows: 0
11+
returning: []
12+
query:
13+
query: |
14+
mutation delete_article {
15+
delete_article (
16+
where: {id: {_eq: 1}}
17+
)
18+
{ affected_rows
19+
returning
20+
{ id
21+
title
22+
content
23+
author_id
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
type: bulk
2+
args:
3+
4+
#Author table
5+
- type: run_sql
6+
args:
7+
sql: |
8+
create table author(
9+
id serial primary key,
10+
name text unique,
11+
payments_done boolean not null default false
12+
);
13+
- type: track_table
14+
args:
15+
schema: public
16+
name: author
17+
18+
#Article table
19+
- type: run_sql
20+
args:
21+
sql: |
22+
CREATE TABLE article (
23+
id SERIAL PRIMARY KEY,
24+
title TEXT,
25+
content TEXT,
26+
author_id INTEGER NOT NULL REFERENCES author(id),
27+
is_published BOOLEAN,
28+
published_on TIMESTAMP
29+
)
30+
- type: track_table
31+
args:
32+
schema: public
33+
name: article
34+
35+
#Object relationship
36+
- type: create_object_relationship
37+
args:
38+
table: article
39+
name: author
40+
using:
41+
foreign_key_constraint_on: author_id
42+
43+
#Array relationship
44+
- type: create_array_relationship
45+
args:
46+
table: author
47+
name: articles
48+
using:
49+
foreign_key_constraint_on:
50+
table: article
51+
column: author_id
52+
53+
#Insert Author table data
54+
- type: insert
55+
args:
56+
table: author
57+
objects:
58+
- name: Author 1
59+
- name: Author 2
60+
- name: Author 3
61+
payments_done: true
62+
63+
#Insert aticle table data
64+
- type: insert
65+
args:
66+
table: article
67+
objects:
68+
- content: Sample article content 1
69+
title: Article 1
70+
author_id: 1
71+
- content: Sample article content 2
72+
title: Article 2
73+
author_id: 1
74+
- content: Sample article content 3
75+
author_id: 1
76+
title: Article 3
77+
- content: Sample article content 4
78+
author_id: 2
79+
title: Article 4
80+
- content: Sample article content 5
81+
author_id: 2
82+
title: Article 5
83+
84+
#Prevent deletion if payments to the author is not yet done
85+
- type: create_delete_permission
86+
args:
87+
table: author
88+
role: user
89+
permission:
90+
filter:
91+
$and:
92+
- id: X-HASURA-USER-ID
93+
- payments_done: true
94+
95+
96+
#A user can delete only his articles
97+
- type: create_select_permission
98+
args:
99+
table: article
100+
role: user
101+
permission:
102+
columns:
103+
- id
104+
- title
105+
- content
106+
- author_id
107+
filter:
108+
$and:
109+
- author_id: X-HASURA-USER-ID
110+
111+
#A user can delete only his articles
112+
- type: create_delete_permission
113+
args:
114+
table: article
115+
role: user
116+
permission:
117+
filter:
118+
$and:
119+
- author_id: X-HASURA-USER-ID
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
type: bulk
2+
args:
3+
#Drop relationship first
4+
- type: drop_relationship
5+
args:
6+
relationship: articles
7+
table:
8+
schema: public
9+
name: author
10+
11+
- type: run_sql
12+
args:
13+
sql: |
14+
drop table article
15+
- type: run_sql
16+
args:
17+
sql: |
18+
drop table author

server/tests-py/queries/graphql_mutation/insert/constraints/setup.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
type: bulk
22
args:
33

4+
#Author table
5+
- type: run_sql
6+
args:
7+
sql: |
8+
create table author(
9+
id serial primary key,
10+
name text unique
11+
);
12+
- type: track_table
13+
args:
14+
schema: public
15+
name: author
16+
417
#Create resident table
518
- type: run_sql
619
args:

server/tests-py/queries/graphql_mutation/insert/constraints/teardown.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
type: bulk
22
args:
33

4+
- type: run_sql
5+
args:
6+
sql: |
7+
drop table author
8+
49
- type: run_sql
510
args:
611
sql: |

0 commit comments

Comments
 (0)