Skip to content

Commit

Permalink
Fix compatibility with Django 3.1 and actually run test against it (#112
Browse files Browse the repository at this point in the history
)
  • Loading branch information
michael-k authored Oct 6, 2020
1 parent 805c090 commit a7b1826
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- [dev] CI switched to GitHub Actions
- [dev] Freeze dev requirements
- [dev] Add Django 3.1 to test matrix
- [dev] Add Django 3.1 to test matrix [PR #103](https://github.com/model-bakers/model_bakery/pull/103) and [PR #112](https://github.com/model-bakers/model_bakery/pull/112)
- [dev] pre-commit to use local packages (so versions will match)
- [dev] consistent use of pydocstyle
- [dev] Updates to MANIFEST.in
- [dev] Correct field in recipe docs
- [dev] Adjust imports for Django 3.1 compatibility [PR #112](https://github.com/model-bakers/model_bakery/pull/112)

### Removed

Expand Down
6 changes: 4 additions & 2 deletions model_bakery/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@
BigIntegerRangeField,
DateRangeField,
DateTimeRangeField,
FloatRangeField,
IntegerRangeField,
)
except ImportError:
IntegerRangeField = None
BigIntegerRangeField = None
FloatRangeField = None
DateRangeField = None
DateTimeRangeField = None
try:
from django.contrib.postgres.fields.ranges import FloatRangeField
except ImportError:
FloatRangeField = None


def _make_integer_gen_by_range(field_type: Any) -> Callable:
Expand Down
11 changes: 9 additions & 2 deletions tests/generic/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ class Person(models.Model):
BigIntegerRangeField,
DateRangeField,
DateTimeRangeField,
FloatRangeField,
IntegerRangeField,
)

Expand All @@ -122,13 +121,21 @@ class Person(models.Model):
ci_text = CITextField()
int_range = IntegerRangeField()
bigint_range = BigIntegerRangeField()
float_range = FloatRangeField()
date_range = DateRangeField()
datetime_range = DateTimeRangeField()
except ImportError:
# Skip PostgreSQL-related fields
pass

try:
from django.contrib.postgres.fields.ranges import FloatRangeField

if settings.USING_POSTGRES:
float_range = FloatRangeField()
except ImportError:
# Django version greater or equal than 3.1
pass

try:
from django.contrib.postgres.fields.ranges import DecimalRangeField

Expand Down
10 changes: 8 additions & 2 deletions tests/test_filling_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
BigIntegerRangeField,
DateRangeField,
DateTimeRangeField,
FloatRangeField,
IntegerRangeField,
)
except ImportError:
Expand All @@ -50,10 +49,13 @@
CITextField = None
IntegerRangeField = None
BigIntegerRangeField = None
FloatRangeField = None
DateRangeField = None
DateTimeRangeField = None

try:
from django.contrib.postgres.fields.ranges import FloatRangeField
except ImportError:
FloatRangeField = None
try:
from django.contrib.postgres.fields.ranges import DecimalRangeField
except ImportError:
Expand Down Expand Up @@ -454,6 +456,10 @@ def test_filling_integer_range_field_for_big_int(self, person):
assert isinstance(person.bigint_range.upper, int)
assert person.bigint_range.lower < person.bigint_range.upper

@pytest.mark.skipif(
FloatRangeField is None,
reason="Django version does not support FloatRangeField",
)
def test_filling_float_range_field(self, person):
from psycopg2._range import NumericRange

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist =
py35-django{111,20,21,22}-{postgresql,sqlite}
py{36,37,38}-django{111,20,21,22,30}-{postgresql,sqlite}
py{36,37,38}-django{111,20,21,22,30,31}-{postgresql,sqlite}
flake8
isort
pydocstyle
Expand Down

0 comments on commit a7b1826

Please sign in to comment.