Skip to content

Commit

Permalink
Fixed DecimalField unittest to properly test for the right value & be…
Browse files Browse the repository at this point in the history
… assoicated with the right field type.
  • Loading branch information
Christopher Grebs authored and toastdriven committed Jun 26, 2011
1 parent d0bb1a5 commit 5ebd1b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tastypie/resources.py
Expand Up @@ -1260,8 +1260,10 @@ def api_field_from_django_field(cls, f, default=CharField):
result = DateTimeField
elif f.get_internal_type() in ('BooleanField', 'NullBooleanField'):
result = BooleanField
elif f.get_internal_type() in ('DecimalField', 'FloatField'):
elif f.get_internal_type() in ('FloatField',):
result = FloatField
elif f.get_internal_type() in ('DecimalField',):
result = DecimalField
elif f.get_internal_type() in ('IntegerField', 'PositiveIntegerField', 'PositiveSmallIntegerField', 'SmallIntegerField'):
result = IntegerField
elif f.get_internal_type() in ('FileField', 'ImageField'):
Expand Down
11 changes: 8 additions & 3 deletions tests/core/tests/fields.py
@@ -1,5 +1,6 @@
import datetime
from dateutil.tz import *
from django.db import models
from django.contrib.auth.models import User
from django.test import TestCase
from tastypie.bundle import Bundle
Expand Down Expand Up @@ -285,12 +286,16 @@ def test_dehydrate(self):
note = Note.objects.get(pk=1)
bundle = Bundle(obj=note)

field_1 = DecimalField(default=20)
self.assertEqual(field_1.dehydrate(bundle), 20.0)
field_1 = DecimalField(default='20')
self.assertEqual(field_1.dehydrate(bundle), Decimal('20.0'))

field_2 = DecimalField(default=18.5)
field_2 = DecimalField(default='18.5')
self.assertEqual(field_2.dehydrate(bundle), Decimal('18.5'))

def test_model_resource_correct_association(self):
api_field = ModelResource.api_field_from_django_field(models.DecimalField())
self.assertEqual(api_field, DecimalField)


class ListFieldTestCase(TestCase):
fixtures = ['note_testdata.json']
Expand Down

0 comments on commit 5ebd1b5

Please sign in to comment.