Skip to content

Commit

Permalink
Merge pull request coagulant#60 from hovel/django_1.11_2.0
Browse files Browse the repository at this point in the history
django 1.11, 2.0
  • Loading branch information
GeyseR committed Dec 27, 2017
2 parents ecf4284 + 965e687 commit 3dc9bb6
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 27 deletions.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ python:
- "3.4"
- "3.5"
env:
- DJANGO="Django>=1.7,<1.8" DB=sqlite
- DJANGO="Django>=1.8,<1.9" DB=sqlite
- DJANGO="Django>=1.9,<1.10" DB=sqlite
- DJANGO="Django>=1.10,<1.11" DB=sqlite
- DJANGO="Django>=1.11,<2.0" DB=sqlite
- DJANGO="Django>=2.0,<2.1" DB=sqlite
matrix:
exclude:
- python: "2.7"
env: DJANGO="Django>=2.0,<2.1" DB=sqlite
install:
- export PYTHONPATH=./django_any/:$PYTHONPATH
- pip install -U $DJANGO
Expand Down
9 changes: 9 additions & 0 deletions django_any/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import django
from django.core import validators
from django.db import models

if django.VERSION >= (1, 8):
from django.utils.lorem_ipsum import paragraphs
Expand Down Expand Up @@ -45,3 +47,10 @@ def get_remote_field_model(field):
return field.remote_field.model
else:
return field.rel.to


if django.VERSION < (2, 0):
CommaSeparatedIntegerField = models.CommaSeparatedIntegerField
else:
class CommaSeparatedIntegerField(models.CharField):
default_validators = [validators.validate_comma_separated_integer_list]
2 changes: 1 addition & 1 deletion django_any/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def ipaddress_field_data(field, **kwargs):
if choices:
return random.choice(choices)
else:
nums = [str(xunit.any_int(min_value=0, max_value=255)) for _ in xrange(0, 4)]
nums = [str(xunit.any_int(min_value=0, max_value=255)) for _ in range(0, 4)]
return ".".join(nums)

if validate_ipv6_address:
Expand Down
3 changes: 3 additions & 0 deletions django_any/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def any_char_field(field, **kwargs):
>>> type(result)
<type 'str'>
"""
if validators.validate_comma_separated_integer_list in field.validators:
return any_commaseparatedinteger_field(field, **kwargs)

min_length = kwargs.get('min_length', 1)
max_length = kwargs.get('max_length', field.max_length)
return xunit.any_string(min_length=min_length, max_length=max_length)
Expand Down
6 changes: 3 additions & 3 deletions django_any/tests/test_contrib_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SimpleModelWithDefaults(models.Model):
big_integer_field = models.BigIntegerField(default=8223372036854775807)
char_field = models.CharField(max_length=5, default='USSR')
boolean_field = models.BooleanField(default=True)
comma_separated_field = models.CommaSeparatedIntegerField(max_length=50, default='1,2,3')
comma_separated_field = compat.CommaSeparatedIntegerField(max_length=50, default='1,2,3')
date_field = models.DateField(default=datetime.date(2010, 12, 10))
datetime_field = models.DateTimeField(datetime.datetime.now)
decimal_field = models.DecimalField(decimal_places=2, max_digits=10, default=Decimal('0.5'))
Expand Down Expand Up @@ -43,8 +43,8 @@ class Meta:


class RelationshipModelsWithDefaults(models.Model):
fk = models.ForeignKey(TargetModel, default=1, related_name='related_fk')
o2o = models.OneToOneField(TargetModel, default=1, related_name='related_o2o')
fk = models.ForeignKey(TargetModel, on_delete=models.CASCADE, default=1, related_name='related_fk')
o2o = models.OneToOneField(TargetModel, on_delete=models.CASCADE, default=1, related_name='related_o2o')

class Meta:
app_label = 'django_any'
Expand Down
4 changes: 2 additions & 2 deletions django_any/tests/test_model_creation_constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Meta:


class ModelWithConstraintOnForeignKey(models.Model):
timestamp = models.ForeignKey(ModelWithConstraint)
timestamp = models.ForeignKey(ModelWithConstraint, on_delete=models.CASCADE)

class Meta:
app_label = 'django_any'
Expand All @@ -36,6 +36,6 @@ def test_model_creation_succeed(self):
self.assertTrue(result.start_time <= result.end_time)

def test_foreignkey_constraint_succeed(self):
result = any_model(ModelWithConstraintOnForeignKey)
result = any_model(ModelWithConstraintOnForeignKey, on_delete=models.CASCADE)
self.assertTrue(result.timestamp.start_time <= result.timestamp.end_time)

3 changes: 1 addition & 2 deletions django_any/tests/test_model_creation_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
Create models will all fields with simply to generate values
"""
import django
from django.db import models
from django.test import TestCase

