예제 #1
0
    def test_camelize(self):
        tests = (
            (
                [
                    1, 'a_bc_d', {
                        'a_bc_d': {
                            'd_ef_g': ['h_ij_k'],
                            2: 2
                        },
                        1: 1
                    }, b"x"
                ],
                [],
                [
                    1, 'a_bc_d', {
                        'aBcD': {
                            'dEfG': ['h_ij_k'],
                            2: 2
                        },
                        1: 1
                    }, b"x"
                ],
            ),
            (
                [
                    1, 'a_bc_d', {
                        'a_bc_d': {
                            'd_ef_g': {
                                'h_ij_k': {
                                    'qr_s': 't_uv'
                                }
                            }
                        }
                    }, {
                        'd_ef_g': {
                            'h_ij_k': 4
                        }
                    }
                ],
                ['*.d_ef_g', '*.*.d_ef_g.h_ij_k'],
                [
                    1, 'a_bc_d', {
                        'aBcD': {
                            'dEfG': {
                                'h_ij_k': {
                                    'qrS': 't_uv'
                                }
                            }
                        }
                    }, {
                        'd_ef_g': {
                            'hIjK': 4
                        }
                    }
                ],
            ),
        )

        for test_in, ignore, test_out in tests:
            self.assertEqual(camelize(test_in, ignore), test_out)
예제 #2
0
    def test_camelize_file(self):
        file1 = InMemoryUploadedFile(StringIO(), "name", "name", "content", 1,
                                     "utf8")
        file2 = InMemoryUploadedFile(StringIO(), "name", "name", "content", 1,
                                     "utf8")
        tests = ((
            [{
                'test_file': file1
            }, file2],
            [],
            [{
                'testFile': file1
            }, file2],
        ), )

        for test_in, ignore, test_out in tests:
            self.assertEqual(camelize(test_in, ignore), test_out)
예제 #3
0
    def test_camelize_queryset(self):
        p1 = Person.objects.create(username="******", label="pang")
        p2 = Person.objects.create(username="******", label="ping")
        tests = ((
            Person.objects.all().order_by('username').values(
                'user_ptr', 'username', 'label'),
            [],
            [{
                'userPtr': p1.pk,
                'username': '******',
                'label': 'pang'
            }, {
                'userPtr': p2.pk,
                'username': '******',
                'label': 'ping'
            }],
        ), )

        for test_in, ignore, test_out in tests:
            self.assertEqual(camelize(test_in, ignore), test_out)
예제 #4
0
 def render(self, data, *args, **kwargs):
     data = camelize(data)
     return super().render(data, *args, **kwargs)
예제 #5
0
    def test_camelize_django_lazy(self):
        tests = (
            (
                [
                    1,
                    gettext_lazy('a_bc_d'), {
                        gettext_lazy('a_bc_d'): {
                            gettext_lazy('d_ef_g'): [gettext_lazy('h_ij_k')],
                            2: 2
                        },
                        1: 1
                    }, b"x"
                ],
                [],
                [
                    1, 'a_bc_d', {
                        'aBcD': {
                            'dEfG': ['h_ij_k'],
                            2: 2
                        },
                        1: 1
                    }, b"x"
                ],
            ),
            (
                [
                    1,
                    gettext_lazy('a_bc_d'), {
                        gettext_lazy('a_bc_d'): {
                            gettext_lazy('d_ef_g'): {
                                gettext_lazy('h_ij_k'): {
                                    gettext_lazy('qr_s'): gettext_lazy('t_uv')
                                }
                            }
                        }
                    }, {
                        gettext_lazy('d_ef_g'): {
                            gettext_lazy('h_ij_k'): 4
                        }
                    }
                ],
                ['*.d_ef_g', '*.*.d_ef_g.h_ij_k'],
                [
                    1, 'a_bc_d', {
                        'aBcD': {
                            'dEfG': {
                                'h_ij_k': {
                                    'qrS': 't_uv'
                                }
                            }
                        }
                    }, {
                        'd_ef_g': {
                            'hIjK': 4
                        }
                    }
                ],
            ),
        )

        for test_in, ignore, test_out in tests:
            self.assertEqual(camelize(test_in, ignore), test_out)