예제 #1
0
    def test_hstoredictionaryexception(self):
        # ok
        HStoreDict({})

        # json object string allowed
        HStoreDict('{}')

        # None is ok, will be converted to empty dict
        HStoreDict(None)
        HStoreDict()

        # non-json string not allowed
        with self.assertRaises(HStoreDictException):
            HStoreDict('wrong')

        # list not allowed
        with self.assertRaises(HStoreDictException):
            HStoreDict(['wrong'])

        # json array string representation not allowed
        with self.assertRaises(HStoreDictException):
            HStoreDict('["wrong"]')

        # number not allowed
        with self.assertRaises(HStoreDictException):
            HStoreDict(3)
예제 #2
0
        def to_native(self, value):
            if isinstance(value, dict) or value is None:
                return value

            value = HStoreDict(value)

            return value
예제 #3
0
 def from_native(self, value):
     if value:
         try:
             return HStoreDict(value)
         except HStoreDictException as e:
             raise ValidationError(
                 _('Invalid JSON: %s' % e.json_error_message))
     else:
         return None
예제 #4
0
 def test_hstoredictionary_unicoce_vs_str(self):
     d = HStoreDict({ 'test': 'test' })
     self.assertEqual(d.__str__(), d.__unicode__())
예제 #5
0
 def test_get_default(self):
     d = HStoreDict()
     self.assertIsNone(d.get('none_key', None))
     self.assertIsNone(d.get('none_key'))
예제 #6
0
 def test_hstoredictionary_unicode_vs_str(self):
     d = HStoreDict({'test': 'test'})
     self.assertEqual(d.__str__(), d.__unicode__())
예제 #7
0
 def test_get_default(self):
     d = HStoreDict()
     self.assertIsNone(d.get('none_key', None))
     self.assertIsNone(d.get('none_key'))
예제 #8
0
 def test_get_default(self):
     d = HStoreDict()
     self.assertIsNone(d.get('none_key', None))
     
     with self.assertRaises(KeyError):
         d.get('none_key')