summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Aguilar <roberto@baremetal.io>2013-09-06 15:56:48 +0000
committerRoberto Aguilar <roberto@baremetal.io>2013-09-06 20:23:27 +0000
commitd8d61d8260badd87b85accaf5776587f2d355c10 (patch)
tree7aa8e04912ff79fbe056ea61237bc66ae3678d54
parent630eb0564abd228da439d86ad93acb4089d795e7 (diff)
Added tests for missing pyyaml.
This test makes sure an YAML import errors are communicated to the caller rather than stating the serializer does not exist.
-rw-r--r--tests/fixtures/tests.py1
-rw-r--r--tests/serializers/tests.py22
2 files changed, 22 insertions, 1 deletions
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index c24e0806fa..d6348e82ff 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
+import unittest
import warnings
from django.contrib.sites.models import Site
diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py
index 381cc5ed87..b32aa22657 100644
--- a/tests/serializers/tests.py
+++ b/tests/serializers/tests.py
@@ -14,7 +14,7 @@ except ImportError:
from django.conf import settings
-from django.core import serializers
+from django.core import management, serializers
from django.db import transaction, connection
from django.test import TestCase, TransactionTestCase, Approximate
from django.utils import six
@@ -440,6 +440,26 @@ class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact
}]"""
+@unittest.skipIf(HAS_YAML, "Yaml is installed")
+class NoYamlSerializerTestCase(TestCase):
+ """Not having pyyaml installed provides a misleading error
+
+ #12756
+ """
+ def test_missing_pyyaml_error_message(self):
+ """Using yaml serializer without pyyaml raises ImportError"""
+ jane = Author(name="Jane")
+ self.assertRaises(ImportError, serializers.serialize, "yaml", [jane])
+
+ def test_deserializer_pyyaml_error_message(self):
+ """Using yaml deserializer without pyyaml raises ImportError"""
+ self.assertRaises(ImportError, serializers.deserialize, "yaml", "")
+
+ def test_missing_pyyaml_error_message(self):
+ self.assertRaisesRegexp(management.CommandError, r'No module named yaml',
+ management.call_command, 'dumpdata', format='yaml')
+
+
@unittest.skipUnless(HAS_YAML, "No yaml library detected")
class YamlSerializerTestCase(SerializersTestBase, TestCase):
serializer_name = "yaml"