Exemplo n.º 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)
Exemplo n.º 2
0
        def to_native(self, value):
            if isinstance(value, dict) or value is None:
                return value

            value = HStoreDict(value)

            return value
Exemplo n.º 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
Exemplo n.º 4
0
 def test_hstoredictionary_unicoce_vs_str(self):
     d = HStoreDict({ 'test': 'test' })
     self.assertEqual(d.__str__(), d.__unicode__())
Exemplo n.º 5
0
 def test_get_default(self):
     d = HStoreDict()
     self.assertIsNone(d.get('none_key', None))
     self.assertIsNone(d.get('none_key'))
Exemplo n.º 6
0
 def test_hstoredictionary_unicode_vs_str(self):
     d = HStoreDict({'test': 'test'})
     self.assertEqual(d.__str__(), d.__unicode__())
Exemplo n.º 7
0
 def test_get_default(self):
     d = HStoreDict()
     self.assertIsNone(d.get('none_key', None))
     self.assertIsNone(d.get('none_key'))
Exemplo n.º 8
0
 def test_get_default(self):
     d = HStoreDict()
     self.assertIsNone(d.get('none_key', None))
     
     with self.assertRaises(KeyError):
         d.get('none_key')