コード例 #1
0
ファイル: tests.py プロジェクト: alanjds/arecibo
    def testBasic(self):
        c = Client()
        assert not Error.all().count()
        c.post(reverse("error-post"), test_data)
        assert test_data["priority"] < 5, test_data["priority"]
        assert Error.all().count() == 1
        assert Notification.all().count() == 1

        c.post(reverse("error-post"), test_data)
        assert test_data["priority"] < 5, test_data["priority"]
        assert Error.all().count() == 2
        assert Notification.all().count() == 2
コード例 #2
0
ファイル: views.py プロジェクト: andymckay/arecibo
def notifications_send(request):
    log("Firing cron: notifications_send")
    notifications = Notification.all().filter("type = ", "Error").filter("tried = ", False)

    # batch up the notifications for the user
    holders = {}
    for notif in notifications:
        for user in notif.user_list():
            key = str(user.key())
            if key not in holders:
                holder = Holder()
                holder.user = user
                holders[key] = holder

            holders[key].objs.append(notif.notifier())
            holders[key].notifs.append(notif)

    for user_id, holder in holders.items():
        try:
            send_error_email(holder)
            for notification in holder.notifs:
                notification.tried = True
                notification.completed = True
                notification.save()
        except:
            info = sys.exc_info()
            data = "%s, %s" % (info[0], info[1])
            for notification in holder.notifs:
                notification.tried = True
                notification.completed = True
                notification.error_msg = data
                notification.save()
            
    return render_plain("Cron job completed")
コード例 #3
0
ファイル: tests.py プロジェクト: slok/dwarf
    def test_achievement_notification_get_all_asc(self):
        #with three we have enought to test
        achieves = Achievement.objects.all()
        user = User.objects.get(id=1)
        r = get_redis_connection()

        a_len = len(achieves)

        for i in achieves:
            notif = AchievementNotification(achievement=i, user=user)
            time.sleep(1)

            if random.randrange(100) % 2:
                key = Notification.STORE_KEY_UNREAD_FORMAT.format(user.id)
            else:
                key = Notification.STORE_KEY_READ_FORMAT.format(user.id)

            r.zadd(key, notif.date, notif.to_json())

        # Get notifications
        res = Notification.all(user, desc=False)

        self.assertEquals(a_len, len(res))

        for i in range(len(res)):
            before = achieves[i]
            after = res[i]

            self.assertEquals(before.id, after.achievement_id)
コード例 #4
0
def notifications_send(request):
    log("Firing cron: notifications_send")
    notifications = Notification.all().filter("tried = ", False)

    # batch up the notifications for the user
    holders = {}
    for notif in notifications:
        for user in notif.user_list():
            key = str(user.key())
            if key not in holders:
                holder = Holder()
                holder.user = user
                holders[key] = holder

            holders[key].objs.append(notif.error)
            holders[key].notifs.append(notif)

    for user_id, holder in holders.items():
        try:
            send_error_email(holder)
            for notification in holder.notifs:
                notification.tried = True
                notification.completed = True
                notification.save()
        except:
            info = sys.exc_info()
            data = "%s, %s" % (info[0], info[1])
            for notification in holder.notifs:
                notification.tried = True
                notification.completed = True
                notification.error_msg = data
                notification.save()

    return render_plain("Cron job completed")
コード例 #5
0
ファイル: views.py プロジェクト: andymckay/arecibo
def notifications_cleanup(request):
    log("Firing cron: notifications_cleanup")
    expired = datetime.today() - timedelta(days=7)
    queryset = Notification.all().filter("tried = ", True).filter("timestamp < ", expired)
    for notification in queryset:
        notification.delete()

    return render_plain("Cron job completed")
コード例 #6
0
def notifications_cleanup(request):
    log("Firing cron: notifications_cleanup")
    expired = datetime.today() - timedelta(days=7)
    queryset = Notification.all().filter("tried = ",
                                         True).filter("timestamp < ", expired)
    for notification in queryset:
        notification.delete()

    return render_plain("Cron job completed")
コード例 #7
0
ファイル: tests.py プロジェクト: andymckay/arecibo
 def testNoNotification(self):
     c = Client()
     assert not Error.all().count()
     data = test_data.copy()
     data["priority"] = 6
     c.post(reverse("error-post"), data)
     assert data["priority"] > 5, data["priority"]
     assert Error.all().count() == 1
     assert Notification.all().count() == 0
コード例 #8
0
ファイル: tests.py プロジェクト: pajenterprise/arecibo
 def testNoNotification(self):
     c = Client()
     assert not Error.all().count()
     data = test_data.copy()
     data["priority"] = 6
     c.post(reverse("error-post"), data)
     assert data["priority"] > 5, data["priority"]
     assert Error.all().count() == 1
     assert Notification.all().count() == 0
