def get_mongo_field_names_dict(self): """ Return a dictionary of fieldnames as saved in mongodb with corresponding xform field names e.g {"Q1Lg==1": "Q1.1"} """ names = {} for elem in self.get_survey_elements(): names[_encode_for_mongo(text(elem.get_abbreviated_xpath()))] = \ elem.get_abbreviated_xpath() return names
def test_api_decode_from_mongo(self): field = "$section1.group01.question1" encoded = _encode_for_mongo(field) self.assertEqual(encoded, ( "%(dollar)ssection1%(dot)sgroup01%(dot)squestion1" % { "dollar": base64.b64encode( '$'.encode('utf-8')).decode('utf-8'), "dot": base64.b64encode('.'.encode('utf-8')).decode('utf-8')})) decoded = _decode_from_mongo(encoded) self.assertEqual(field, decoded)
def test_api_decode_from_mongo(self): field = "$section1.group01.question1" encoded = _encode_for_mongo(field) self.assertEqual( encoded, ("%(dollar)ssection1%(dot)sgroup01%(dot)squestion1" % { "dollar": base64.b64encode( '$'.encode('utf-8')).decode('utf-8'), "dot": base64.b64encode('.'.encode('utf-8')).decode('utf-8') })) decoded = _decode_from_mongo(encoded) self.assertEqual(field, decoded)