示例#1
0
    def test_list_field(self):
        field = ListField(AuthorModel)

        author_dict_list = [
            {
                'name': 'Jacob',
                'email': '*****@*****.**',
            },
            {
                'name': "Bob",
                'email': None
            },
            {
                'name': "Jane",
                "email": "*****@*****.**",
            }
        ]
        resource_list = field.scrub_value(author_dict_list)

        assert len(resource_list) == 3
        assert resource_list[0].name == 'Jacob'
        assert resource_list[1].name == 'Bob'
        assert resource_list[2].name == 'Jane'

        assert resource_list[0].email == '*****@*****.**'
        assert resource_list[1].email is None
        assert resource_list[2].email == '*****@*****.**'

        new_author_dict_list = field.descrub_value(resource_list)

        assert new_author_dict_list == author_dict_list
示例#2
0
    def test_list_field(self):
        field = ListField(AuthorModel)

        author_dict_list = [{
            'name': 'Jacob',
            'email': '*****@*****.**',
        }, {
            'name': "Bob",
            'email': None
        }, {
            'name': "Jane",
            "email": "*****@*****.**",
        }]
        resource_list = field.scrub_value(author_dict_list)

        assert len(resource_list) == 3
        assert resource_list[0].name == 'Jacob'
        assert resource_list[1].name == 'Bob'
        assert resource_list[2].name == 'Jane'

        assert resource_list[0].email == '*****@*****.**'
        assert resource_list[1].email is None
        assert resource_list[2].email == '*****@*****.**'

        new_author_dict_list = field.descrub_value(resource_list)

        assert new_author_dict_list == author_dict_list
示例#3
0
 def test_empty_list_field(self):
     field = ListField(AuthorModel)
     for val in ('', None, {}):
         for result in (field.scrub_value(val), field.descrub_value(val)):
             assert hasattr(result, '__iter__')
             assert len(result) == 0
示例#4
0
 def test_empty_list_field(self):
     field = ListField(AuthorModel)
     assert field.scrub_value([]) == []
     assert field.scrub_value(None) == []
示例#5
0
 def test_empty_list_field(self):
     field = ListField(AuthorModel)
     for val in ('', None, {}):
         for result in (field.scrub_value(val), field.descrub_value(val)):
             assert hasattr(result, '__iter__')
             assert len(result) == 0