def test_validate(self): f = VumiMessage(Message) msg = Message() f.validate(msg) self.assertRaises(ValidationError, f.validate, u'this is not a vumi message') self.assertRaises(ValidationError, f.validate, None)
def test_validate(self): f = VumiMessage(Message) msg = Message() f.validate(msg) self.assertRaises( ValidationError, f.validate, u'this is not a vumi message') self.assertRaises( ValidationError, f.validate, None)
class OutboundMessage(Model): VERSION = 5 MIGRATOR = OutboundMessageMigrator # key is message_id msg = VumiMessage(TransportUserMessage) batches = ManyToMany(Batch) # Extra fields for compound indexes batches_with_addresses = ListOf(Unicode(), index=True) batches_with_addresses_reverse = ListOf(Unicode(), index=True) def save(self): # We override this method to set our index fields before saving. self.batches_with_addresses = [] self.batches_with_addresses_reverse = [] timestamp = self.msg['timestamp'] if not isinstance(timestamp, basestring): timestamp = format_vumi_date(timestamp) reverse_ts = to_reverse_timestamp(timestamp) for batch_id in self.batches.keys(): self.batches_with_addresses.append( u"%s$%s$%s" % (batch_id, timestamp, self.msg['to_addr'])) self.batches_with_addresses_reverse.append( u"%s$%s$%s" % (batch_id, reverse_ts, self.msg['to_addr'])) return super(OutboundMessage, self).save()
class Event(Model): VERSION = 2 MIGRATOR = EventMigrator # key is event_id event = VumiMessage(TransportEvent) message = ForeignKey(OutboundMessage) batches = ManyToMany(Batch) # Extra fields for compound indexes message_with_status = Unicode(index=True, null=True) batches_with_statuses_reverse = ListOf(Unicode(), index=True) def save(self): # We override this method to set our index fields before saving. timestamp = self.event['timestamp'] if not isinstance(timestamp, basestring): timestamp = format_vumi_date(timestamp) status = self.event['event_type'] if status == "delivery_report": status = "%s.%s" % (status, self.event['delivery_status']) self.message_with_status = u"%s$%s$%s" % (self.message.key, timestamp, status) self.batches_with_statuses_reverse = [] reverse_ts = to_reverse_timestamp(timestamp) for batch_id in self.batches.keys(): self.batches_with_statuses_reverse.append( u"%s$%s$%s" % (batch_id, reverse_ts, status)) return super(Event, self).save()
class InboundMessageV3(Model): bucket = 'inboundmessage' VERSION = 3 MIGRATOR = InboundMessageMigrator # key is message_id msg = VumiMessage(TransportUserMessage) batches = ManyToMany(BatchVNone) # Extra fields for compound indexes batches_with_timestamps = ListOf(Unicode(), index=True) batches_with_addresses = ListOf(Unicode(), index=True) def save(self): # We override this method to set our index fields before saving. batches_with_timestamps = [] batches_with_addresses = [] timestamp = self.msg['timestamp'] for batch_id in self.batches.keys(): batches_with_timestamps.append(u"%s$%s" % (batch_id, timestamp)) batches_with_addresses.append( u"%s$%s$%s" % (batch_id, timestamp, self.msg['from_addr'])) self.batches_with_timestamps = batches_with_timestamps self.batches_with_addresses = batches_with_addresses return super(InboundMessageV3, self).save()
class InboundMessage(Model): VERSION = 1 MIGRATOR = InboundMessageMigrator # key is message_id msg = VumiMessage(TransportUserMessage) batches = ManyToMany(Batch)
class InboundMessageV1(Model): bucket = 'inboundmessage' VERSION = 1 MIGRATOR = InboundMessageMigrator # key is message_id msg = VumiMessage(TransportUserMessage) batches = ManyToMany(BatchVNone)
class Event(Model): VERSION = 1 MIGRATOR = EventMigrator # key is event_id event = VumiMessage(TransportEvent) message = ForeignKey(OutboundMessage) # Extra fields for compound indexes message_with_status = Unicode(index=True, null=True) def save(self): # We override this method to set our index fields before saving. timestamp = self.event['timestamp'] status = self.event['event_type'] if status == "delivery_report": status = "%s.%s" % (status, self.event['delivery_status']) self.message_with_status = u"%s$%s$%s" % (self.message.key, timestamp, status) return super(Event, self).save()
class OutboundMessage(Model): VERSION = 3 MIGRATOR = OutboundMessageMigrator # key is message_id msg = VumiMessage(TransportUserMessage) batches = ManyToMany(Batch) # Extra fields for compound indexes batches_with_timestamps = ListOf(Unicode(), index=True) batches_with_addresses = ListOf(Unicode(), index=True) def save(self): # We override this method to set our index fields before saving. batches_with_timestamps = [] batches_with_addresses = [] timestamp = format_vumi_date(self.msg['timestamp']) for batch_id in self.batches.keys(): batches_with_timestamps.append(u"%s$%s" % (batch_id, timestamp)) batches_with_addresses.append( u"%s$%s$%s" % (batch_id, timestamp, self.msg['to_addr'])) self.batches_with_timestamps = batches_with_timestamps self.batches_with_addresses = batches_with_addresses return super(OutboundMessage, self).save()
class InboundMessageVNone(Model): bucket = 'inboundmessage' # key is message_id msg = VumiMessage(TransportUserMessage) batch = ForeignKey(BatchVNone, null=True)
class EventVNone(Model): bucket = 'event' # key is event_id event = VumiMessage(TransportEvent) message = ForeignKey(OutboundMessageVNone)
class VumiMessageModel(Model): msg = VumiMessage(TransportUserMessage)
class Event(Model): # key is message_id event = VumiMessage(TransportEvent) message = ForeignKey(OutboundMessage)
class VumiMessageModel(Model): """ Toy model for VumiMessage tests. """ msg = VumiMessage(TransportUserMessage)