コード例 #9
0
ファイル: tests.py プロジェクト: pajenterprise/arecibo
 def setUp(self):
     for error in Error.all():
         error.delete()
     for notification in Notification.all():
         notification.delete()
     for user in AppUser.all():
         user.delete()
     for issue in Issue.all():
         issue.delete()
コード例 #10
0
ファイル: views.py プロジェクト: andymckay/arecibo
def notifications_list(request):
    queryset = Notification.all().order("-timestamp")
    # this number doesn't need to be high and its quite an expensive
    # page to generate
    paginated = Paginator(queryset, 10)
    page = get_page(request, paginated)
    return direct_to_template(request, "notification_list.html", extra_context={
        "page": page,
        "nav": {"selected": "notifications"}
        })
コード例 #11
0
ファイル: tests.py プロジェクト: andymckay/arecibo
    def testProfile(self):
        user = create_user()        
        
        c = Client()
        data = test_data.copy()
        data["priority"] = 6
        c.post(reverse("error-post"), data)
        
        assert Notification.all().count() == 0, Notification.all().count()
    
        data["priority"] = 5
        c.post(reverse("error-post"), data)
        
        assert Notification.all().count() == 1
        
        profile = get_profile(user)
        profile.notification = 8

        data["priority"] = 5
        c.post(reverse("error-post"), data)
        
        assert Notification.all().count() == 2
        
        data["priority"] = 8
        c.post(reverse("error-post"), data)
        
        assert Notification.all().count() == 2

        data["priority"] = 9
        c.post(reverse("error-post"), data)
        
        assert Notification.all().count() == 2
コード例 #12
0
ファイル: tests.py プロジェクト: pajenterprise/arecibo
    def testProfile(self):
        user = create_user()

        c = Client()
        data = test_data.copy()
        data["priority"] = 6
        c.post(reverse("error-post"), data)

        assert Notification.all().count() == 0, Notification.all().count()

        data["priority"] = 5
        c.post(reverse("error-post"), data)

        assert Notification.all().count() == 1

        profile = get_profile(user)
        profile.notification = 8

        data["priority"] = 5
        c.post(reverse("error-post"), data)

        assert Notification.all().count() == 2

        data["priority"] = 8
        c.post(reverse("error-post"), data)

        assert Notification.all().count() == 2

        data["priority"] = 9
        c.post(reverse("error-post"), data)

        assert Notification.all().count() == 2
コード例 #13
0
def notifications_list(request):
    queryset = Notification.all().order("-timestamp")
    # this number doesn't need to be high and its quite an expensive
    # page to generate
    paginated = Paginator(queryset, 10)
    page = get_page(request, paginated)
    return direct_to_template(request,
                              "notification_list.html",
                              extra_context={
                                  "page": page,
                                  "nav": {
                                      "selected": "notifications"
                                  }
                              })
コード例 #14
0
ファイル: tests.py プロジェクト: andymckay/arecibo
    def testIssueAndErrorNotification(self):
        user = create_user()
        
        issue = Issue()
        issue.description = "This is a test"
        issue.save()
        
        assert Issue.all().count() == 1

        c = Client()
        c.post(reverse("error-post"), test_data)

        #assert Notification.all().count() == 2
        # this would be 2 when issues are turned on
        assert Notification.all().count() == 1
        
        c = Client()
        res = c.get(reverse("notification-send"))        
        self.assertEquals(len(mail.outbox), 1)
コード例 #15
0
ファイル: tests.py プロジェクト: pajenterprise/arecibo
    def testIssueAndErrorNotification(self):
        user = create_user()

        issue = Issue()
        issue.description = "This is a test"
        issue.save()

        assert Issue.all().count() == 1

        c = Client()
        c.post(reverse("error-post"), test_data)

        #assert Notification.all().count() == 2
        # this would be 2 when issues are turned on
        assert Notification.all().count() == 1

        c = Client()
        res = c.get(reverse("notification-send"))
        self.assertEquals(len(mail.outbox), 1)
コード例 #16
0
ファイル: tests.py プロジェクト: andymckay/arecibo
 def testNotificationNoUsers(self):
     c = Client()
     c.post(reverse("error-post"), test_data)
     assert Notification.all().count() == 0
コード例 #17
0
ファイル: tests.py プロジェクト: andymckay/arecibo
 def setUp(self):
     for error in Error.all(): error.delete()
     for notification in Notification.all(): notification.delete()
     for user in AppUser.all(): user.delete()
     for issue in Issue.all(): issue.delete()
コード例 #18
0
ファイル: tests.py プロジェクト: alanjds/arecibo
 def setUp(self):
     for error in Error.all(): error.delete()
     for notification in Notification.all(): notification.delete()
コード例 #19
0
ファイル: tests.py プロジェクト: pajenterprise/arecibo
 def testNotificationNoUsers(self):
     c = Client()
     c.post(reverse("error-post"), test_data)
     assert Notification.all().count() == 0