Example #1
0
    def test_dict_field(self):
        field = DictField(AuthorModel)
        author_dict_dict = {
            'main': {
                'name': 'Jacob',
                'email': '*****@*****.**',
            },
            'ghost_writer': {
                'name': "Bob",
                'email': None,
            },
        }
        resource_dict = field.scrub_value(author_dict_dict)

        assert len(resource_dict.keys()) == 2
        assert resource_dict['main'].name == 'Jacob'
        assert resource_dict['main'].email == '*****@*****.**'

        assert resource_dict['ghost_writer'].name == 'Bob'

        new_author_dict_dict = field.descrub_value(resource_dict)
        assert new_author_dict_dict == author_dict_dict
Example #2
0
    def test_dict_field(self):
        field = DictField(AuthorModel)
        author_dict_dict = {
            'main': {
                'name': 'Jacob',
                'email': '*****@*****.**',
            },
            'ghost_writer': {
                'name': "Bob",
                'email': None,
            },
        }
        resource_dict = field.scrub_value(author_dict_dict)

        assert len(resource_dict.keys()) == 2
        assert resource_dict['main'].name == 'Jacob'
        assert resource_dict['main'].email == '*****@*****.**'

        assert resource_dict['ghost_writer'].name == 'Bob'

        new_author_dict_dict = field.descrub_value(resource_dict)
        assert new_author_dict_dict == author_dict_dict
Example #3
0
 def test_empty_dict_field(self):
     field = DictField(AuthorModel)
     for val in ('', None, {}):
         for result in (field.scrub_value(val), field.descrub_value(val)):
             assert hasattr(result, 'keys')
             assert len(result) == 0
Example #4
0
 def test_empty_dict_field(self):
     field = DictField(AuthorModel)
     assert field.scrub_value({}) == {}
     assert field.scrub_value(None) == {}
Example #5
0
 def test_empty_dict_field(self):
     field = DictField(AuthorModel)
     for val in ('', None, {}):
         for result in (field.scrub_value(val), field.descrub_value(val)):
             assert hasattr(result, 'keys')
             assert len(result) == 0