def to_json(self): "Returns a JSON-friendly python dictionary." encoded = super(PullRequestMessage, self).to_json() encoded['operations'] = map(encode_dict(Operation), imap(properties_dict, self.operations)) encoded['latest_version_id'] = encode(types.Integer())( self.latest_version_id) return encoded
def to_json(self): """ Returns a JSON-friendly python dictionary. Structure:: created: datetime, node_id: node primary key or null, key: a string generated from the secret and part of the message, latest_version_id: number or null, operations: list of operations, payload: dictionay with lists of objects mapped to model names """ encoded = super(PushMessage, self).to_json() encoded['created'] = encode(types.DateTime())(self.created) encoded['node_id'] = encode(types.Integer())(self.node_id) encoded['key'] = encode(types.String())(self.key) encoded['latest_version_id'] = encode(types.Integer())( self.latest_version_id) encoded['operations'] = map(encode_dict(Operation), imap(properties_dict, self.operations)) return encoded
def to_json(self): """ Returns a JSON-friendly python dictionary. Structure:: created: datetime, operations: list of operations, versions: list of versions, payload: dictionary with lists of objects mapped to model names """ encoded = super(PullMessage, self).to_json() encoded["created"] = encode(types.DateTime())(self.created) encoded["operations"] = map(encode_dict(Operation), imap(properties_dict, self.operations)) encoded["versions"] = map(encode_dict(Version), imap(properties_dict, self.versions)) return encoded
def to_json(self): """ Returns a JSON-friendly python dictionary. Structure:: created: datetime, operations: list of operations, versions: list of versions, payload: dictionary with lists of objects mapped to model names """ encoded = super(PullMessage, self).to_json() encoded['created'] = encode(types.DateTime())(self.created) encoded['operations'] = map(encode_dict(Operation), imap(properties_dict, self.operations)) encoded['versions'] = map(encode_dict(Version), imap(properties_dict, self.versions)) return encoded
def test_encode_date(): today = datetime.date.today() e = encode(types.Date()) d = decode(types.Date()) assert today == d(e(today))
def test_encode_float_numeric(): num = 3.3 e = encode(types.Numeric(asdecimal=False)) d = decode(types.Numeric(asdecimal=False)) assert num == d(e(num))
def test_encode_numeric(): num = decimal.Decimal('3.3') e = encode(types.Numeric()) d = decode(types.Numeric()) assert num == d(e(num))
def test_encode_datetime(): now = datetime.datetime.now() e = encode(types.DateTime()) d = decode(types.DateTime()) # microseconds are lost, but that's ok assert now.timetuple()[:6] == d(e(now)).timetuple()[:6]
def to_json(self): "Returns a JSON-friendly python dictionary." encoded = super(PullRequestMessage, self).to_json() encoded["operations"] = map(encode_dict(Operation), imap(properties_dict, self.operations)) encoded["latest_version_id"] = encode(types.Integer())(self.latest_version_id) return encoded