Skip to content

Commit d5f0db7

Browse files
committed
Added steps for error handling
1 parent b35109e commit d5f0db7

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
# Copyright (c) 2002-2016 "Neo Technology,"
5+
# Network Engine for Objects in Lund AB [http://neotechnology.com]
6+
#
7+
# This file is part of Neo4j.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License");
10+
# you may not use this file except in compliance with the License.
11+
# You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS,
17+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
# See the License for the specific language governing permissions and
19+
# limitations under the License.
20+
21+
from behave import *
22+
23+
from neo4j.v1.exceptions import ProtocolError, CypherError
24+
from test.tck import tck_util
25+
26+
from neo4j.v1 import compat, GraphDatabase, basic_auth
27+
28+
use_step_matcher("re")
29+
30+
31+
@given("I have a driver")
32+
def step_impl(context):
33+
context.driver = tck_util.driver
34+
35+
36+
@step("I start a `Transaction` through a session")
37+
def step_impl(context):
38+
context.session = context.driver.session()
39+
context.session.begin_transaction()
40+
41+
42+
@step("`run` a query with that same session without closing the transaction first")
43+
def step_impl(context):
44+
try:
45+
context.session.run("CREATE (:n)")
46+
except Exception as e:
47+
context.exception = e
48+
49+
50+
@step("I start a new `Transaction` with the same session before closing the previous")
51+
def step_impl(context):
52+
try:
53+
context.session.begin_transaction()
54+
except Exception as e:
55+
context.exception = e
56+
57+
58+
@step("I run a non valid cypher statement")
59+
def step_impl(context):
60+
try:
61+
context.driver.session().run("NOT VALID").consume()
62+
except Exception as e:
63+
context.exception = e
64+
65+
66+
@step("I set up a driver to an incorrect port")
67+
def step_impl(context):
68+
try:
69+
context.driver = GraphDatabase.driver("bolt://localhost:7777")
70+
context.driver.session()
71+
except Exception as e:
72+
context.exception = e
73+
74+
75+
@step("I set up a driver with wrong scheme")
76+
def step_impl(context):
77+
try:
78+
context.driver = GraphDatabase.driver("wrong://localhost")
79+
context.driver.session()
80+
except Exception as e:
81+
context.exception = e
82+
83+
84+
@step("it throws a `ClientException`")
85+
def step_impl(context):
86+
assert context.exception is not None
87+
assert type(context.exception) == ProtocolError or type(context.exception) == CypherError
88+
assert isinstance(context.exception, ProtocolError) or isinstance(context.exception, CypherError)
89+
assert str(context.exception).startswith(context.table.rows[0][0])

0 commit comments

Comments
 (0)