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")
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"[]")
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
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)
def _convertFromDict(value): return json_format.convertToPersistenceFormat(value)
def testDictValue(self): self.assertEquals(json_format.convertToPersistenceFormat(dict()), u"{}")
def testDatetimeValue(self): persistedValue = datetime.datetime(2006, 10, 16, 10, 19, 39) self.assertEquals( json_format.convertToPersistenceFormat(persistedValue), '"2006-10-16T08:19:39Z"')
def testNoneValue(self): self.assertEquals(json_format.convertToPersistenceFormat(None), "null")
def testBoolValue(self): self.assertEquals(json_format.convertToPersistenceFormat(True), "true") self.assertEquals(json_format.convertToPersistenceFormat(False), "false")