Expand All @@ -14,7 +13,7 @@ class SimpleModel(models.Model):
big_integer_field = models.BigIntegerField()
char_field = models.CharField(max_length=5)
boolean_field = models.BooleanField()
comma_separated_field = models.CommaSeparatedIntegerField(max_length=50)
comma_separated_field = compat.CommaSeparatedIntegerField(max_length=50)
date_field = models.DateField()
datetime_field = models.DateTimeField()
decimal_field = models.DecimalField(decimal_places=2, max_digits=10)
Expand Down
2 changes: 1 addition & 1 deletion django_any/tests/test_model_field_content_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Meta:

class ModelWithGenericRelation(models.Model):
tag = models.SlugField()
content_type = models.ForeignKey(ContentType)
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')

Expand Down
4 changes: 2 additions & 2 deletions django_any/tests/test_model_foreign_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class Meta:


class BaseModel(models.Model):
related = models.ForeignKey(RelatedModel)
related = models.ForeignKey(RelatedModel, on_delete=models.CASCADE)

class Meta:
app_label = 'django_any'


class SelfReferencingModel(models.Model):
name = models.CharField(max_length=5)
parent = models.ForeignKey('self', null=True, blank=True)
parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True)

class Meta:
app_label = 'django_any'
Expand Down
2 changes: 1 addition & 1 deletion django_any/tests/test_model_oneto_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Meta:

class ModelWithOneToOneField(models.Model):
name = models.CharField(max_length=5)
related = models.OneToOneField(OneToOneRelated)
related = models.OneToOneField(OneToOneRelated, on_delete=models.CASCADE)

class Meta:
app_label = 'django_any'
Expand Down
2 changes: 1 addition & 1 deletion django_any/tests/test_model_qobjects_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Meta:


class RelatedToQObject(models.Model):
related = models.ForeignKey(QObjectRelated)
related = models.ForeignKey(QObjectRelated, on_delete=models.CASCADE)

class Meta:
app_label = 'django_any'
Expand Down
2 changes: 1 addition & 1 deletion django_any/tests/test_model_redefine_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Meta:


class RelatedToRedefined(models.Model):
related = models.ForeignKey(Redefined)
related = models.ForeignKey(Redefined, on_delete=models.CASCADE)

class Meta:
app_label = 'django_any'
Expand Down
4 changes: 2 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for setting values for related instances::

#models.py
class Choice(models.Model):
poll = models.ForeignKey(Poll)
poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
choice = models.CharField(max_length=200)
votes = models.IntegerField()

Expand Down Expand Up @@ -88,4 +88,4 @@ generate random data for this filed you should register it explicitly::
.. note:: When project defines a lot of custom fields, it can be a hassle to
register all of them manually. Quite often the registered sample data for the field the custom field
was inherited from will work just as well, so django-whatever tries to use parent generator
if no function is registered for a custom field.
if no function is registered for a custom field.
12 changes: 8 additions & 4 deletions tests/testproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,21 @@
'django_any',
]

MIDDLEWARE_CLASSES = [
middlewares = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
if django.VERSION >= (1, 8):
MIDDLEWARE_CLASSES.append('django.middleware.security.SecurityMiddleware')
if django.VERSION <= (1, 9):
middlewares.append('django.contrib.auth.middleware.SessionAuthenticationMiddleware')
if django.VERSION >= (1, 10):
MIDDLEWARE = middlewares
else:
MIDDLEWARE_CLASSES = middlewares

ROOT_URLCONF = 'testproject.urls'

Expand Down
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,34,35}-django1{8,9,10}
envlist = py{27,34,35}-django1{8,11},py{34,35}-django2{0}

[testenv]
setenv =
Expand All @@ -11,7 +11,6 @@ basepython =
py35: python3.5
deps =
-rtests/requirements.pip
django17: Django>=1.7,<1.8
django18: Django>=1.8,<1.9
django19: Django>=1.9,<1.10
django110: Django>=1.10,<1.11
django111: Django>=1.11,<2.0
django20: Django>=2.0,<2.1

0 comments on commit 3dc9bb6

Please sign in to comment.