Neo4j ImpermanentDatabase in python unittests

I am trying to create unit tests for a python project that will interact with a Neo4j Graph database.

I am currently implementing a built-in graph database, but will most likely switch to the REST interface if I want to deploy it to a web application. I installed v1.9rc2 of the neo4j embedded project installed through pipin a virtual environment.

It mentions java class org.neo4j.test.TestGraphDatabaseFactory, which sounds perfect for what I mean. I am currently reading and writing to the database by file, which is normal, but I am having problems with the correct cleaning after checking the ech, which does not include the call shutil.rmtree... or is this how it should be done?

Another possible method is to create and shut down a database for each test using methods setUpand tearDownmine TestCase.

>>> import neo4j
>>> print neo4j.__version__
'1.9.c2'
+2
source share
2 answers

The best practice is to create and shut down the database individually for each test using setUp / tearDown - exactly the same as you already mentioned.

side note: 1.9rc2 is quite outdated, we will consider updating to the latest stable, since a couple of errors have been fixed since then.

+2
source

This is the way they do it on the official Python Neo4j Driver, it should probably be considered a “good example,” given where it comes from.

class ServerTestCase(TestCase):
""" Base class for test cases that use a remote server.
"""

known_hosts = KNOWN_HOSTS
known_hosts_backup = known_hosts + ".backup"

def setUp(self):
    if isfile(self.known_hosts):
        if isfile(self.known_hosts_backup):
            remove(self.known_hosts_backup)
        rename(self.known_hosts, self.known_hosts_backup)

def tearDown(self):
    if isfile(self.known_hosts_backup):
        if isfile(self.known_hosts):
            remove(self.known_hosts)
        rename(self.known_hosts_backup, self.known_hosts)

: https://github.com/neo4j/neo4j-python-driver/blob/1.1/test/util.py

0

Source: https://habr.com/ru/post/1668646/


All Articles