Beispiel #1
0
 def testNumericValue(self):
     # Decimals
     persistedValue = decimal.Decimal("4.5")
     self.assertEquals(
         json_format.convertToPersistenceFormat(persistedValue), u"4.5")
     persistedValue = decimal.Decimal("5")
     self.assertEquals(
         json_format.convertToPersistenceFormat(persistedValue), u"5")
     # Raw integer
     self.assertEquals(json_format.convertToPersistenceFormat(5), u"5")
     # Raw float
     self.assertEquals(json_format.convertToPersistenceFormat(4.5), u"4.5")
Beispiel #2
0
 def testListValue(self):
     persistedValue = [
         decimal.Decimal("2006"),
         decimal.Decimal("10.0"),
         decimal.Decimal("16"),
         decimal.Decimal("10.01")
     ]
     self.assertEquals(
         json_format.convertToPersistenceFormat(persistedValue),
         u"[2006, 10.0, 16, 10.01]")
     persistedValue = list()
     self.assertEquals(
         json_format.convertToPersistenceFormat(persistedValue), u"[]")
Beispiel #3
0
    def testStringValue(self):
        self.assertEquals(json_format.convertToPersistenceFormat(u"test"),
                          '"test"')
        self.assertEquals(json_format.convertToPersistenceFormat("test"),
                          '"test"')

        # Invalid raw string
        orignalFunction = sys.getdefaultencoding
        sys.getdefaultencoding = lambda: None  # Mock encoding determination
        try:
            self.assertRaises(PersistenceError,
                              json_format.convertToPersistenceFormat,
                              _AE.encode("Latin-1)"))
        finally:
            sys.getdefaultencoding = orignalFunction
Beispiel #4
0
    def update(self, properties):
        """ @see: L{NullMetadataStorer<datafinder.persistence.metadata.metadatastorer.NullMetadataStorer>}"""

        connection = self.__connectionPool.acquire()
        try:
            customProperties = self._retrieveCustomProperties(connection)
            customProperties.update(properties)
            newJsonString = json_format.convertToPersistenceFormat(customProperties)
            try:
                connection.update(self.identifier)
                connection.setProperty(self.identifier, JSON_PROPERTY_NAME, newJsonString)
            except SubversionError, error:
                errorMessage = "Cannot update properties of item '%s'. " % self.identifier \
                               + "Reason: '%s'" % error 
                raise PersistenceError(errorMessage)
        finally:
            self.__connectionPool.release(connection)
Beispiel #5
0
def _convertFromDict(value):
    return json_format.convertToPersistenceFormat(value)
Beispiel #6
0
 def testDictValue(self):
     self.assertEquals(json_format.convertToPersistenceFormat(dict()),
                       u"{}")
Beispiel #7
0
 def testDatetimeValue(self):
     persistedValue = datetime.datetime(2006, 10, 16, 10, 19, 39)
     self.assertEquals(
         json_format.convertToPersistenceFormat(persistedValue),
         '"2006-10-16T08:19:39Z"')
Beispiel #8
0
 def testNoneValue(self):
     self.assertEquals(json_format.convertToPersistenceFormat(None), "null")
Beispiel #9
0
 def testBoolValue(self):
     self.assertEquals(json_format.convertToPersistenceFormat(True), "true")
     self.assertEquals(json_format.convertToPersistenceFormat(False),
                       "false")
Beispiel #10
0
def _convertFromDict(value):
    return json_format.convertToPersistenceFormat(value)