2018-09-18 09:21:57 +03:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import queue
|
2018-09-19 15:12:57 +03:00
|
|
|
import time
|
2020-02-13 12:14:02 +03:00
|
|
|
from validate import check_query_f, check_event
|
|
|
|
|
|
|
|
usefixtures = pytest.mark.usefixtures
|
|
|
|
|
|
|
|
# Every test in this class requires the events webhook to be running first
|
|
|
|
# We are also going to mark as server upgrade tests are allowed
|
|
|
|
# A few tests are going to be excluded with skip_server_upgrade_test mark
|
|
|
|
pytestmark = [usefixtures('evts_webhook'), pytest.mark.allow_server_upgrade_test]
|
2018-10-30 12:21:58 +03:00
|
|
|
|
2018-09-19 15:12:57 +03:00
|
|
|
def select_last_event_fromdb(hge_ctx):
|
|
|
|
q = {
|
|
|
|
"type": "select",
|
|
|
|
"args": {
|
|
|
|
"table": {"schema": "hdb_catalog", "name": "event_log"},
|
|
|
|
"columns": ["*"],
|
|
|
|
"order_by": ["-created_at"],
|
|
|
|
"limit": 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
st_code, resp = hge_ctx.v1q(q)
|
|
|
|
return st_code, resp
|
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
|
2019-01-28 09:12:52 +03:00
|
|
|
def insert(hge_ctx, table, row, returning=[], headers = {}):
|
2018-09-19 15:12:57 +03:00
|
|
|
q = {
|
|
|
|
"type": "insert",
|
|
|
|
"args": {
|
|
|
|
"table": table,
|
|
|
|
"objects": [row],
|
|
|
|
"returning": returning
|
|
|
|
}
|
|
|
|
}
|
2019-01-28 09:12:52 +03:00
|
|
|
st_code, resp = hge_ctx.v1q(q, headers = headers)
|
2018-09-19 15:12:57 +03:00
|
|
|
return st_code, resp
|
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
|
2019-01-28 09:12:52 +03:00
|
|
|
def update(hge_ctx, table, where_exp, set_exp, headers = {}):
|
2018-09-19 15:12:57 +03:00
|
|
|
q = {
|
|
|
|
"type": "update",
|
|
|
|
"args": {
|
|
|
|
"table": table,
|
|
|
|
"where": where_exp,
|
|
|
|
"$set": set_exp
|
|
|
|
}
|
|
|
|
}
|
2019-01-28 09:12:52 +03:00
|
|
|
st_code, resp = hge_ctx.v1q(q, headers = headers)
|
2018-09-19 15:12:57 +03:00
|
|
|
return st_code, resp
|
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
|
2019-01-28 09:12:52 +03:00
|
|
|
def delete(hge_ctx, table, where_exp, headers = {}):
|
2018-09-19 15:12:57 +03:00
|
|
|
q = {
|
|
|
|
"type": "delete",
|
|
|
|
"args": {
|
|
|
|
"table": table,
|
|
|
|
"where": where_exp
|
|
|
|
}
|
|
|
|
}
|
2019-01-28 09:12:52 +03:00
|
|
|
st_code, resp = hge_ctx.v1q(q, headers = headers)
|
2018-09-19 15:12:57 +03:00
|
|
|
return st_code, resp
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures("per_method_tests_db_state")
|
|
|
|
class TestCreateAndDelete:
|
2018-12-19 09:34:27 +03:00
|
|
|
|
|
|
|
def test_create_delete(self, hge_ctx):
|
|
|
|
check_query_f(hge_ctx, self.dir() + "/create_and_delete.yaml")
|
|
|
|
|
|
|
|
def test_create_reset(self, hge_ctx):
|
|
|
|
check_query_f(hge_ctx, self.dir() + "/create_and_reset.yaml")
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
# Can't run server upgrade tests, as this test has a schema change
|
|
|
|
@pytest.mark.skip_server_upgrade_test
|
2019-02-01 12:37:38 +03:00
|
|
|
def test_create_operation_spec_not_provider_err(self, hge_ctx):
|
|
|
|
check_query_f(hge_ctx, self.dir() + "/create_trigger_operation_specs_not_provided_err.yaml")
|
|
|
|
|
2018-12-19 09:34:27 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/create-delete'
|
2018-09-19 15:12:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures("per_method_tests_db_state")
|
2018-09-19 15:12:57 +03:00
|
|
|
class TestCreateEvtQuery(object):
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/basic'
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_basic(self, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
|
|
|
"new": init_row
|
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "INSERT", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c2": "world"}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": init_row,
|
2018-10-30 12:21:58 +03:00
|
|
|
"new": {"c1": 1, "c2": "world"}
|
2018-09-18 09:21:57 +03:00
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "UPDATE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
|
|
|
exp_ev_data = {
|
2018-10-30 12:21:58 +03:00
|
|
|
"old": {"c1": 1, "c2": "world"},
|
2018-09-18 09:21:57 +03:00
|
|
|
"new": None
|
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = delete(hge_ctx, table, where_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "DELETE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_method_tests_db_state')
|
2018-09-19 15:12:57 +03:00
|
|
|
class TestRetryConf(object):
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/retry_conf'
|
2018-09-19 15:12:57 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_basic(self, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
2018-09-19 15:12:57 +03:00
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
2018-09-19 15:12:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
|
|
|
"new": init_row
|
|
|
|
}
|
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
time.sleep(15)
|
2019-04-08 10:22:38 +03:00
|
|
|
tries = evts_webhook.get_error_queue_size()
|
2018-09-19 15:12:57 +03:00
|
|
|
assert tries == 5, tries
|
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_timeout_short(self, hge_ctx, evts_webhook):
|
2019-02-14 10:37:59 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t2"}
|
|
|
|
|
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
|
|
|
"new": init_row
|
|
|
|
}
|
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
time.sleep(20)
|
2019-04-08 10:22:38 +03:00
|
|
|
tries = evts_webhook.get_error_queue_size()
|
2019-02-14 10:37:59 +03:00
|
|
|
assert tries == 3, tries
|
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_timeout_long(self, hge_ctx, evts_webhook):
|
2019-02-14 10:37:59 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t3"}
|
|
|
|
|
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
|
|
|
"new": init_row
|
|
|
|
}
|
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
time.sleep(15)
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t3_timeout_long", table, "INSERT", exp_ev_data, webhook_path = "/timeout_long")
|
2018-10-30 12:21:58 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_method_tests_db_state')
|
2018-09-24 14:50:11 +03:00
|
|
|
class TestEvtHeaders(object):
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/headers'
|
2018-09-24 14:50:11 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_basic(self, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
2018-09-24 14:50:11 +03:00
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
2018-09-24 14:50:11 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
|
|
|
"new": init_row
|
|
|
|
}
|
|
|
|
headers = {"X-Header-From-Value": "MyValue", "X-Header-From-Env": "MyEnvValue"}
|
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "INSERT", exp_ev_data, headers = headers)
|
2018-09-24 14:50:11 +03:00
|
|
|
|
2018-09-19 15:12:57 +03:00
|
|
|
class TestUpdateEvtQuery(object):
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
2019-04-08 10:22:38 +03:00
|
|
|
def transact(self, request, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
print("In setup method")
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = hge_ctx.v1q_f('queries/event_triggers/update_query/create-setup.yaml')
|
|
|
|
assert st_code == 200, resp
|
|
|
|
st_code, resp = hge_ctx.v1q_f('queries/event_triggers/update_query/update-setup.yaml')
|
|
|
|
assert st_code == 200, '{}'.format(resp)
|
2019-04-05 15:20:46 +03:00
|
|
|
assert resp[1][0]["configuration"]["webhook"] == 'http://127.0.0.1:5592/new'
|
2018-09-19 15:12:57 +03:00
|
|
|
yield
|
|
|
|
st_code, resp = hge_ctx.v1q_f('queries/event_triggers/update_query/teardown.yaml')
|
|
|
|
assert st_code == 200, resp
|
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_update_basic(self, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
2018-09-19 15:12:57 +03:00
|
|
|
|
2019-09-13 02:22:01 +03:00
|
|
|
init_row = {"c1": 1, "c2": "hello", "c3": {"name": "clarke"}}
|
2018-09-19 15:12:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
2019-09-13 02:22:01 +03:00
|
|
|
"new": {"c1": 1, "c2": "hello", "c3": {"name": "clarke"}}
|
2018-09-19 15:12:57 +03:00
|
|
|
}
|
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
2018-12-15 08:05:29 +03:00
|
|
|
with pytest.raises(queue.Empty):
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "INSERT", exp_ev_data, webhook_path = "/new")
|
2018-09-19 15:12:57 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c2": "world"}
|
2018-10-25 10:22:51 +03:00
|
|
|
# expected no event hence previous expected data
|
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
with pytest.raises(queue.Empty):
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "UPDATE", exp_ev_data, webhook_path = "/new")
|
2018-10-25 10:22:51 +03:00
|
|
|
|
2019-09-13 02:22:01 +03:00
|
|
|
where_exp = {"c1": 1}
|
|
|
|
set_exp = {"c3": {"name": "bellamy"}}
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": {"c1": 1, "c2": "world", "c3": {"name": "clarke"}},
|
|
|
|
"new": {"c1": 1, "c2": "world", "c3": {"name": "bellamy"}}
|
|
|
|
}
|
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "UPDATE", exp_ev_data, webhook_path ="/new")
|
|
|
|
|
2018-10-25 10:22:51 +03:00
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c1": 2}
|
2018-09-19 15:12:57 +03:00
|
|
|
exp_ev_data = {
|
2019-09-13 02:22:01 +03:00
|
|
|
"old": {"c1": 1, "c2": "world", "c3": {"name": "bellamy"}},
|
|
|
|
"new": {"c1": 2, "c2": "world", "c3": {"name": "bellamy"}}
|
2018-09-19 15:12:57 +03:00
|
|
|
}
|
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "UPDATE", exp_ev_data, webhook_path ="/new")
|
2018-09-19 15:12:57 +03:00
|
|
|
|
2018-10-25 10:22:51 +03:00
|
|
|
where_exp = {"c1": 2}
|
2018-09-19 15:12:57 +03:00
|
|
|
exp_ev_data = {
|
2019-09-13 02:22:01 +03:00
|
|
|
"old": {"c1": 2, "c2": "world", "c3": {"name": "bellamy"}},
|
2018-09-19 15:12:57 +03:00
|
|
|
"new": None
|
|
|
|
}
|
|
|
|
st_code, resp = delete(hge_ctx, table, where_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "DELETE", exp_ev_data, webhook_path = "/new")
|
2018-09-19 15:12:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_method_tests_db_state')
|
2018-09-19 15:12:57 +03:00
|
|
|
class TestDeleteEvtQuery(object):
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
directory = 'queries/event_triggers'
|
|
|
|
|
|
|
|
setup_files = [
|
|
|
|
directory + '/basic/setup.yaml',
|
|
|
|
directory + '/delete_query/setup.yaml'
|
|
|
|
]
|
|
|
|
|
|
|
|
teardown_files = [ directory + '/delete_query/teardown.yaml']
|
2018-09-19 15:12:57 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_delete_basic(self, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
2018-09-19 15:12:57 +03:00
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
2018-09-19 15:12:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
|
|
|
"new": init_row
|
|
|
|
}
|
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
with pytest.raises(queue.Empty):
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "INSERT", exp_ev_data)
|
2018-09-19 15:12:57 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c2": "world"}
|
2018-09-19 15:12:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": init_row,
|
2018-10-30 12:21:58 +03:00
|
|
|
"new": {"c1": 1, "c2": "world"}
|
2018-09-19 15:12:57 +03:00
|
|
|
}
|
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
with pytest.raises(queue.Empty):
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "UPDATE", exp_ev_data)
|
2018-09-19 15:12:57 +03:00
|
|
|
|
|
|
|
exp_ev_data = {
|
2018-10-30 12:21:58 +03:00
|
|
|
"old": {"c1": 1, "c2": "world"},
|
2018-09-19 15:12:57 +03:00
|
|
|
"new": None
|
|
|
|
}
|
|
|
|
st_code, resp = delete(hge_ctx, table, where_exp)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
with pytest.raises(queue.Empty):
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "DELETE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_class_tests_db_state')
|
2018-09-18 09:21:57 +03:00
|
|
|
class TestEvtSelCols:
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/selected_cols'
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_selected_cols(self, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
2018-10-25 10:22:51 +03:00
|
|
|
"new": {"c1": 1, "c2": "hello"}
|
2018-09-18 09:21:57 +03:00
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "INSERT", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c2": "world"}
|
2018-10-25 10:22:51 +03:00
|
|
|
# expected no event hence previous expected data
|
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
with pytest.raises(queue.Empty):
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "UPDATE", exp_ev_data)
|
2018-10-25 10:22:51 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c1": 2}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
2018-10-30 12:21:58 +03:00
|
|
|
"old": {"c1": 1, "c2": "world"},
|
|
|
|
"new": {"c1": 2, "c2": "world"}
|
2018-09-18 09:21:57 +03:00
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "UPDATE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2018-10-25 10:22:51 +03:00
|
|
|
where_exp = {"c1": 2}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
2018-10-30 12:21:58 +03:00
|
|
|
"old": {"c1": 2, "c2": "world"},
|
2018-09-18 09:21:57 +03:00
|
|
|
"new": None
|
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = delete(hge_ctx, table, where_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_cols", table, "DELETE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@pytest.mark.skip_server_upgrade_test
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_selected_cols_dep(self, hge_ctx, evts_webhook):
|
2018-09-18 09:21:57 +03:00
|
|
|
st_code, resp = hge_ctx.v1q({
|
|
|
|
"type": "run_sql",
|
|
|
|
"args": {
|
|
|
|
"sql": "alter table hge_tests.test_t1 drop column c1"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
assert st_code == 400, resp
|
|
|
|
assert resp['code'] == "dependency-error", resp
|
|
|
|
|
|
|
|
st_code, resp = hge_ctx.v1q({
|
|
|
|
"type": "run_sql",
|
|
|
|
"args": {
|
|
|
|
"sql": "alter table hge_tests.test_t1 drop column c2"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
assert st_code == 200, resp
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_method_tests_db_state')
|
2018-10-25 10:22:51 +03:00
|
|
|
class TestEvtInsertOnly:
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/insert_only'
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_insert_only(self, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
2018-10-25 10:22:51 +03:00
|
|
|
"new": init_row
|
2018-09-18 09:21:57 +03:00
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_insert", table, "INSERT", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c2": "world"}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
2018-10-25 10:22:51 +03:00
|
|
|
"old": init_row,
|
2018-10-30 12:21:58 +03:00
|
|
|
"new": {"c1": 1, "c2": "world"}
|
2018-09-18 09:21:57 +03:00
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
2018-10-25 10:22:51 +03:00
|
|
|
with pytest.raises(queue.Empty):
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_insert", table, "UPDATE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
|
|
|
exp_ev_data = {
|
2018-10-30 12:21:58 +03:00
|
|
|
"old": {"c1": 1, "c2": "world"},
|
2018-09-18 09:21:57 +03:00
|
|
|
"new": None
|
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = delete(hge_ctx, table, where_exp)
|
|
|
|
assert st_code == 200, resp
|
2018-10-25 10:22:51 +03:00
|
|
|
with pytest.raises(queue.Empty):
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_insert", table, "DELETE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_class_tests_db_state')
|
2018-10-25 10:22:51 +03:00
|
|
|
class TestEvtSelPayload:
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/selected_payload'
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_selected_payload(self, hge_ctx, evts_webhook):
|
2018-10-30 12:21:58 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2018-10-30 12:21:58 +03:00
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
2018-10-25 10:22:51 +03:00
|
|
|
"new": {"c1": 1, "c2": "hello"}
|
2018-09-18 09:21:57 +03:00
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_payload", table, "INSERT", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c2": "world"}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
2018-10-25 10:22:51 +03:00
|
|
|
"old": {"c1": 1},
|
|
|
|
"new": {"c1": 1}
|
2018-09-18 09:21:57 +03:00
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_payload", table, "UPDATE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2018-10-25 10:22:51 +03:00
|
|
|
where_exp = {"c1": 1}
|
2018-10-30 12:21:58 +03:00
|
|
|
set_exp = {"c1": 2}
|
2018-09-18 09:21:57 +03:00
|
|
|
exp_ev_data = {
|
2018-10-25 10:22:51 +03:00
|
|
|
"old": {"c1": 1},
|
|
|
|
"new": {"c1": 2}
|
|
|
|
}
|
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_payload", table, "UPDATE", exp_ev_data)
|
2018-10-25 10:22:51 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 2}
|
|
|
|
exp_ev_data = {
|
2018-10-30 12:21:58 +03:00
|
|
|
"old": {"c2": "world"},
|
2018-09-18 09:21:57 +03:00
|
|
|
"new": None
|
|
|
|
}
|
2018-09-19 15:12:57 +03:00
|
|
|
st_code, resp = delete(hge_ctx, table, where_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_payload", table, "DELETE", exp_ev_data)
|
2018-09-18 09:21:57 +03:00
|
|
|
|
2018-10-25 10:22:51 +03:00
|
|
|
def test_selected_payload_dep(self, hge_ctx):
|
|
|
|
st_code, resp = hge_ctx.v1q({
|
|
|
|
"type": "run_sql",
|
|
|
|
"args": {
|
|
|
|
"sql": "alter table hge_tests.test_t1 drop column c1"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
assert st_code == 400, resp
|
|
|
|
assert resp['code'] == "dependency-error", resp
|
|
|
|
|
|
|
|
st_code, resp = hge_ctx.v1q({
|
|
|
|
"type": "run_sql",
|
|
|
|
"args": {
|
|
|
|
"sql": "alter table hge_tests.test_t1 drop column c2"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
assert st_code == 400, resp
|
|
|
|
assert resp['code'] == "dependency-error", resp
|
2018-11-14 10:13:01 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_method_tests_db_state')
|
2018-11-14 10:13:01 +03:00
|
|
|
class TestWebhookEnv(object):
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/webhook_env'
|
2018-11-14 10:13:01 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_basic(self, hge_ctx, evts_webhook):
|
2018-11-14 10:13:01 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
|
|
|
|
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
|
|
|
"new": init_row
|
|
|
|
}
|
|
|
|
st_code, resp = insert(hge_ctx, table, init_row)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "INSERT", exp_ev_data)
|
2018-11-14 10:13:01 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
|
|
|
set_exp = {"c2": "world"}
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": init_row,
|
|
|
|
"new": {"c1": 1, "c2": "world"}
|
|
|
|
}
|
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "UPDATE", exp_ev_data)
|
2019-01-28 09:12:52 +03:00
|
|
|
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": {"c1": 1, "c2": "world"},
|
|
|
|
"new": None
|
|
|
|
}
|
|
|
|
st_code, resp = delete(hge_ctx, table, where_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "DELETE", exp_ev_data)
|
2019-01-28 09:12:52 +03:00
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_method_tests_db_state')
|
2019-01-28 09:12:52 +03:00
|
|
|
class TestSessionVariables(object):
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/basic'
|
2019-01-28 09:12:52 +03:00
|
|
|
|
2019-04-08 10:22:38 +03:00
|
|
|
def test_basic(self, hge_ctx, evts_webhook):
|
2019-01-28 09:12:52 +03:00
|
|
|
table = {"schema": "hge_tests", "name": "test_t1"}
|
|
|
|
|
|
|
|
init_row = {"c1": 1, "c2": "hello"}
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": None,
|
|
|
|
"new": init_row
|
|
|
|
}
|
|
|
|
session_variables = { 'x-hasura-role': 'admin', 'x-hasura-allowed-roles': "['admin','user']", 'x-hasura-user-id': '1'}
|
|
|
|
st_code, resp = insert(hge_ctx, table, init_row, headers = session_variables)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "INSERT", exp_ev_data, session_variables = session_variables)
|
2019-01-28 09:12:52 +03:00
|
|
|
|
|
|
|
where_exp = {"c1": 1}
|
|
|
|
set_exp = {"c2": "world"}
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": init_row,
|
|
|
|
"new": {"c1": 1, "c2": "world"}
|
|
|
|
}
|
|
|
|
session_variables = { 'x-hasura-role': 'admin', 'x-hasura-random': 'some_random_info', 'X-Random-Header': 'not_session_variable'}
|
|
|
|
st_code, resp = update(hge_ctx, table, where_exp, set_exp, headers = session_variables)
|
|
|
|
assert st_code == 200, resp
|
|
|
|
session_variables.pop('X-Random-Header')
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "UPDATE", exp_ev_data, session_variables = session_variables)
|
2018-11-14 10:13:01 +03:00
|
|
|
|
|
|
|
exp_ev_data = {
|
|
|
|
"old": {"c1": 1, "c2": "world"},
|
|
|
|
"new": None
|
|
|
|
}
|
|
|
|
st_code, resp = delete(hge_ctx, table, where_exp)
|
|
|
|
assert st_code == 200, resp
|
2019-04-08 10:22:38 +03:00
|
|
|
check_event(hge_ctx, evts_webhook, "t1_all", table, "DELETE", exp_ev_data)
|
2019-05-13 12:41:07 +03:00
|
|
|
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@usefixtures('per_method_tests_db_state')
|
2019-05-13 12:41:07 +03:00
|
|
|
class TestManualEvents(object):
|
|
|
|
|
2020-02-13 12:14:02 +03:00
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return 'queries/event_triggers/manual_events'
|
2019-05-13 12:41:07 +03:00
|
|
|
|
|
|
|
def test_basic(self, hge_ctx, evts_webhook):
|
|
|
|
st_code, resp = hge_ctx.v1q_f('queries/event_triggers/manual_events/enabled.yaml')
|
|
|
|
assert st_code == 200, resp
|
|
|
|
st_code, resp = hge_ctx.v1q_f('queries/event_triggers/manual_events/disabled.yaml')
|
|
|
|
assert st_code == 400, resp
|