mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	Merge pull request #1181 from badale/master
Fixed #1179: RepresenterError with DecimalField and YAMLRenderer
This commit is contained in:
		
						commit
						b3e0145294
					
				| 
						 | 
				
			
			@ -328,7 +328,7 @@ if yaml:
 | 
			
		|||
 | 
			
		||||
    class YAMLRendererTests(TestCase):
 | 
			
		||||
        """
 | 
			
		||||
        Tests specific to the JSON Renderer
 | 
			
		||||
        Tests specific to the YAML Renderer
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        def test_render(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -354,6 +354,17 @@ if yaml:
 | 
			
		|||
            data = parser.parse(StringIO(content))
 | 
			
		||||
            self.assertEqual(obj, data)
 | 
			
		||||
 | 
			
		||||
        def test_render_decimal(self):
 | 
			
		||||
            """
 | 
			
		||||
            Test YAML decimal rendering.
 | 
			
		||||
            """
 | 
			
		||||
            renderer = YAMLRenderer()
 | 
			
		||||
            content = renderer.render({'field': Decimal('111.2')}, 'application/yaml')
 | 
			
		||||
            self.assertYAMLContains(content, "field: '111.2'")
 | 
			
		||||
 | 
			
		||||
        def assertYAMLContains(self, content, string):
 | 
			
		||||
            self.assertTrue(string in content, '%r not in %r' % (string, content))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class XMLRendererTestCase(TestCase):
 | 
			
		||||
    """
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -89,6 +89,9 @@ else:
 | 
			
		|||
                    node.flow_style = best_style
 | 
			
		||||
            return node
 | 
			
		||||
 | 
			
		||||
    SafeDumper.add_representer(decimal.Decimal,
 | 
			
		||||
            SafeDumper.represent_decimal)
 | 
			
		||||
 | 
			
		||||
    SafeDumper.add_representer(SortedDict,
 | 
			
		||||
            yaml.representer.SafeRepresenter.represent_dict)
 | 
			
		||||
    SafeDumper.add_representer(DictWithMetadata,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user