def test_reminder_set(self): now = datetime.utcnow() people = list( RandrReminder(TEST_DOMAIN, datetime.utcnow()).get_people()) self.assertEqual(len(people), 1) self.assertEqual(people[0].get_id, self.user1.get_id) self.facility.metadata['group'] = DeliveryGroups( ).current_delivering_group() self.facility.save() people = list( SupervisionReminder(TEST_DOMAIN, datetime.utcnow()).get_people()) self.assertEqual(len(people), 1) update_statuses([self.facility.get_id], SupplyPointStatusTypes.SUPERVISION_FACILITY, SupplyPointStatusValues.REMINDER_SENT) people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 0) SupplyPointStatus.objects.all().delete() people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 1) SupplyPointStatus.objects.create( status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY, status_value=SupplyPointStatusValues.RECEIVED, location_id=self.facility.get_id) people = list(SupervisionReminder(TEST_DOMAIN, now).get_people()) self.assertEqual(len(people), 0)
def test_supervision_reminder(self): date = datetime(2015, 5, 1) SupervisionReminder(TEST_DOMAIN, date).send() self.assertEqual(SMS.objects.count(), 2) statuses = SupplyPointStatus.objects.filter(status_type=SupplyPointStatusTypes.SUPERVISION_FACILITY) self.assertEqual(statuses.count(), 2) smses = SMS.objects.all() self.assertEqual(smses.first().text, six.text_type(SUPERVISION_REMINDER)) self.assertSetEqual( set(statuses.values_list('location_id', flat=True)), {self.facility.get_id, self.facility2.get_id} ) now = datetime.utcnow() SupervisionReminder(TEST_DOMAIN, date).send() self.assertEqual(SMS.objects.filter(date__gte=now).count(), 0)