def test_rows_alpha_index(self): """ TODO this test is unstable (once fails, once not) :return: """ post = QueryDict('row[0][fld]=0&row[bla][fld]=bla') with self.assertRaises(ValueError): unpack_post(post)
def test_rows_inverse_order_numcomparison(self): """ to check that 1, 10, 2 are sorted numerically and not alphabetically """ post = QueryDict('&'.join( ['row[{}][fld]={}'.format(i, i) for i in range(11, -1, -1)])) self.assertDictEqual( unpack_post(post), { 'row': [{ 'fld': '0' }, { 'fld': '1' }, { 'fld': '2' }, { 'fld': '3' }, { 'fld': '4' }, { 'fld': '5' }, { 'fld': '6' }, { 'fld': '7' }, { 'fld': '8' }, { 'fld': '9' }, { 'fld': '10' }, { 'fld': '11' }] }) pass
def test_object(self): post = QueryDict('obj[field1]=val1&obj[field2]=val2') self.assertDictEqual(unpack_post(post), {'obj': { 'field1': 'val1', 'field2': 'val2' }})
def test_nested_rows_not_numbered(self): post = QueryDict('row[0][entry_id]=val1&row[0][entry_options][]=val2&row[0][entry_options][]=val3') self.assertDictEqual(unpack_post(post), { 'row': [{ 'entry_id': 'val1', 'entry_options': ['val2', 'val3'] }] })
def test_rows_inverse_order(self): post = QueryDict('row[1][field1]=val3&row[0][field1]=val1&row[0][field2]=val2') self.assertDictEqual(unpack_post(post), { 'row': [ {'field1': 'val1', 'field2': 'val2'}, {'field1': 'val3'} ] })
def test_single_with_brackets(self): """ Where we assume that the developer wanted list """ post = QueryDict('field[]=val1') self.assertDictEqual(unpack_post(post), { 'field': ['val1'] })
def test_rows_missing_index(self): """ For now, we don't throw errors.. Should we? """ post = QueryDict('row[0][fld]=0&row[2][fld]=2') self.assertDictEqual(unpack_post(post), {'row': [{ 'fld': '0' }, { 'fld': '2' }]})
def test_single_wo_brackets(self): post = QueryDict('field=val1') self.assertDictEqual(unpack_post(post), {'field': 'val1'})
def test_multiple_with_brackets(self): post = QueryDict('field[]=val1&field[]=val2') self.assertDictEqual(unpack_post(post), {'field': ['val1', 'val2']})