Skip to content

Commit

Permalink
feat: upload testcases to SQLAuto server (#4666)
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon authored Sep 21, 2022
1 parent f92c24c commit 5c20d8d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
11 changes: 9 additions & 2 deletions tests/common/nebula_test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# from nebula3.gclient.net import ConnectionPool
# from nebula3.Config import Config
from nebula3.graph import ttypes

from tests.common import utils
from tests.common.configs import get_delay_time
from tests.common.utils import (
compare_value,
Expand Down Expand Up @@ -152,11 +154,16 @@ def release_nebula_client(self, client):
# self.client.release()
# self.close_nebula_clients()


@classmethod
def execute(self, ngql, profile=True):
return self.client.execute(
def execute(self, ngql, profile=True, space_name=None):
resp = self.client.execute(
'PROFILE {{{}}}'.format(ngql) if profile else ngql)

utils.upload_2_sqlauto(ngql, resp, space_name)
return resp


@classmethod
def check_rows_with_header(cls, stmt: str, expected: dict):
resp = cls.execute(stmt)
Expand Down
64 changes: 64 additions & 0 deletions tests/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import random
import string
import time

import requests
import yaml
from typing import Pattern

Expand Down Expand Up @@ -472,3 +474,65 @@ def get_ssl_config(is_graph_ssl: bool, ca_signed: bool):
ssl_config.certfile = os.path.join(NEBULA_HOME, 'tests/cert/test.derive.crt')
ssl_config.keyfile = os.path.join(NEBULA_HOME, 'tests/cert/test.derive.key')
return ssl_config


sqlauto_cookies = None


def upload_2_sqlauto(ngql, resp, space_name=None):
try: # Upload testcases and their responses to SQLAuto Server
key_code = "code"
host = "http://apijson.cn:8080"
code_success = 200

global sqlauto_cookies

if sqlauto_cookies is None:
login_resp = requests.post(host + "/login", json={
"phone": "13000082005",
"password": "123456",
"remember": True
})
sqlauto_cookies = login_resp.cookies

exist_resp = requests.post(host + "/get/Document", json={
"url": "/" + ("" if space_name is None else space_name),
"sqlauto": ngql,
}, cookies=sqlauto_cookies)

exist_resp = {key_code: exist_resp.status_code} if exist_resp.status_code != code_success else exist_resp.json()

is_doc = exist_resp.get(key_code) != code_success or exist_resp.get("Document") is None
upload_resp = requests.post(host + "/post", json={
"format": False,
"Document": {
"testAccountId": None,
"name": ngql if len(ngql) <= 20 else (ngql[:16] + "..."),
"type": "JSON",
"url": "/" + space_name,
"request": "{}",
"sqlauto": ngql,
"standard": None,
"header": ""
} if is_doc else None,
"TestRecord": {
"randomId": 0,
"host": "jdbc:nebula://localhost:9669",
"testAccountId": None,
"response": ('{"code":200,msg:"success","list":' + json.dumps(resp.rows) + '}')
if resp.is_succeeded else ('{"code":' + resp.error_code + ',msg:' + resp.error_msg + '}'),
"standard": None
},
"tag": "Document" if is_doc else "TestRecord"
}, cookies=sqlauto_cookies)

result = {key_code: upload_resp.status_code} if upload_resp.status_code != code_success else upload_resp.json()
if result.get(key_code) != code_success:
print("\n\nupload case to SQLAuto server failed: statusCode: " + upload_resp.status_code
+ ", responseText: " + upload_resp.text + "\n\n")
except Exception as e:
print("\n\nupload case to SQLAuto server failed: {}".format(e))


if __name__ == "__main__":
upload_2_sqlauto("show hosts;", requests.Response(), "testSpace")
8 changes: 7 additions & 1 deletion tests/tck/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from nebula3.Exception import AuthFailedException
from pytest_bdd import given, parsers, then, when

from tests.common import utils
from tests.common.dataset_printer import DataSetPrinter
from tests.common.comparator import DataSetComparator, CmpType
from tests.common.plan_differ import PlanDiffer
Expand Down Expand Up @@ -271,9 +272,14 @@ def exec_query(request, ngql, exec_ctx, sess=None, need_try: bool = False):
ngql = normalize_outline_scenario(request, ngql)
if sess is None:
sess = exec_ctx.get('current_session')
exec_ctx['result_set'] = response(sess, ngql, need_try)

resp = response(sess, ngql, need_try)
exec_ctx['result_set'] = resp
exec_ctx['ngql'] = ngql

space_desc = exec_ctx.get("space_desc", None)
utils.upload_2_sqlauto(ngql, resp, None if space_desc is None else space_desc.name)


@given(
parse(
Expand Down

0 comments on commit 5c20d8d

Please sign in to comment.