from testcase import TestCase from variabledecode import variableDecode, variableEncode class DecodeTest(TestCase): def testEncode(self, description, input, output): input = self.cgiParse(input) self.assertDictEqual(variableDecode(input), output) params_testEncode = [ ('simple', 'a=10', {'a': '10'}), ('double', 'a=10&a=10', {'a': ['10', '10']}), ('double2', 'a=1&b=2', {'a': '1', 'b': '2'}), ('list', 'a-1=1&a-2=2', {'a': ['1', '2']}), ('nestlist', 'a-1.b=1&a-1.c=2&a-2.e=5', {'a': [{'b': '1', 'c': '2'}, {'e': '5'}]}), ('nestdict', 'a.b.c=1&a.b=2', {'a': {'b': {None: '2', 'c': '1'}}}), ('bignest', 'a-1.b-1=1&a-1.b-2=2&a-2.b-1=3&a-3.b-3=4', {'a': [{'b': ['1', '2']}, {'b': ['3']}, {'b': ['4']}]}), ('deepnest', 'a.b-1=1&a.b-2=2&a.b=3&a.b=4', {'a': {'b': ['3', '4', '1', '2']}}), ('rep', 'a-1=1&a-2=2&a-3=3&a--repetitions=5', {'a': ['1', '2', '3', '', '']}), ('example', '_formName_=form&items-0=whatever&items-0.hash=XXX&required=yes', {'_formName_': 'form', 'required': 'yes', 'items': [{None: 'whatever', 'hash': 'XXX'}]}), ('example2', '_formName_=form&items-0=test&items-0=test&items-0.hash=XXX&required=', {'_formName_': 'form', 'required': '', 'items': [{None: ['test', 'test'], 'hash': 'XXX'}]}), ]