Beispiel #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
Beispiel #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
Beispiel #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
Beispiel #4
0
 def test_empty_list_field(self):
     field = ListField(AuthorModel)
     assert field.scrub_value([]) == []
     assert field.scrub_value(None) == []
Beispiel #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