Beispiel #1
0
 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)
Beispiel #2
0
 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.diff_5_minutes()),
         RecordType.APPEAL,
         SubscriptionType.NEW,
     )
     self.assertEqual(len(emails), 1)
     self.assertEqual(emails[0], user.email)
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
 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)
Beispiel #6
0
    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.diff_5_minutes()),
            RecordType.FIELD_REPORT,
            SubscriptionType.NEW,
        )
        self.assertEqual(len(emails), 2)
        self.assertEqual(emails.sort(), [user1.email, user2.email].sort())
Beispiel #7
0
 def test_filter_just_created(self):
     notify = Notify()
     filtered = notify.filter_just_created(Appeal.objects.filter(created_at__gte=notify.diff_5_minutes()))
     self.assertEqual(len(filtered), 1)
     self.assertEqual(filtered[0].aid, 'test2')