|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- encoding: utf-8 -*- |
| 3 | + |
| 4 | +# Copyright (c) 2002-2015 "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 | + |
| 22 | +from unittest import TestCase |
| 23 | + |
| 24 | +from neo4j.v1 import GraphDatabase |
| 25 | + |
| 26 | + |
| 27 | +class ExamplesTestCase(TestCase): |
| 28 | + |
| 29 | + def setUp(self): |
| 30 | + session = GraphDatabase.driver("bolt://localhost").session() |
| 31 | + session.run("MATCH (n) DETACH DELETE n") |
| 32 | + session.close() |
| 33 | + |
| 34 | + def test_minimum_snippet(self): |
| 35 | + #tag::minimum-snippet[] |
| 36 | + driver = GraphDatabase.driver("bolt://localhost") |
| 37 | + session = driver.session() |
| 38 | + session.run("CREATE (neo:Person {name:'Neo', age:23})") |
| 39 | + |
| 40 | + for record in session.run("MATCH (p:Person) WHERE p.name = 'Neo' RETURN p.age"): |
| 41 | + print("Neo is {0} years old.".format(record["p.age"])) |
| 42 | + session.close() |
| 43 | + #end::minimum-snippet[] |
| 44 | + |
| 45 | + def test_statement_with_parameters(self): |
| 46 | + driver = GraphDatabase.driver("bolt://localhost") |
| 47 | + session = driver.session() |
| 48 | + #tag::statement[] |
| 49 | + result = session.run("CREATE (p:Person { name: {name} })", {"name": "The One"}) |
| 50 | + ones_created = result.summary.statistics.nodes_created |
| 51 | + print("There were {0} the ones created.".format(ones_created)) |
| 52 | + #end::statement[] |
| 53 | + assert ones_created == 1 |
| 54 | + session.close() |
| 55 | + |
| 56 | + def test_statement_without_parameters(self): |
| 57 | + driver = GraphDatabase.driver("bolt://localhost") |
| 58 | + session = driver.session() |
| 59 | + #tag::statement-without-parameters[] |
| 60 | + result = session.run("CREATE (p:Person { name: 'The One' })") |
| 61 | + ones_created = result.summary.statistics.nodes_created |
| 62 | + print("There were {0} the ones created.".format(ones_created)) |
| 63 | + #end::statement-without-parameterst[] |
| 64 | + assert ones_created == 1 |
| 65 | + session.close() |
| 66 | + |
| 67 | + def test_commit_a_transaction(self): |
| 68 | + driver = GraphDatabase.driver("bolt://localhost") |
| 69 | + session = driver.session() |
| 70 | + #tag::transaction-commit[] |
| 71 | + tx = session.begin_transaction() |
| 72 | + tx.run("CREATE (p:Person { name: 'The One' })") |
| 73 | + tx.commit() |
| 74 | + #end::transaction-commit[] |
| 75 | + res = session.run("MATCH (p:Person { name: 'The One' }) RETURN count(p)") |
| 76 | + assert res[0]["count(p)"] == 1 |
| 77 | + session.close() |
| 78 | + |
| 79 | + def test_rollback_a_transaction(self): |
| 80 | + driver = GraphDatabase.driver("bolt://localhost") |
| 81 | + session = driver.session() |
| 82 | + #tag::transaction-rollback[] |
| 83 | + tx = session.begin_transaction() |
| 84 | + tx.run("CREATE (p:Person { name: 'The One' })") |
| 85 | + tx.rollback() |
| 86 | + #end::transaction-rollback[] |
| 87 | + res = session.run("MATCH (p:Person { name: 'The One' }) RETURN count(p)") |
| 88 | + assert res[0]["count(p)"] == 0 |
| 89 | + session.close() |
| 90 | + |
| 91 | + def test_require_encryption(self): |
| 92 | + #tag::tls-require-encryption[] |
| 93 | + #Unfortunately, this feature is not yet implemented for Python |
| 94 | + pass |
| 95 | + #end::tls-require-encryption[] |
| 96 | + |
| 97 | + def test_trust_on_first_use(self): |
| 98 | + #tag::tls-trust-on-first-use[] |
| 99 | + #Unfortunately, this feature is not yet implemented for Python |
| 100 | + pass |
| 101 | + #end::tls-trust-on-first-use[] |
| 102 | + |
| 103 | + def test_signed_certificate(self): |
| 104 | + #tag::tls-signed[] |
| 105 | + #Unfortunately, this feature is not yet implemented for Python |
| 106 | + pass |
| 107 | + #end::tls-signed[] |
0 commit comments