コード例 #1
0
ファイル: utils.py プロジェクト: GunioRobot/django-features
    def test_with_fields(self):
        fk_obj = RelationshipTestModel.objects.create()
        m2m_obj = RelationshipTestModel.objects.create()
        obj = TestModel.objects.create(test_fk=fk_obj)
        obj.test_m2m.add(m2m_obj)
        obj.save()
        
        fields = (
            'test_attr',
            'some_field',
            ('test_fk', lambda o: o.id),
            ('test_m2m', lambda o: o.some_attr),
        )
        
        expected = {
            'test_attr': 'test attr value',
            'some_field': 'test string',
            'test_fk': fk_obj.id,
            'test_m2m': ['Attribute value.'],
        }

        d = obj_to_dict(fields)(obj)
        self.assertEqual(d, expected)
コード例 #2
0
ファイル: utils.py プロジェクト: GunioRobot/django-features
 def test_with_no_fields(self):
     to_dict = obj_to_dict([])
     self.assertEqual(to_dict(object()), {})