Skip to content

Commit

Permalink
Merge pull request #39 from neo4j-contrib/Neo4J-update-t-4.1
Browse files Browse the repository at this point in the history
Neo4J-update-t-4.1
  • Loading branch information
robinedwards authored Dec 8, 2020
2 parents 9bee670 + ba861a3 commit 5db95df
Show file tree
Hide file tree
Showing 21 changed files with 178 additions and 80 deletions.
Binary file added .DS_Store
Binary file not shown.
35 changes: 22 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
language: python
sudo: required
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
install: "python setup.py install"
script:
- cd tests
- python manage.py test
- "3.7"
- "3.8"
- "3.9"

env:
- NEO4J_VERSION="3.1.0"
- NEO4J_VERSION="3.5.24"
- NEO4J_VERSION="4.0.9"
- NEO4J_VERSION="4.1.4"
- NEO4J_VERSION="4.2.0"
before_install:
- sudo apt-get update && sudo apt-get install oracle-java8-installer
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
- wget dist.neo4j.org/neo4j-community-$NEO4J_VERSION-unix.tar.gz
- tar -xzf neo4j-community-$NEO4J_VERSION-unix.tar.gz
- neo4j-community-$NEO4J_VERSION/bin/neo4j start
- sudo add-apt-repository -y ppa:openjdk-r/ppa
- sudo apt-get update && sudo apt-get install openjdk-11-jre-headless
- curl -L http://dist.neo4j.org/neo4j-community-$NEO4J_VERSION-unix.tar.gz | tar xz
install: "python setup.py install"
before_script:
- neo4j-community-$NEO4J_VERSION/bin/neo4j-admin set-initial-password foobar
- JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 neo4j-community-$NEO4J_VERSION/bin/neo4j start
- export DJANGO_SETTINGS_MODULE=settings
- sleep 10
script:
- cd tests
- ./manage.py install_labels
- ./manage.py migrate
- export DJANGO_SETTINGS_MODULE=tests.settings
- pytest
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 0.0.5 2020-11-20
* Update project to use python 3(required) and neomodel 4.1.1(required)

Version 0.0.4 2017-06-10
* Allow required fields to be excluded from forms when updating, closes #6
* Require neomodel 3.2.5 (neo4j_driver 1.2.1)
Expand Down
38 changes: 34 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ These are mapped to neomodel.config as django is started::
NEOMODEL_SIGNALS = True
NEOMODEL_FORCE_TIMEZONE = False
NEOMODEL_ENCRYPTED_CONNECTION = True
NEOMODEL_MAX_POOL_SIZE = 50
NEOMODEL_MAX_CONNECTION_POOL_SIZE = 50

Signals
=======
Expand Down Expand Up @@ -141,7 +141,6 @@ Setup constraints and indexes on labels for your node definitions. This should b

Found tests.someapp.models.Book
+ Creating unique constraint for title on label Book for class tests.someapp.models.Book

Finished 1 class(es).

clear_neo4j
Expand All @@ -151,9 +150,40 @@ Delete all nodes in your database, warning there is no confirmation!
Requirements
============

- Python 2.7, 3.4+
- neo4j 3.0+
- Python 3.6+
- neo4j 3.5+

.. image:: https://badges.gitter.im/Join%20Chat.svg
:alt: Join the chat at https://gitter.im/robinedwards/neomodel
:target: https://gitter.im/robinedwards/neomodel?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge


To Contribute
===================

Setup neo4j Desktop with a local database with password 'foobar' and version 4.1.2 (current version when this was written).

Commands to run tests::

# create local venv and install dependencies.
$ python3 -m venv venv; source venv/bin/activate; python setup.py develop; export DJANGO_SETTINGS_MODULE=tests.settings;
# Go to tests
$ cd tests/
$ ./manage.py install_labels
$ ./manage.py migrate
$ pytest

# example output:

platform darwin -- Python 3.9.0, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
pick 0900469 Neo4J-update-t-4.1
rootdir: /Users/matthewgalvis/SilverLogic/GGP/gh/django-neomodel, configfile: pytest.ini
collected 16 items

someapp/tests/test_atomicity.py . [ 6%]
someapp/tests/test_commands.py .. [ 18%]
someapp/tests/test_model_form.py ........... [ 87%]
someapp/tests/test_sanity.py . [ 93%]
someapp/tests/test_signals.py .
16 passed, 11 warnings in 1.62s

4 changes: 4 additions & 0 deletions django_neomodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ def get_choices(self, include_blank=True):
blank_defined = False
blank_choice = BLANK_CHOICE_DASH
choices = list(self.choices) if self.choices else []

if issubclass(type(self.choices), dict):
choices = list(enumerate(self.choices))

for choice, __ in choices:
if choice in ('', None):
blank_defined = True
Expand Down
4 changes: 2 additions & 2 deletions django_neomodel/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class NeomodelConfig(AppConfig):
def read_settings(self):
config.DATABASE_URL = getattr(settings, 'NEOMODEL_NEO4J_BOLT_URL', config.DATABASE_URL)
config.FORCE_TIMEZONE = getattr(settings, 'NEOMODEL_FORCE_TIMEZONE', False)
config.ENCRYPTED_CONNECTION = getattr(settings, 'NEOMODEL_ENCRYPTED_CONNECTION', True)
config.MAX_POOL_SIZE = getattr(settings, 'NEOMODEL_MAX_POOL_SIZE', config.MAX_POOL_SIZE)
config.ENCRYPTED_CONNECTION = getattr(settings, 'NEOMODEL_ENCRYPTED_CONNECTION', False)
config.MAX_CONNECTION_POOL_SIZE = getattr(settings, 'NEOMODEL_MAX_CONNECTION_POOL_SIZE', config.MAX_CONNECTION_POOL_SIZE)

