Skip to content

Commit 3a5781d

Browse files
authored
Merge pull request #162 from zhenlineo/1.2-auth-examples
Added test for custom auth
2 parents 76b0725 + 66d8c63 commit 3a5781d

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

test/examples/basic_auth_example.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from neo4j.v1 import GraphDatabase
2323
# end::basic-auth-import[]
2424

25+
2526
class BasicAuthExample:
2627
# tag::basic-auth[]
2728
def __init__(self, uri, user, password):

test/examples/custom_auth_example.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@
1919
# limitations under the License.
2020

2121
# tag::custom-auth-import[]
22-
from neo4j.v1 import GraphDatabase;
22+
from neo4j.v1 import GraphDatabase, custom_auth
2323
# end::custom-auth-import[]
2424

25+
2526
class CustomAuthExample:
2627
# tag::custom-auth[]
27-
def __init__(self, uri, principal, credentials, realm, scheme, parameters):
28-
self._driver = GraphDatabase.driver( uri, auth=(principal, credentials, realm, scheme, parameters))
28+
def __init__(self, uri, principal, credentials, realm, scheme, **parameters):
29+
self._driver = GraphDatabase.driver(uri, auth=custom_auth(principal, credentials, realm, scheme, **parameters))
2930
# end::custom-auth[]
3031

3132
def close(self):
3233
self._driver.close()
34+
35+
def can_connect(self):
36+
record_list = list(self._driver.session().run("RETURN 1"))
37+
return int(record_list[0][0]) == 1

test/examples/test_examples.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def test_basic_auth_example(self):
6161

6262
self.assertTrue(example.can_connect())
6363

64+
def test_custom_auth_example(self):
65+
from test.examples.custom_auth_example import CustomAuthExample
66+
67+
example = CustomAuthExample(self.bolt_uri, self.user, self.password, None, "basic", **{"key":"value"})
68+
69+
self.assertTrue(example.can_connect())
70+
6471
def test_config_unencrypted_example(self):
6572
from test.examples.config_unencrypted_example import ConfigUnencryptedExample
6673

0 commit comments

Comments
 (0)