Skip to content

Commit 0fb2782

Browse files
authored
Merge pull request #163 from zhenlineo/1.3-auth-example
1.3 auth example
2 parents e3bb3db + 4216741 commit 0fb2782

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

test/examples/auth_example.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# See the License for the specific language governing permissions and
1919
# limitations under the License.
2020

21-
from neo4j.v1 import GraphDatabase, kerberos_auth
21+
from neo4j.v1 import GraphDatabase, kerberos_auth, custom_auth
2222

2323

2424
class BasicAuthExample:
@@ -47,9 +47,13 @@ def close(self):
4747

4848
class CustomAuthExample:
4949
# tag::custom-auth[]
50-
def __init__(self, uri, principal, credentials, realm, scheme, parameters):
51-
self._driver = GraphDatabase.driver( uri, auth=(principal, credentials, realm, scheme, parameters))
50+
def __init__(self, uri, principal, credentials, realm, scheme, **parameters):
51+
self._driver = GraphDatabase.driver(uri, auth=custom_auth(principal, credentials, realm, scheme, **parameters))
5252
# end::custom-auth[]
5353

5454
def close(self):
5555
self._driver.close()
56+
57+
def can_connect(self):
58+
record_list = list(self._driver.session().run("RETURN 1"))
59+
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.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)