2017-03-20 20:32:09 +08:00
|
|
|
import logging
|
|
|
|
import datetime
|
|
|
|
import time
|
|
|
|
import json
|
2017-03-14 17:17:52 +08:00
|
|
|
from steps.test_parameters import TestParameters
|
|
|
|
from neo4j.v1 import GraphDatabase, basic_auth
|
|
|
|
from steps.graph_properties import GraphProperties
|
|
|
|
from test_results import TestResults
|
|
|
|
|
|
|
|
test_results = TestResults()
|
|
|
|
|
2017-03-20 20:32:09 +08:00
|
|
|
|
2017-03-14 17:17:52 +08:00
|
|
|
def before_scenario(context, step):
|
|
|
|
context.test_parameters = TestParameters()
|
|
|
|
context.graph_properties = GraphProperties()
|
|
|
|
context.exception = None
|
|
|
|
|
2017-03-20 20:32:09 +08:00
|
|
|
|
2017-03-14 17:17:52 +08:00
|
|
|
def after_scenario(context, scenario):
|
|
|
|
test_results.add_test(scenario.status)
|
|
|
|
|
2017-03-20 20:32:09 +08:00
|
|
|
|
2017-03-14 17:17:52 +08:00
|
|
|
def before_all(context):
|
|
|
|
set_logging(context)
|
|
|
|
context.driver = create_db_driver(context)
|
2017-03-20 20:32:09 +08:00
|
|
|
|
|
|
|
|
2017-03-14 17:17:52 +08:00
|
|
|
def after_all(context):
|
|
|
|
ts = time.time()
|
|
|
|
timestamp = datetime.datetime.fromtimestamp(ts).strftime("%Y_%m_%d__%H_%M")
|
2017-03-20 20:32:09 +08:00
|
|
|
|
|
|
|
root = context.config.root
|
|
|
|
|
|
|
|
if root.endswith("/"):
|
|
|
|
root = root[0:len(root) - 1]
|
|
|
|
if root.endswith("features"):
|
|
|
|
root = root[0: len(root) - len("features") - 1]
|
|
|
|
|
|
|
|
test_suite = root.split('/')[-1]
|
|
|
|
file_name = context.config.output_folder + timestamp + \
|
|
|
|
"-" + context.config.database + "-" + test_suite + ".json"
|
|
|
|
|
|
|
|
js = {
|
|
|
|
"total": test_results.num_total(), "passed": test_results.num_passed(),
|
|
|
|
"test_suite": test_suite, "timestamp": timestamp, "db": context.config.database}
|
2017-03-14 17:17:52 +08:00
|
|
|
with open(file_name, 'w') as f:
|
|
|
|
json.dump(js, f)
|
|
|
|
|
2017-03-20 20:32:09 +08:00
|
|
|
|
2017-03-14 17:17:52 +08:00
|
|
|
def set_logging(context):
|
|
|
|
logging.basicConfig(level="DEBUG")
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
context.log = log
|
|
|
|
|
2017-03-20 20:32:09 +08:00
|
|
|
|
2017-03-14 17:17:52 +08:00
|
|
|
def create_db_driver(context):
|
|
|
|
uri = context.config.database_uri
|
2017-03-20 20:32:09 +08:00
|
|
|
auth_token = basic_auth(
|
|
|
|
context.config.database_username, context.config.database_password)
|
2017-03-17 17:27:01 +08:00
|
|
|
if context.config.database == "neo4j" or context.config.database == "memgraph":
|
|
|
|
driver = GraphDatabase.driver(uri, auth=auth_token, encrypted=0)
|
2017-03-14 17:17:52 +08:00
|
|
|
else:
|
2017-03-17 17:27:01 +08:00
|
|
|
raise "Unsupported database type"
|
2017-03-14 17:17:52 +08:00
|
|
|
return driver
|