aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_model_serializer.py
diff options
context:
space:
mode:
authorTom Christie2014-12-05 14:15:58 +0000
committerTom Christie2014-12-05 14:15:58 +0000
commit544967f36ed6e29819018428d48da00de74958b9 (patch)
tree20005a2ab9731b326de9187c29cbaa4aa046226c /tests/test_model_serializer.py
parentc611a2c1fe7370bbe3151cb04b546e3e400acf1e (diff)
downloaddjango-rest-framework-544967f36ed6e29819018428d48da00de74958b9.tar.bz2
Test tweaks
Diffstat (limited to 'tests/test_model_serializer.py')
-rw-r--r--tests/test_model_serializer.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/test_model_serializer.py b/tests/test_model_serializer.py
index 1bcd58e0..da79164a 100644
--- a/tests/test_model_serializer.py
+++ b/tests/test_model_serializer.py
@@ -559,3 +559,53 @@ class TestBulkCreate(TestCase):
# Serializer returns correct data.
assert serializer.data == data
+
+
+class TestMetaClassModel(models.Model):
+ text = models.CharField(max_length=100)
+
+
+class TestSerializerMetaClass(TestCase):
+ def test_meta_class_fields_option(self):
+ class ExampleSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = TestMetaClassModel
+ fields = 'text'
+
+ with self.assertRaises(TypeError) as result:
+ ExampleSerializer().fields
+
+ exception = result.exception
+ assert str(exception).startswith(
+ "The `fields` option must be a list or tuple"
+ )
+
+ def test_meta_class_exclude_option(self):
+ class ExampleSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = TestMetaClassModel
+ exclude = 'text'
+
+ with self.assertRaises(TypeError) as result:
+ ExampleSerializer().fields
+
+ exception = result.exception
+ assert str(exception).startswith(
+ "The `exclude` option must be a list or tuple"
+ )
+
+ def test_meta_class_fields_and_exclude_options(self):
+ class ExampleSerializer(serializers.ModelSerializer):
+ class Meta:
+ model = TestMetaClassModel
+ fields = ('text',)
+ exclude = ('text',)
+
+ with self.assertRaises(AssertionError) as result:
+ ExampleSerializer().fields
+
+ exception = result.exception
+ self.assertEqual(
+ str(exception),
+ "Cannot set both 'fields' and 'exclude'."
+ )