aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTom Christie2014-12-02 12:46:47 +0000
committerTom Christie2014-12-02 12:46:47 +0000
commit54b7b32818fc9b8872b65d25d5684c72b8e60ae0 (patch)
treef2234a5eeee59d745abe876670653b7d1cc0973a /tests
parent79e18a2a06178e8c00dfafc1cfd062f2528ec2c1 (diff)
parentad060aa360fa2ed33bd83cbb419d7b996a428726 (diff)
downloaddjango-rest-framework-54b7b32818fc9b8872b65d25d5684c72b8e60ae0.tar.bz2
Merge branch 'fixes/2013' of git://github.com/gregmuellegger/django-rest-framework into gregmuellegger-fixes/2013
Diffstat (limited to 'tests')
-rw-r--r--tests/test_model_serializer.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py
index 3aec0da0..90767dac 100644
--- a/tests/test_model_serializer.py
+++ b/tests/test_model_serializer.py
@@ -10,6 +10,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator, MinLeng
from django.db import models
from django.test import TestCase
from rest_framework import serializers
+import pytest
def dedent(blocktext):
@@ -26,6 +27,10 @@ class CustomField(models.Field):
pass
+class OneFieldModel(models.Model):
+ char_field = models.CharField(max_length=100)
+
+
class RegularFieldsModel(models.Model):
"""
A model class for testing regular flat fields.
@@ -68,6 +73,29 @@ class FieldOptionsModel(models.Model):
choices_field = models.CharField(max_length=100, choices=COLOR_CHOICES)
+class TestModelSerializer(TestCase):
+ def test_create_method(self):
+ class TestSerializer(serializers.ModelSerializer):
+ non_model_field = serializers.CharField()
+
+ class Meta:
+ model = OneFieldModel
+ fields = ('char_field', 'non_model_field')
+
+ serializer = TestSerializer(data={
+ 'char_field': 'foo',
+ 'non_model_field': 'bar',
+ })
+ serializer.is_valid()
+ with pytest.raises(TypeError):
+ serializer.save()
+
+ try:
+ serializer.save()
+ except TypeError as exc:
+ assert 'ModelSerializer' in str(exc)
+
+
class TestRegularFieldMappings(TestCase):
def test_regular_fields(self):
"""