def ready(self):
self.read_settings()
2 changes: 1 addition & 1 deletion django_neomodel/management/commands/clear_neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ class Command(BaseCommand):

def handle(self, *args, **options):
self.stdout.write('Deleting all nodes..\n')
clear_neo4j_database(db)
clear_neo4j_database(db, True, True)
self.stdout.write('Done.\n')
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
DJANGO_SETTINGS_MODULE = tests.settings
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='django_neomodel',
version='0.0.4',
version='0.0.5',
description='Use Neo4j with Django!',
long_description=open('README.rst').read(),
author='Robin Edwards',
Expand All @@ -12,18 +12,19 @@
license='MIT',
packages=find_packages(exclude=('tests',)),
keywords='neo4j django plugin neomodel',
install_requires=['neomodel>=3.2.5', 'django>=1.9'],
install_requires=['neomodel>=4.0.1', 'pytz>=2020.1', 'django>=2.2'],
tests_require=['pytest-django>=3.10.0'],
classifiers=[
"Development Status :: 4 - Beta",
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
# With (3.9) warnings on Shapely install on neobolt repo
"Programming Language :: Python :: 3.9",
"Topic :: Database",
])
3 changes: 0 additions & 3 deletions tests/manage.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)
16 changes: 12 additions & 4 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
here = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, here)
sys.path.insert(0, os.path.join(here, os.pardir))

SITE_ID = 300

DEBUG = True
Expand All @@ -26,8 +25,11 @@
},
}

NEOMODEL_NEO4J_BOLT_URL = os.environ.get('NEO4J_BOLT_URL', 'bolt://neo4j:neo4j@localhost:7687')
NEOMODEL_NEO4J_BOLT_URL = os.environ.get('NEO4J_BOLT_URL', 'bolt://neo4j:foobar@localhost:7687')
NEOMODEL_SIGNALS = True
NEOMODEL_FORCE_TIMEZONE = False
NEOMODEL_ENCRYPTED_CONNECTION = False
NEOMODEL_MAX_POOL_SIZE = 50

TEMPLATES = [
{
Expand All @@ -36,15 +38,21 @@
},
]

INSTALLED_APPS = (
INSTALLED_APPS = [
# Django
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',

# Third party
'django_neomodel',

# Test
'tests.someapp',
)
]

USE_TZ = True
TIME_ZONE = 'UTC'
MIDDLEWARE = []

21 changes: 21 additions & 0 deletions tests/someapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 2.2 on 2020-11-20 15:58

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Library',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10)),
],
),
]
Empty file.
14 changes: 6 additions & 8 deletions tests/someapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ class Meta:

class Book(DjangoNode):
uid = UniqueIdProperty()
condition = StringProperty(default='new') # check fields can be omitted
format = StringProperty(required=True) # check required field can be ommitted on update
title = StringProperty(unique_index=True)
format = StringProperty(required=True) # check required field can be omitted on update
status = StringProperty(choices=(
('Available', 'A'),
('On loan', 'L'),
('Damaged', 'D'),
), default='Available')

('available', 'A'),
('on_loan', 'L'),
('damaged', 'D'),
), default='available', coerce=str)
created = DateTimeProperty(default=datetime.utcnow)

class Meta:
app_label = 'someapp'
app_label = 'someapp'
18 changes: 0 additions & 18 deletions tests/someapp/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
from __future__ import print_function

from neomodel import db, change_neo4j_password, clear_neo4j_database
from neo4j.v1 import CypherError

# Travis default password dance
try:
clear_neo4j_database(db)
except CypherError as ce:
# handle instance without password being changed
if 'The credentials you provided were valid, but must be changed before you can use this instance' in str(ce):
change_neo4j_password(db, 'test')
db.set_connection('bolt://neo4j:test@localhost:7687')

print("New database with no password set, setting password to 'test'")
print("Please 'export NEO4J_BOLT_URL=bolt://neo4j:test@localhost:7687' for subsequent test runs")
else:
raise ce
14 changes: 10 additions & 4 deletions tests/someapp/tests/test_atomicity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from django.test import TestCase
from neomodel import db, clear_neo4j_database
from django.db import transaction
import django
django.setup()

from tests.someapp.models import Book, Library


class AtomicityTestClass(TestCase):
def setUp(self):
clear_neo4j_database(db)
Expand All @@ -11,14 +15,16 @@ def test_create_object(self):
try:
with transaction.atomic(using="default"):
with db.transaction:
sql_row = Library.objects.create(name="example")
neo4j_node = Book(title="example", format="foo").save()
# sql_row
Library.objects.create(name="example")
# neo4j_node
Book(title="example", format="foo").save()
raise Exception
except Exception as e:
pass

neo4j_q = Book.nodes.get_or_none(title="example")
sql_q = Library.objects.filter(name="example").first()

self.assertIsNone(neo4j_q)

sql_q = Library.objects.filter(name="example").first()
self.assertIsNone(sql_q)
5 changes: 4 additions & 1 deletion tests/someapp/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
import django
django.setup()

from io import StringIO ## for Python 3


class TestCommands(TestCase):
Expand Down
Loading

0 comments on commit 5db95df

Please sign in to comment.