def create_message_for_patient(self, timestamp): msg = WisepillMessage( sms_message='', # ignore timestamp=timestamp, msisdn=self.patient.wisepill_msisdn, patient=self.patient) msg.save()
def create_wisepill_message(self, data=None): defaults = dict(msisdn=self.patient.wisepill_msisdn, timestamp=datetime.datetime.now(), message_type=WisepillMessage.LIVE_EVENT, patient=self.patient, batterystrength=WISEPILL_LOW_BATTERY+1, ) if data: defaults.update(data) msg = WisepillMessage() for key,value in defaults.iteritems(): setattr(msg, key, value) msg.save() return msg
def create_wisepill_message(self, data=None): defaults = dict( msisdn=self.patient.wisepill_msisdn, timestamp=datetime.datetime.now(), message_type=WisepillMessage.LIVE_EVENT, patient=self.patient, batterystrength=WISEPILL_LOW_BATTERY + 1, ) if data: defaults.update(data) msg = WisepillMessage() for key, value in defaults.iteritems(): setattr(msg, key, value) msg.save() return msg
def test_message_parsing(self): for testmsg in self.testmsgs: obj = WisepillMessage(sms_message = testmsg['raw']) now = datetime.datetime.now() obj.save() # causes the parse # make sure we got the data out of the message correctly self.assertEquals(testmsg['msisdn'], obj.msisdn) self.assertEquals(testmsg['timestamp'], obj.timestamp) self.assertEquals(testmsg['message_type'], obj.message_type) self.assertEquals(testmsg['raw'], obj.sms_message) # make sure the time received is sane fudge = abs((now - obj.time_received)) self.assertTrue(fudge < datetime.timedelta(seconds=10)) # make sure we found a matching patient self.assertEquals(testmsg['patient'], obj.patient) self.assertEquals(testmsg['msisdn'], obj.patient.wisepill_msisdn)
def test_message_parsing(self): for testmsg in self.testmsgs: obj = WisepillMessage(sms_message=testmsg["raw"]) now = datetime.datetime.now() obj.save() # causes the parse # make sure we got the data out of the message correctly self.assertEquals(testmsg["msisdn"], obj.msisdn) self.assertEquals(testmsg["timestamp"], obj.timestamp) self.assertEquals(testmsg["message_type"], obj.message_type) self.assertEquals(testmsg["raw"], obj.sms_message) # make sure the time received is sane fudge = abs((now - obj.time_received)) self.assertTrue(fudge < datetime.timedelta(seconds=10)) # make sure we found a matching patient self.assertEquals(testmsg["patient"], obj.patient) self.assertEquals(testmsg["msisdn"], obj.patient.wisepill_msisdn)
def test_only_parsed_on_creation(self): """Test that the raw message is only parsed into the other fields when we create the object, so we can edit the object later and not have our changes reverted every time we save it.""" obj = WisepillMessage(sms_message = self.testmsgs[0]['raw']) obj.save() # now change the the sms message and save again # other values should not change obj.sms_message = self.testmsgs[1]['raw'] obj.save() self.assertEquals(obj.msisdn, self.testmsgs[0]['msisdn'])
def test_only_parsed_on_creation(self): """Test that the raw message is only parsed into the other fields when we create the object, so we can edit the object later and not have our changes reverted every time we save it.""" obj = WisepillMessage(sms_message=self.testmsgs[0]["raw"]) obj.save() # now change the the sms message and save again # other values should not change obj.sms_message = self.testmsgs[1]["raw"] obj.save() self.assertEquals(obj.msisdn, self.testmsgs[0]["msisdn"])
def create_message_for_patient(self, timestamp): msg = WisepillMessage( sms_message="", timestamp=timestamp, msisdn=self.patient.wisepill_msisdn, patient=self.patient # ignore ) msg.save()