diff --git a/.travis.yml b/.travis.yml index 6318584..3e2c049 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,13 +6,14 @@ python: - "pypy" env: - - "DRF='djangorestframework<3'" - - "DRF='djangorestframework>=3'" + - "$DJANGO_DRF='django<1.8' 'djangorestframework<3'" + - "$DJANGO_DRF='djangorestframework>=3'" # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors install: - - pip install $DRF + - pip install $DJANGO_DRF - pip install -r requirements-dev.txt + - pip freeze # command to run tests, e.g. python setup.py test script: make check diff --git a/HISTORY.rst b/HISTORY.rst index 7bf4f04..7d4f47b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,14 @@ History ------- +0.2.1 (2015-04-26) +~~~~~~~~~~~~~~~~~~ + +* Fixed a bug which allowed to submit data for update to serializer + without update field. + See `#34 `_. +* Removed support for Django1.8 with DRF2.x + 0.2 (2015-02-09) ~~~~~~~~~~~~~~~~ diff --git a/Makefile b/Makefile index 2a5771b..7d4160c 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,7 @@ .PHONY: clean-pyc clean-build docs clean -NOSE_FLAGS=-s --verbosity=2 -COVER_CONFIG_FLAGS=--with-coverage --cover-package=rest_framework_bulk --cover-erase -COVER_REPORT_FLAGS=--cover-html --cover-html-dir=htmlcov -COVER_FLAGS=${COVER_CONFIG_FLAGS} ${COVER_REPORT_FLAGS} +TEST_FLAGS=--verbosity=2 +COVER_FLAGS=--source=rest_framework_bulk help: @echo "install - install all requirements including for testing" @@ -51,10 +49,14 @@ lint: flake8 rest_framework_bulk test: - python tests/manage.py test ${NOSE_FLAGS} - -test-coverage: - python tests/manage.py test ${NOSE_FLAGS} ${COVER_FLAGS} + python tests/manage.py test ${TEST_FLAGS} + +test-coverage: clean-test + -coverage run ${COVER_FLAGS} tests/manage.py test ${TEST_FLAGS} + @exit_code=$? + @-coverage report + @-coverage html + @exit ${exit_code} test-all: tox diff --git a/README.rst b/README.rst index 0c6027b..af70822 100644 --- a/README.rst +++ b/README.rst @@ -21,10 +21,11 @@ within the framework. That is the purpose of this project. Requirements ------------ -* Python 2.7+ -* Django 1.3+ -* Django REST Framework >= 2.2.5 (when bulk features were added to serializers) -* Django REST Framework >= 3.0.0 (DRF-bulk supports both DRF2 and DRF3!) +* Python>=2.7 +* Django>=1.3 +* Django REST Framework >= 3.0.0 +* REST Framework >= 2.2.5 + (**only with** Django<1.8 since DRF<3 does not support Django1.8) Installing ---------- diff --git a/requirements-dev.txt b/requirements-dev.txt index 9060574..257c17d 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,4 @@ -r requirements.txt coverage -django-nose flake8 tox diff --git a/rest_framework_bulk/__init__.py b/rest_framework_bulk/__init__.py index 7dceaaf..1d7f9a3 100644 --- a/rest_framework_bulk/__init__.py +++ b/rest_framework_bulk/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.2' +__version__ = '0.2.1' __author__ = 'Miroslav Shubernetskiy' try: diff --git a/rest_framework_bulk/drf3/serializers.py b/rest_framework_bulk/drf3/serializers.py index 9098829..31fff46 100644 --- a/rest_framework_bulk/drf3/serializers.py +++ b/rest_framework_bulk/drf3/serializers.py @@ -1,4 +1,6 @@ from __future__ import print_function, unicode_literals +import inspect + from rest_framework.exceptions import ValidationError from rest_framework.serializers import ListSerializer @@ -41,6 +43,10 @@ def update(self, queryset, all_validated_data): for i in all_validated_data } + if not all((bool(i) and not inspect.isclass(i) + for i in all_validated_data_by_id.keys())): + raise ValidationError('') + # since this method is given a queryset which can have many # model instances, first find all objects to update # and only then update the models diff --git a/rest_framework_bulk/tests/test_generics.py b/rest_framework_bulk/tests/test_generics.py index 5522948..6838bf4 100644 --- a/rest_framework_bulk/tests/test_generics.py +++ b/rest_framework_bulk/tests/test_generics.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals, print_function import json + from django.core.urlresolvers import reverse from django.test import TestCase from django.test.client import RequestFactory @@ -83,6 +84,22 @@ def test_put(self): ] ) + def test_put_without_update_key(self): + """ + Test that PUT request updates all submitted resources. + """ + response = self.view(self.request.put( + '', + json.dumps([ + {'contents': 'foo', 'number': 3}, + {'contents': 'rainbows', 'number': 4}, # multiple objects without id + {'contents': 'bar', 'number': 4, 'id': 555}, # non-existing id + ]), + content_type='application/json', + )) + + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + def test_patch(self): """ Test that PATCH request partially updates all submitted resources. diff --git a/tests/settings.py b/tests/settings.py index 48f7ae6..2fcd255 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -12,15 +12,14 @@ MIDDLEWARE_CLASSES = () INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', 'django.contrib.staticfiles', - 'django_nose', 'rest_framework', 'rest_framework_bulk', 'rest_framework_bulk.tests.simple_app', ) -TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' - STATIC_URL = '/static/' SECRET_KEY = 'foo' diff --git a/tox.ini b/tox.ini index d088851..0af40aa 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ basepython = pypy: pypy pypy3: pypy3 setenv = - PYTHONPATH = {toxinidir}:{toxinidir}/multinosetests + PYTHONPATH = {toxinidir} commands = make install-quite pip freeze @@ -20,5 +20,21 @@ deps = whitelist_externals = make +[testenv:py27-drf2] +deps = + django<1.8 + +[testenv:py34-drf2] +deps = + django<1.8 + +[testenv:pypy-drf2] +deps = + django<1.8 + +[testenv:pypy3-drf2] +deps = + django<1.8 + [flake8] max-line-length = 100