Esempio n. 1
0
    def test_nested_repeated(self):
        m = self.populate_MessageOfTypes()
        m.nestedRepeated.extend([MessageOfTypes.NestedType(req=str(i)) for i in range(10)])

        d = protobuf_to_dict(m)
        self.compare(m, d, exclude=['nestedRepeated'])
        assert d['nestedRepeated'] == [{'req': str(i)} for i in range(10)]

        m2 = dict_to_protobuf(MessageOfTypes, d)
        assert m == m2
Esempio n. 2
0
    def test_nested_repeated(self, add_class_metadata,
                             overwrite_package_with_name):
        m = self.populate_MessageOfTypes()
        m.nestedRepeated.extend(
            [MessageOfTypes.NestedType(req=str(i)) for i in range(10)])

        d = protobuf_to_dict(
            m,
            add_class_metadata=add_class_metadata,
            overwrite_package_with_name=overwrite_package_with_name)
        self.compare(m,
                     d,
                     exclude=['nestedRepeated'],
                     add_class_metadata=add_class_metadata,
                     overwrite_package_with_name=overwrite_package_with_name)
        if not add_class_metadata:
            assert d['nestedRepeated'] == [{'req': str(i)} for i in range(10)]
        else:
            if overwrite_package_with_name is not None:
                assert d['nestedRepeated'] == [{
                    'req':
                    str(i),
                    _CLASS_KEY:
                    'NestedType',
                    _PACKAGE_KEY:
                    overwrite_package_with_name
                } for i in range(10)]
            else:
                assert d['nestedRepeated'] == [{
                    'req':
                    str(i),
                    _CLASS_KEY:
                    'NestedType',
                    _PACKAGE_KEY:
                    'tests.MessageOfTypes'
                } for i in range(10)]

        m2 = dict_to_protobuf(MessageOfTypes, d)
        assert m == m2