示例#1
0
 def test_int_list_key(self):
     """Check that int key results in valid dictionary with list"""
     data = {
         "sample[d][0]": "val-2",
     }
     res = parsers.parse_multipart_data(data)
     self.assertEqual(res, {
         "sample": {
             "d": ["val-2"],
         }
     })
示例#2
0
 def test_str_list_key(self):
     """Check that string keys results in valid dictionary"""
     data = {
         "sample[d][_obj][key-2]": "val-2",
     }
     res = parsers.parse_multipart_data(data)
     self.assertEqual(res, {
         "sample": {
             "d": {"key-2": "val-2"},
         }
     })
示例#3
0
    def _parse_data(self, request):
        dt_cp = request.data
        for k in dt_cp:
            if dt_cp[k] in ['', 'null']:
                dt_cp[k] = None
            elif dt_cp[k] == 'true':
                dt_cp[k] = True
            elif dt_cp[k] == 'false':
                dt_cp[k] = False

        dt = parse_multipart_data(dt_cp)
        return dt
示例#4
0
 def test_mix(self):
     """Check that int key results in valid dictionary with list"""
     data = {
         "one": "two",
         "sample[d][0]": "val-0",
         "sample[d][1]": "val-1",
         "sample[extra][_obj][key-2]": "val-2",
         "sample[extra][_obj][key-5]": "val-5",
     }
     res = parsers.parse_multipart_data(data)
     self.assertEqual(res, {
         "one": "two",
         "sample": {
             "d": ["val-0", "val-1"],
             "extra": {"key-2": "val-2", "key-5": "val-5"}
         }
     })
示例#5
0
 def test_use_case(self):
     """Check live use case sample"""
     data = {
         u'attachments[8][_obj][type]': [u'133'],
         u'attachments[7][_obj][id]': [u'1681'],
         u'attachments[0][_obj][intervention]': [u'71'],
         u'sector_locations[0][_obj][locations][4]': [u'7705'],
         u'sector_locations[0][_obj][locations][0]': [u'7699'],
         u'attachments[8][_obj][id]': [u'1693'],
         u'sector_locations[0][_obj][locations][2]': [u'7702'],
         u'attachments[1][_obj][id]': [u'1691'],
         u'attachments[2][_obj][id]': [u'1692'],
         u'attachments[5][_obj][type]': [u'135'],
         u'attachments[2][_obj][type]': [u'135'],
         u'attachments[6][_obj][id]': [u'1680'],
         u'offices[0]': [u'1'],
         u'unicef_focal_points[0]': [u'1086'],
         u'attachments[0][_obj][attachment]': ["sample.pdf"],
         u'partner_focal_points[0]': [u'99'],
         u'attachments[1][_obj][type]': [u'135'],
         u'sector_locations[0][_obj][id]': [u'230'],
         u'sector_locations[0][_obj][sector]': [u'4'],
         u'attachments[6][_obj][type]': [u'135'],
         u'attachments[5][_obj][id]': [u'1679'],
         u'sector_locations[0][_obj][locations][3]': [u'7704'],
         u'attachments[0][_obj][type]': [u'135'],
         u'sector_locations[0][_obj][locations][5]': [u'7701'],
         u'attachments[4][_obj][type]': [u'135'],
         u'sector_locations[0][_obj][locations][1]': [u'7706'],
         u'attachments[0][_obj][id]': [None],
         u'attachments[3][_obj][id]': [u'1677'],
         u'attachments[4][_obj][id]': [u'1678'],
         u'attachments[3][_obj][type]': [u'135'],
         u'attachments[9][_obj][type]': [u'135'],
         u'attachments[9][_obj][id]': [u'1694'],
         u'attachments[7][_obj][type]': [u'135']
     }
     res = parsers.parse_multipart_data(data)
     self.assertEqual(res, {
         'unicef_focal_points': [[u'1086']],
         'sector_locations': [
             {
                 'sector': [u'4'],
                 'id': [u'230'],
                 'locations': [
                     [u'7699'],
                     [u'7706'],
                     [u'7702'],
                     [u'7704'],
                     [u'7705'],
                     [u'7701']
                 ]
             }
         ],
         'offices': [[u'1']],
         'attachments': [
             {'intervention': [u'71'], 'type': [u'135'], 'attachment': ['sample.pdf'], 'id': [None]},
             {'type': [u'135'], 'id': [u'1691']},
             {'type': [u'135'], 'id': [u'1692']},
             {'type': [u'135'], 'id': [u'1677']},
             {'type': [u'135'], 'id': [u'1678']},
             {'type': [u'135'], 'id': [u'1679']},
             {'type': [u'135'], 'id': [u'1680']},
             {'type': [u'135'], 'id': [u'1681']},
             {'type': [u'133'], 'id': [u'1693']},
             {'type': [u'135'], 'id': [u'1694']}
         ],
         'partner_focal_points': [[u'99']]
     })
示例#6
0
 def test_simple(self):
     data = {"one": "two"}
     res = parsers.parse_multipart_data(data)
     self.assertEqual(res, {"one": "two"})
示例#7
0
 def test_empty(self):
     self.assertEqual(parsers.parse_multipart_data({}), {})