Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse zero padded integers as strings #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rest_framework_xml/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ def _type_convert(self, value):
except ValueError:
pass

if value.startswith('0'):
return value

try:
return int(value)
except ValueError:
Expand Down
8 changes: 6 additions & 2 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import unicode_literals
import datetime


from decimal import Decimal
from django.test import TestCase
from django.test.utils import skipUnless
from django.utils.six.moves import StringIO
Expand All @@ -19,13 +19,17 @@ def setUp(self):
'<field_b>dasd</field_b>'
'<field_c></field_c>'
'<field_d>2011-12-25 12:45:00</field_d>'
'<field_e>121.1</field_e>'
'<field_f>0001</field_f>'
'</root>'
)
self._data = {
'field_a': 121,
'field_b': 'dasd',
'field_c': None,
'field_d': datetime.datetime(2011, 12, 25, 12, 45, 00)
'field_d': datetime.datetime(2011, 12, 25, 12, 45, 00),
'field_e': Decimal('121.1'),
'field_f': '0001',
}
self._complex_data_input = StringIO(
'<?xml version="1.0" encoding="utf-8"?>'
Expand Down
3 changes: 2 additions & 1 deletion tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def test_render_string(self):
Test XML rendering.
"""
renderer = XMLRenderer()
content = renderer.render({'field': 'astring'}, 'application/xml')
content = renderer.render({'field': 'astring', 'field_b': '0001'}, 'application/xml')
self.assertXMLContains(content, '<field>astring</field>')
self.assertXMLContains(content, '<field_b>0001</field_b>')

def test_render_integer(self):
"""
Expand Down