def test_service_root_on_bound_path(graph): alice = Node(name="Alice") bob = Node(name="Bob") carol = Node(name="Carol") dave = Node(name="Dave") path = Path(alice, "LOVES", bob, Rev("HATES"), carol, "KNOWS", dave) graph.create(path) assert path.service_root == ServiceRoot("http://localhost:7474/") path[0].unbind() assert path.service_root == ServiceRoot("http://localhost:7474/")
def test_service_root(graph): a, b, ab = graph.create({}, {}, (0, "KNOWS", 1)) assert ab.service_root == ServiceRoot("http://localhost:7474/") ab.rel.unbind() assert ab.service_root == ServiceRoot("http://localhost:7474/") a.unbind() assert ab.service_root == ServiceRoot("http://localhost:7474/") b.unbind() try: _ = ab.service_root except BindError: assert True else: assert False
def start(self): """ Start the server. :rtype: :class:`py2neo.server.GraphServerProcess` """ try: out = check_output("%s start" % self.script, shell=True) except CalledProcessError as error: if error.returncode == 2: raise OSError( "Another process is listening on the server port") elif error.returncode == 512: raise OSError("Another server process is already running") else: raise OSError("An error occurred while trying to start " "the server [%s]" % error.returncode) else: uri = None kwargs = {} for line in out.decode("utf-8").splitlines(False): if line.startswith("Using additional JVM arguments:"): kwargs["jvm_arguments"] = shlex.split(line[32:]) elif line.startswith("process"): numbers = number_in_brackets.search(line).groups() if numbers: kwargs["pid"] = int(numbers[0]) elif line.startswith("http"): uri = line.partition(" ")[0] if not uri: raise RuntimeError( "Unable to parse output from server startup") return GraphServerProcess(self, ServiceRoot(uri), **kwargs)
def service_root(self): """ The service root exposed by this server. :return: :class:`py2neo.ServiceRoot` """ return ServiceRoot("http://localhost:%s" % self.info["NEO4J_SERVER_PORT"])
def main(): script, args = sys.argv[0], sys.argv[1:] if len(args) < 2 or len(args) > 3: _help(script) return try: service_root = ServiceRoot(NEO4J_URI) user_name = args[0] password = args[1] user_manager = UserManager.for_user(service_root, user_name, password) if len(args) == 2: # Check password if user_manager.password_change_required: print("Password change required") else: print("Password change not required") else: # Change password password_manager = user_manager.password_manager new_password = args[2] if password_manager.change(new_password): print("Password change succeeded") else: print("Password change failed") sys.exit(2) except Exception as error: sys.stderr.write("%s: %s\n" % (error.__class__.__name__, ustr(error))) sys.exit(1)
def __init__(self, uri=None): if uri is None: service_root = ServiceRoot() manager = Resource(service_root.resource.metadata["management"]) monitor = Monitor(manager.metadata["services"]["monitor"]) uri = monitor.resource.uri Service.__init__(self) self.bind(uri)
def change_password(): global NEO4J_URL, NEO4J_HOST_PORT, NEO4J_USER, NEO4J_PASSWORD, NEO4J_DEFAULT_PASSWORD service_root = ServiceRoot(NEO4J_URL) user_name = NEO4J_USER password = NEO4J_DEFAULT_PASSWORD user_manager = UserManager.for_user(service_root, user_name, password) password_manager = user_manager.password_manager new_password = NEO4J_PASSWORD password_manager.change(new_password)
def test_service_root_on_unbound_path(): alice = Node(name="Alice") bob = Node(name="Bob") carol = Node(name="Carol") dave = Node(name="Dave") path = Path(alice, "LOVES", bob, Rev("HATES"), carol, "KNOWS", dave) try: assert path.service_root == ServiceRoot("http://localhost:7474/") except BindError: assert True else: assert False
def test_same_uri_gives_same_instance(): uri = "http://localhost:7474/" service_root_1 = ServiceRoot(uri) service_root_2 = ServiceRoot(uri) assert service_root_1 is service_root_2
def test_can_create_service_root_without_trailing_slash(): uri = "http://localhost:7474/" service_root = ServiceRoot(uri[:-1]) assert service_root.uri == uri index = service_root.resource.get().content assert "data" in index
def __init__(self): neo4jUri = 'http://localhost:7474/' self.graph = ServiceRoot(neo4jUri).graph
def graph_p2(): """ Get connection to graph via py2neo. """ graphenedb_url = os.environ.get("GRAPHENEDB_URL", "http://localhost:7474/") return ServiceRoot(graphenedb_url).graph
__author__ = 'devangmundhra' from django.conf import settings from py2neo import ServiceRoot, Relationship, Node _neo4j_url = settings.NEO4J_URL neo4j_graph = ServiceRoot(_neo4j_url).graph