First, a custom search explorer is created in which you stop the development database, then start the test database from a different path, start your tests, and finally stop the test instance and start the development instance again. This solution is proposed in the neo4j database testing Django thread . The following code has been adapted for version 3.1.1 of Neo4j:
from time import sleep
from subprocess import call
from django.test.runner import DiscoverRunner
from py2neo import authenticate
class DiscoverRunner(DiscoverRunner):
def setup_databases(self, *args, **kwargs):
call("sudo neo4j stop", shell=True)
sleep(1)
success = call("neo4j_test/neo4j-community-3.1.1/bin/neo4j"
" start", shell=True)
sleep(10)
if success != 0:
return False
from neomodel import db
query = "match (n)-[r]-() delete n,r"
db.cypher_query(query)
super(DiscoverRunner, self).__init__(*args, **kwargs)
def teardown_databases(self, old_config, **kwargs):
from neomodel import db
query = "match (n)-[r]-() delete n,r"
db.cypher_query(query)
sleep(1)
success = call("neo4j_test/neo4j-community-3.1.1/bin/neo4j"
" stop", shell=True)
if success != 0:
return False
sleep(1)
call("sudo neo4j start", shell=True)
It works fine until it tries to connect to the test database and make a request, because it uses an encryption connection and looks in '~/.neo4/known_hosts'for a connection key, but it conflicts with one of the development database and crashes with the following error:
neo4j.v1.exceptions.ProtocolError: Server certificate does not match known certificate for 'localhost'; check details in file '~/.neo4j/known_hosts'
So, is there a way to avoid certificate verification?