def test_region_subscription(self): user = get_user() r = Region.objects.get(name='1') Subscription.objects.create(user=user, region=r, lookup_id='r%s' % r.id) notify = Notify() emails = notify.gather_subscribers( Appeal.objects.filter(created_at__gte=notify.get_time_threshold()), RecordType.APPEAL, SubscriptionType.NEW, ) self.assertEqual(len(emails), 1) self.assertEqual(emails[0], user.email)
def test_new_record_subscription(self): # Subscription to NEW_EMERGENCIES (orig: new field reports) user = get_user() Subscription.objects.create( user=user, rtype=RecordType.NEW_EMERGENCIES, #FIELD_REPORT, stype=SubscriptionType.NEW, ) notify = Notify() emails = notify.gather_subscribers( FieldReport.objects.filter(created_at__gte=notify.diff_5_minutes()), RecordType.NEW_EMERGENCIES, #FIELD_REPORT, SubscriptionType.NEW, ) self.assertEqual(len(emails), 1) self.assertEqual(emails[0], user.email)
def test_dtype_subscription(self): # Subscription to a disaster type user = get_user() d = DisasterType.objects.get(name='d1') Subscription.objects.create( user=user, dtype=d, lookup_id='d%s' % d.id, ) notify = Notify() emails = notify.gather_subscribers( FieldReport.objects.filter(created_at__gte=notify.diff_5_minutes()), RecordType.FIELD_REPORT, SubscriptionType.NEW, ) self.assertEqual(len(emails), 1) self.assertEqual(emails[0], user.email)
def test_region_subscription(self): # Subscription to a region user = get_user() r = Region.objects.get(name=1) Subscription.objects.create( user=user, region=r, lookup_id='r%s' % r.id, ) notify = Notify() emails = notify.gather_subscribers( FieldReport.objects.filter(created_at__gte=notify.diff_5_minutes()), RecordType.FIELD_REPORT, SubscriptionType.NEW, ) self.assertEqual(len(emails), 1) self.assertEqual(emails[0], user.email)
def test_country_subscription(self): # Subscription to a country user = get_user() c = Country.objects.get(name='c2') Subscription.objects.create( user=user, country=c, lookup_id='c%s' % c.id, ) notify = Notify() emails = notify.gather_subscribers( FieldReport.objects.filter(created_at__gte=notify.diff_5_minutes()), RecordType.FIELD_REPORT, SubscriptionType.NEW, ) self.assertEqual(len(emails), 1) self.assertEqual(emails[0], user.email)
def test_new_record_subscription(self): # Subscription to new field reports user = get_user() Subscription.objects.create( user=user, rtype=RecordType.FIELD_REPORT, stype=SubscriptionType.NEW, ) notify = Notify() emails = notify.gather_subscribers( FieldReport.objects.filter( created_at__gte=notify.get_time_threshold()), RecordType.FIELD_REPORT, SubscriptionType.NEW, ) self.assertEqual(len(emails), 1) self.assertEqual(emails[0], user.email)
def test_region_and_country_subscription(self): user = get_user() r = Region.objects.get(name='1') c = Country.objects.get(name='2') Subscription.objects.create( user=user, region=r, lookup_id='r%s' % r.id ) Subscription.objects.create( user=user, country=c, lookup_id='c%s' % c.id ) notify = Notify() emails = notify.gather_subscribers( Appeal.objects.filter(created_at__gte=notify.diff_5_minutes()), RecordType.APPEAL, SubscriptionType.NEW, ) self.assertEqual(len(emails), 1) self.assertEqual(emails[0], user.email)
def test_multiple_subscription(self): user1 = get_user() user2 = get_user() d = DisasterType.objects.get(name='d1') r = Region.objects.get(name=1) # User 1: Disaster type subscription Subscription.objects.create( user=user1, dtype=d, lookup_id='d%s' % d.id, ) # User 1: Region subscription Subscription.objects.create( user=user1, region=r, lookup_id='r%s' % r.id, ) # User 2: NEW_EMERGENCIES subscription (instead of the original New field report subscription) Subscription.objects.create( user=user2, rtype=RecordType.NEW_EMERGENCIES, #FIELD_REPORT, stype=SubscriptionType.NEW, ) notify = Notify() emails = notify.gather_subscribers( FieldReport.objects.filter( created_at__gte=notify.get_time_threshold()), RecordType.FIELD_REPORT, SubscriptionType.NEW, ) self.assertEqual(len(emails), 2) self.assertEqual(emails.sort(), [user1.email, user2.email].sort())