def test_non_coach_member(self, m_umog):
        m_umog.return_value = True
        groupInfo = MagicMock()
        groupInfo.get_property.return_value = 'other'
        userInfo = MagicMock()
        userInfo.id = 'example'
        r = user_participation_coach_of_group(userInfo, groupInfo)

        self.assertFalse(r)
    def user_posting_limit_hit(self):
        '''The posting limits are based on the *rate* of posting to the
        group. The maximum allowed rate of posting is defined by the
        "senderlimit" and "senderinterval" properties of the mailing list
        for the group. If the user has exceeded his or her posting limits
        if  more than "senderlimit" posts have been sent in
        "senderinterval" seconds to the group.
        '''
        if user_participation_coach_of_group(self.userInfo, self.groupInfo):
            retval = False
            self.__status = u'participation coach'
            self.__statusNum = self.__statusNum + 0
        elif user_admin_of_group(self.userInfo, self.groupInfo):
            retval = False
            self.__status = u'administrator of'
            self.__statusNum = self.__statusNum + 0
        else:
            # The user is not the participation coach or the administrator
            # of the group
            sid = self.groupInfo.siteInfo.id
            gid = self.groupInfo.id
            uid = self.userInfo.id
            limit = self.mailingList.getValueFor('senderlimit')
            interval = self.mailingList.getValueFor('senderinterval')
            td = timedelta(seconds=interval)
            now = datetime.now(pytz.utc)
            earlyDate = now - td
            count = self.messageQuery.num_posts_after_date(
                sid, gid, uid, earlyDate)
            if count >= limit:
                # The user has made over the allowed number of posts in
                # the interval
                retval = True
                d = self.old_message_post_date()

                canPostDate = d + td
                prettyDate = munge_date(self.groupInfo.groupObj,
                                        canPostDate,
                                        user=self.userInfo.user)
                prettyDelta = timedelta_to_string(canPostDate - now)
                self.__status = u'post again at %s\n-- in %s' %\
                  (prettyDate, prettyDelta)
                self.__statusNum = 32
            else:
                retval = False
                self.__status = u'under the posting limit'
                self.__statusNum = self.__statusNum + 0
        assert type(self.__status) == unicode
        assert type(retval) == bool
        return retval
    def user_posting_limit_hit(self):
        '''The posting limits are based on the *rate* of posting to the
        group. The maximum allowed rate of posting is defined by the
        "senderlimit" and "senderinterval" properties of the mailing list
        for the group. If the user has exceeded his or her posting limits
        if  more than "senderlimit" posts have been sent in
        "senderinterval" seconds to the group.
        '''
        if user_participation_coach_of_group(self.userInfo, self.groupInfo):
            retval = False
            self.__status = u'participation coach'
            self.__statusNum = self.__statusNum + 0
        elif user_admin_of_group(self.userInfo, self.groupInfo):
            retval = False
            self.__status = u'administrator of'
            self.__statusNum = self.__statusNum + 0
        else:
            # The user is not the participation coach or the administrator
            # of the group
            sid = self.groupInfo.siteInfo.id
            gid = self.groupInfo.id
            uid = self.userInfo.id
            limit = self.mailingList.getValueFor('senderlimit')
            interval = self.mailingList.getValueFor('senderinterval')
            td = timedelta(seconds=interval)
            now = datetime.now(pytz.utc)
            earlyDate = now - td
            count = self.messageQuery.num_posts_after_date(sid, gid, uid,
                                                           earlyDate)
            if count >= limit:
                # The user has made over the allowed number of posts in
                # the interval
                retval = True
                d = self.old_message_post_date()

                canPostDate = d + td
                prettyDate = munge_date(self.groupInfo.groupObj,
                    canPostDate, user=self.userInfo.user)
                prettyDelta = timedelta_to_string(canPostDate - now)
                self.__status = u'post again at %s\n-- in %s' %\
                  (prettyDate, prettyDelta)
                self.__statusNum = 32
            else:
                retval = False
                self.__status = u'under the posting limit'
                self.__statusNum = self.__statusNum + 0
        assert type(self.__status) == unicode
        assert type(retval) == bool
        return retval
Beispiel #4
0
    def check(self):
        if not self.s['checked']:
            if user_participation_coach_of_group(self.userInfo,
                                                 self.groupInfo):
                self.s['canPost'] = True
                self.s['status'] = u'a participation coach.'
                self.s['statusNum'] = 0
            elif user_admin_of_group(self.userInfo, self.groupInfo):
                self.s['canPost'] = True
                self.s['status'] = u'a group administrator.'
                self.s['statusNum'] = 0
            else:
                interval = self.mailingList.getValueFor('senderinterval')
                n = now()
                td = timedelta(seconds=interval)
                count = self.messageQuery.num_posts_after_date(
                    self.siteInfo.id, self.groupInfo.id, self.userInfo.id,
                    n - td)
                if (count >= self.mailingList.getValueFor('senderlimit')):
                    self.s['canPost'] = False
                    canPostDate = self.oldMessagePostDate + td
                    prettyDate = munge_date(self.group,
                                            canPostDate,
                                            user=self.userInfo.user)
                    prettyDelta = timedelta_to_string(canPostDate - n)
                    self.s['status'] = u'exceeded the posting rate. '\
                        u'You can post again at %s (in %s).' % \
                        (prettyDate, prettyDelta)
                    self.s['statusNum'] = self.weight
                else:
                    self.s['canPost'] = True
                    self.s['status'] = u'under the posting limit.'
                    self.s['statusNum'] = 0
            self.s['checked'] = True

        assert self.s['checked']
        assert type(self.s['canPost']) == bool
        assert type(self.s['status']) == unicode
        assert type(self.s['statusNum']) == int
    def check(self):
        if not self.s['checked']:
            if user_participation_coach_of_group(self.userInfo, self.groupInfo):
                self.s['canPost'] = True
                self.s['status'] = u'a participation coach.'
                self.s['statusNum'] = 0
            elif user_admin_of_group(self.userInfo, self.groupInfo):
                self.s['canPost'] = True
                self.s['status'] = u'a group administrator.'
                self.s['statusNum'] = 0
            else:
                interval = self.mailingList.getValueFor('senderinterval')
                n = now()
                td = timedelta(seconds=interval)
                count = self.messageQuery.num_posts_after_date(
                                    self.siteInfo.id, self.groupInfo.id, 
                                    self.userInfo.id, n - td)
                if (count >= self.mailingList.getValueFor('senderlimit')):
                    self.s['canPost'] = False
                    canPostDate = self.oldMessagePostDate + td
                    prettyDate = munge_date(self.group, canPostDate, 
                                            user=self.userInfo.user)
                    prettyDelta = timedelta_to_string(canPostDate - n)
                    self.s['status'] = u'exceeded the posting rate. '\
                        u'You can post again at %s (in %s).' % \
                        (prettyDate, prettyDelta)
                    self.s['statusNum'] = self.weight
                else:
                    self.s['canPost'] = True
                    self.s['status'] = u'under the posting limit.'
                    self.s['statusNum'] = 0
            self.s['checked'] = True

        assert self.s['checked']                
        assert type(self.s['canPost']) == bool
        assert type(self.s['status']) == unicode
        assert type(self.s['statusNum']) == int