Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions djangomaat/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@
import inspect
from time import time

from django.utils.encoding import python_2_unicode_compatible
try:
from django.utils.encoding import python_2_unicode_compatible
except ImportError:
# Django > 2
def python_2_unicode_compatible(klass):
"""
A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.

To support Python 2 and 3 with a single code base, define a __str__ method
returning text and apply this decorator to the class.
"""
return klass

from django.contrib.contenttypes.models import ContentType
try:
from django.db.transaction import atomic
Expand All @@ -13,7 +26,6 @@
from djangomaat.models import MaatRanking
from djangomaat.exceptions import ManagerDoesNotExist, TypologyNotImplemented
from djangomaat.settings import FLUSH_BATCH_SIZE
from django.utils.encoding import python_2_unicode_compatible

GETTER_PREFIX = 'get_pk_list_for_'

Expand Down
4 changes: 2 additions & 2 deletions djangomaat/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import unicode_literals

from django.db import models, migrations

import django.db.models.deletion

class Migration(migrations.Migration):

Expand All @@ -19,7 +19,7 @@ class Migration(migrations.Migration):
('typology', models.CharField(max_length=255, db_index=True)),
('usable', models.BooleanField(default=False)),
('position', models.PositiveIntegerField(default=0)),
('content_type', models.ForeignKey(to='contenttypes.ContentType')),
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
],
options={
},
Expand Down
16 changes: 14 additions & 2 deletions djangomaat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@
# Django < 1.9
from django.contrib.contenttypes.generic import GenericForeignKey
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

try:
from django.utils.encoding import python_2_unicode_compatible
except ImportError:
# Django > 2
def python_2_unicode_compatible(klass):
"""
A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.

To support Python 2 and 3 with a single code base, define a __str__ method
returning text and apply this decorator to the class.
"""
return klass

@python_2_unicode_compatible
class MaatRanking(models.Model):
content_type = models.ForeignKey(ContentType)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField(db_index=True)
content_object = GenericForeignKey('content_type', 'object_id')

Expand Down
23 changes: 19 additions & 4 deletions djangomaat/tests.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
from __future__ import unicode_literals
import unittest

from django.test import TestCase
from django.core.management import call_command
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

try:
from django.utils.encoding import python_2_unicode_compatible
except ImportError:
# Django > 2
def python_2_unicode_compatible(klass):
"""
A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.

To support Python 2 and 3 with a single code base, define a __str__ method
returning text and apply this decorator to the class.
"""
return klass

try:
from django.contrib.contenttypes.fields import ReverseGenericManyToOneDescriptor as RGD
except ImportError:
Expand All @@ -13,7 +27,8 @@
except ImportError:
# Django < 1.7
from django.contrib.contenttypes.generic import ReverseGenericRelatedObjectsDescriptor as RGD
from django.utils.six import StringIO

from six import StringIO

from djangomaat.register import maat
from djangomaat.handlers import MaatHandler
Expand Down Expand Up @@ -45,7 +60,7 @@ class MockLogger(object):
def write(self, something):
pass

class ClientTest(unittest.TestCase):
class ClientTest(TestCase):

def setUp(self):
self.h = TestMaatHandler(TestModel)
Expand Down
2 changes: 1 addition & 1 deletion tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# This will prevent the tests from running the migrations that come with the app
# otherwise the test models won't be created.
# http://stackoverflow.com/questions/25161425/disable-migrations-when-running-unit-tests-in-django-1-7
MIGRATION_MODULES = {'djangomaat': 'djangomaat.no_migrations_here'}
MIGRATION_MODULES = {'djangomaat': None}
39 changes: 18 additions & 21 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
[tox]
envlist =
{py27,py33,py34,py35}-django18,
{py27,py34,py35}-django{19,110},
coverage
envlist = py{310,311}-django{32,42}
coverage
skip_missing_interpreters = True

[testenv]
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
usedevelop = True
deps =
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
commands =
django-admin.py test djangomaat
setenv =
DJANGO_SETTINGS_MODULE = settings
PYTHONPATH = {toxinidir}/tests
changedir = {toxinidir}/tests/
commands = {envbindir}/django-admin test --verbosity=2 djangomaat
setenv =
PYTHONPATH = {toxinidir}
DJANGO_SETTINGS_MODULE = tests.settings
deps = django32: Django>=3.2,<4.0
django42: Django>=4.2,<5.0
six


[testenv:coverage]
commands =
coverage run --branch --include={toxinidir}/djangomaat/* --omit={toxinidir}/djangomaat/tests* {envbindir}/django-admin.py test djangomaat
coveralls
deps =
coveralls
Django>=1.10,<1.11
; [testenv:coverage]
; commands =
; coverage run --branch --include={toxinidir}/djangomaat/* --omit={toxinidir}/djangomaat/tests* {envbindir}/django-admin test djangomaat
; coveralls
; deps =
; six
; coveralls