diff options
| author | Tom Christie | 2011-05-10 16:01:58 +0100 |
|---|---|---|
| committer | Tom Christie | 2011-05-10 16:01:58 +0100 |
| commit | 4d126796752cc3c79a24fd9caed49da6c525096f (patch) | |
| tree | 117148c29b0a0f8ca4bbfb299a613b2dbabe8259 /djangorestframework/tests/resource.py | |
| parent | a2575c1191104df024b41c58825b9a24d4c4ae2d (diff) | |
| download | django-rest-framework-4d126796752cc3c79a24fd9caed49da6c525096f.tar.bz2 | |
More tests, getting new serialization into resource
Diffstat (limited to 'djangorestframework/tests/resource.py')
| -rw-r--r-- | djangorestframework/tests/resource.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/djangorestframework/tests/resource.py b/djangorestframework/tests/resource.py new file mode 100644 index 00000000..0ed41951 --- /dev/null +++ b/djangorestframework/tests/resource.py @@ -0,0 +1,31 @@ +"""Tests for the resource module""" +from django.test import TestCase +from djangorestframework.resource import _object_to_data + +import datetime +import decimal + +class TestObjectToData(TestCase): + """Tests for the _object_to_data function""" + + def test_decimal(self): + """Decimals need to be converted to a string representation.""" + self.assertEquals(_object_to_data(decimal.Decimal('1.5')), '1.5') + + def test_function(self): + """Functions with no arguments should be called.""" + def foo(): + return 1 + self.assertEquals(_object_to_data(foo), 1) + + def test_method(self): + """Methods with only a ``self`` argument should be called.""" + class Foo(object): + def foo(self): + return 1 + self.assertEquals(_object_to_data(Foo().foo), 1) + + def test_datetime(self): + """datetime objects are left as-is.""" + now = datetime.datetime.now() + self.assertEquals(_object_to_data(now), now)
\ No newline at end of file |
