def test_deactivate(self):
     self.note.activate()
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
     self.note.deactivate()
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 0)
 def test_activate(self):
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 0)
     self.note.activate()
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
     self.assertEqual(notes[0]['isRead'], False)
 def test_activate(self):
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 0)
     self.note.activate()
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
     self.assertEqual(notes[0]['isRead'], False)
 def test_deactivate(self):
     self.note.activate()
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
     self.note.deactivate()
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 0)
 def test_mark_as_read(self):
     self.note.activate()
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
     self.assertEqual(notes[0]['isRead'], False)
     self.note.mark_as_read(self.user)
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
     self.assertEqual(notes[0]['isRead'], True)
 def test_mark_as_read(self):
     self.note.activate()
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
     self.assertEqual(notes[0]['isRead'], False)
     self.note.mark_as_read(self.user)
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
     self.assertEqual(notes[0]['isRead'], True)
Beispiel #7
0
 def get_notifications(self, in_data):
     # todo always grab alerts if they are still relevant
     notifications = Notification.get_by_user(self.request.user)
     has_unread = len(filter(lambda x: not x['isRead'], notifications)) > 0
     return {
         'hasUnread': has_unread,
         'notifications': notifications,
     }
 def test_notification_created_before_user(self):
     self.note.activate()
     date_joined = self.user.date_joined
     notification_activated = date_joined - timedelta(days=1)
     Notification.objects.create(
         content="old notification", url="http://dimagi.com", type="info",
         activated=notification_activated, is_active=True
     )
     notes = Notification.get_by_user(self.user, self.couch_user)
     self.assertEqual(len(notes), 1)
Beispiel #9
0
 def get_notifications(self, in_data):
     # todo always grab alerts if they are still relevant
     notifications = Notification.get_by_user(self.request.user, self.request.couch_user)
     has_unread = len(filter(lambda x: not x["isRead"], notifications)) > 0
     last_seen_notification_date = LastSeenNotification.get_last_seen_notification_date_for_user(self.request.user)
     return {
         "hasUnread": has_unread,
         "notifications": notifications,
         "lastSeenNotificationDate": last_seen_notification_date,
     }
Beispiel #10
0
 def get_notifications(self, in_data):
     # todo always grab alerts if they are still relevant
     notifications = Notification.get_by_user(self.request.user)
     has_unread = len(filter(lambda x: not x['isRead'], notifications)) > 0
     last_seen_notification_date = LastSeenNotification.get_last_seen_notification_date_for_user(
         self.request.user)
     return {
         'hasUnread': has_unread,
         'notifications': notifications,
         'lastSeenNotificationDate': last_seen_notification_date
     }
Beispiel #11
0
 def get_notifications(self, in_data):
     # todo always grab alerts if they are still relevant
     notifications = Notification.get_by_user(self.request.user, self.request.couch_user)
     has_unread = len([x for x in notifications if not x['isRead']]) > 0
     last_seen_notification_date = LastSeenNotification.get_last_seen_notification_date_for_user(
         self.request.user
     )
     return {
         'hasUnread': has_unread,
         'notifications': notifications,
         'lastSeenNotificationDate': last_seen_notification_date
     }
    def test_domain_specific_notification(self):
        self.note.activate()
        notes = Notification.get_by_user(self.user, self.couch_user)
        self.assertEqual(len(notes), 1)

        # notification is for a domain the user is not a member of
        note1 = Notification.objects.create(
            content="dom notification", url="http://dimagi.com", type="info",
            domain_specific=True, domains=['dom']
        )
        note1.activate()
        notes = Notification.get_by_user(self.user, self.couch_user)
        self.assertEqual(len(notes), 1)

        #notification is for the users domain
        note2 = Notification.objects.create(
            content="test dom notification", url="http://dimagi.com", type="info",
            domain_specific=True, domains=['test-dom']
        )
        note2.activate()
        notes = Notification.get_by_user(self.user, self.couch_user)
        self.assertEqual(len(notes), 2)
Beispiel #13
0
    def get_notifications(self, in_data):
        # todo always grab alerts if they are still relevant
        subscribed_plan = Subscription.get_subscribed_plan_by_domain(
            self.get_domain())
        pro_tier_editions = [
            SoftwarePlanEdition.PRO, SoftwarePlanEdition.ADVANCED,
            SoftwarePlanEdition.ENTERPRISE
        ]
        if subscribed_plan.plan.edition in pro_tier_editions:
            plan_tier = 'pro'
        else:
            plan_tier = 'basic'

        def should_hide_feature_notifs(domain, plan):
            groups = Group.get_case_sharing_groups(domain, wrap=False)
            subscription_type = Subscription.get_active_subscription_by_domain(
                domain).service_type
            if plan == 'pro' and groups != []:
                return True
            if subscription_type == 'IMPLEMENTATION' or subscription_type == 'SANDBOX':
                return True
            return False

        notifications = Notification.get_by_user(
            self.request.user,
            self.request.couch_user,
            plan_tier=plan_tier,
            hide_features=should_hide_feature_notifs(self.get_domain(),
                                                     plan_tier))
        has_unread = len([x for x in notifications if not x['isRead']]) > 0
        last_seen_notification_date = LastSeenNotification.get_last_seen_notification_date_for_user(
            self.request.user)
        return {
            'hasUnread': has_unread,
            'notifications': notifications,
            'lastSeenNotificationDate': last_seen_notification_date
        }