示例#1
0
 def test_comment(self):
     response = self.app.get(url(controller='package', action='comment',
                                 packagename='testpackage'))
     self.assertEquals(response.status_int, 302)
     self.assertTrue(response.location.endswith(
             url(controller='package', action='index',
                 packagename='testpackage')))
     self.app.post(url('login'), self._AUTHDATA)
     response = self.app.get(url(controller='package', action='comment',
                                 packagename='testpackage'))
     self.assertTrue(response.location.endswith(
             url(controller='package', action='index',
                 packagename='testpackage')))
     self.assertEquals(response.status_int, 302)
     response = self.app.post(
         url(controller='package', action='comment',
             packagename='testpackage'),
         {'package_version': 1,
          'text': 'This is a test comment',
          'outcome': constants.PACKAGE_COMMENT_OUTCOME_UNREVIEWED,
          'commit': 'submit'})
     self.assertEquals(response.status_int, 302)
     self.assertTrue(response.location.endswith(
             url(controller='package', action='index',
                 packagename='testpackage')))
     comment = meta.session.query(PackageComment).filter_by(
         package_version_id=1).one()
     self.assertEquals(comment.text, 'This is a test comment')
     self.assertEquals(comment.status,
                       constants.PACKAGE_COMMENT_STATUS_NOT_UPLOADED)
     meta.session.delete(comment)
     # test with a subscriber
     user = meta.session.query(User).filter(User.email=='*****@*****.**').one()
     packsub = PackageSubscription(
         package='testpackage',
         level=constants.SUBSCRIPTION_LEVEL_COMMENTS)
     packsub.user = user
     meta.session.add(packsub)
     meta.session.commit()
     response = self.app.post(
         url(controller='package', action='comment',
             packagename='testpackage'),
         {'package_version': 1,
          'text': 'This is a test comment',
          'outcome': constants.PACKAGE_COMMENT_OUTCOME_UNREVIEWED,
          'commit': 'submit',
          'status': 'checked'})
     self.assertEquals(response.status_int, 302)
     self.assertTrue(response.location.endswith(
             url(controller='package', action='index',
                 packagename='testpackage')))
     comment = meta.session.query(PackageComment).filter_by(
         package_version_id=1).one()
     self.assertEquals(comment.text, 'This is a test comment')
     self.assertEquals(comment.status,
                       constants.PACKAGE_COMMENT_STATUS_UPLOADED)
     meta.session.delete(packsub)
     meta.session.commit()
示例#2
0
 def test_comment(self):
     response = self.app.get(url(controller="package", action="comment", packagename="testpackage"))
     self.assertEquals(response.status_int, 302)
     self.assertTrue(
         response.location.endswith(url(controller="package", action="index", packagename="testpackage"))
     )
     self.app.post(url("login"), self._AUTHDATA)
     response = self.app.get(url(controller="package", action="comment", packagename="testpackage"))
     self.assertTrue(
         response.location.endswith(url(controller="package", action="index", packagename="testpackage"))
     )
     self.assertEquals(response.status_int, 302)
     response = self.app.post(
         url(controller="package", action="comment", packagename="testpackage"),
         {
             "package_version": 1,
             "text": "This is a test comment",
             "outcome": constants.PACKAGE_COMMENT_OUTCOME_UNREVIEWED,
             "commit": "submit",
         },
     )
     self.assertEquals(response.status_int, 302)
     self.assertTrue(
         response.location.endswith(url(controller="package", action="index", packagename="testpackage"))
     )
     comment = meta.session.query(PackageComment).filter_by(package_version_id=1).one()
     self.assertEquals(comment.text, "This is a test comment")
     self.assertEquals(comment.status, constants.PACKAGE_COMMENT_STATUS_NOT_UPLOADED)
     meta.session.delete(comment)
     # test with a subscriber
     user = meta.session.query(User).filter(User.email == "*****@*****.**").one()
     packsub = PackageSubscription(package="testpackage", level=constants.SUBSCRIPTION_LEVEL_COMMENTS)
     packsub.user = user
     meta.session.add(packsub)
     meta.session.commit()
     response = self.app.post(
         url(controller="package", action="comment", packagename="testpackage"),
         {
             "package_version": 1,
             "text": "This is a test comment",
             "outcome": constants.PACKAGE_COMMENT_OUTCOME_UNREVIEWED,
             "commit": "submit",
             "status": "checked",
         },
     )
     self.assertEquals(response.status_int, 302)
     self.assertTrue(
         response.location.endswith(url(controller="package", action="index", packagename="testpackage"))
     )
     comment = meta.session.query(PackageComment).filter_by(package_version_id=1).one()
     self.assertEquals(comment.text, "This is a test comment")
     self.assertEquals(comment.status, constants.PACKAGE_COMMENT_STATUS_UPLOADED)
     meta.session.delete(packsub)
     meta.session.commit()
示例#3
0
    def subscribe(self, packagename):
        """
        Package subscription.

        ``packagename``
            Package name to look at.
        """
        if 'user_id' not in session:
            log.debug('Requires authentication')
            session['path_before_login'] = request.path_info
            session.save()
            redirect(url('login'))

        package = self._get_package(packagename)

        query = meta.session.query(PackageSubscription).filter_by(
            package=packagename).filter_by(user_id=session['user_id'])
        subscription = query.first()

        validation = False
        if request.method == 'POST':
            # The form has been submitted.
            try:
                fields = form.validate(PackageSubscribeForm,
                                       user_id=session['user_id'])
            except Exception, e:
                log.error('Failed validation')
                validation = e
            if not validation:
                if subscription is None:
                    # There is no previous subscription.
                    if fields['level'] != -1:
                        log.debug('Creating new subscription on %s' %
                                  packagename)
                        subscription = PackageSubscription(
                            package=packagename,
                            user_id=session['user_id'],
                            level=fields['level'])
                        meta.session.add(subscription)
                else:
                    # There is a previous subscription.
                    if fields['level'] != -1:
                        log.debug('Changing previous subscription on %s' %
                                  packagename)
                        subscription.level = fields['level']
                    else:
                        log.debug('Deleting previous subscription on %s' %
                                  packagename)
                        meta.session.delete(subscription)
                meta.session.commit()
                redirect(url('package', packagename=packagename))
示例#4
0
文件: package.py 项目: kenhys/debexpo
    def subscribe(self, packagename):
        """
        Package subscription.

        ``packagename``
            Package name to look at.
        """
        if 'user_id' not in session:
            log.debug('Requires authentication')
            session['path_before_login'] = request.path_info
            session.save()
            redirect(url('login'))

        package = self._get_package(packagename)

        query = meta.session.query(PackageSubscription).filter_by(
            package=packagename).filter_by(user_id=session['user_id'])
        subscription = query.first()

        validation = False
        if request.method == 'POST':
            # The form has been submitted.
            try:
                fields = form.validate(PackageSubscribeForm,
                                       user_id=session['user_id'])
            except Exception, e:
                log.error('Failed validation')
                validation = e
            if not validation:
                if subscription is None:
                    # There is no previous subscription.
                    if fields['level'] != -1:
                        log.debug('Creating new subscription on %s' % packagename)
                        subscription = PackageSubscription(
                            package=packagename,
                            user_id=session['user_id'],
                            level=fields['level'])
                        meta.session.add(subscription)
                else:
                    # There is a previous subscription.
                    if fields['level'] != -1:
                        log.debug('Changing previous subscription on %s' % packagename)
                        subscription.level = fields['level']
                    else:
                        log.debug('Deleting previous subscription on %s' % packagename)
                        meta.session.delete(subscription)
                meta.session.commit()
                redirect(url('package', packagename=packagename))
示例#5
0
文件: package.py 项目: swvist/Debexpo
    def subscribe(self, packagename):
        """
        Package subscription.

        ``packagename``
            Package name to look at.
        """
        if "user_id" not in session:
            log.debug("Requires authentication")
            session["path_before_login"] = request.path_info
            session.save()
            redirect(url("login"))

        package = self._get_package(packagename)

        query = (
            meta.session.query(PackageSubscription).filter_by(package=packagename).filter_by(user_id=session["user_id"])
        )
        subscription = query.first()

        validation = False
        if request.method == "POST":
            # The form has been submitted.
            try:
                fields = form.validate(PackageSubscribeForm, user_id=session["user_id"])
            except Exception, e:
                log.error("Failed validation")
                validation = e
            if not validation:
                if subscription is None:
                    # There is no previous subscription.
                    if fields["level"] != -1:
                        log.debug("Creating new subscription on %s" % packagename)
                        subscription = PackageSubscription(
                            package=packagename, user_id=session["user_id"], level=fields["level"]
                        )
                        meta.session.add(subscription)
                else:
                    # There is a previous subscription.
                    if fields["level"] != -1:
                        log.debug("Changing previous subscription on %s" % packagename)
                        subscription.level = fields["level"]
                    else:
                        log.debug("Deleting previous subscription on %s" % packagename)
                        meta.session.delete(subscription)
                meta.session.commit()
                redirect(url("package", packagename=packagename))
示例#6
0
 def test_comment(self):
     response = self.app.get(
         url(controller='package',
             action='comment',
             packagename='testpackage'))
     self.assertEquals(response.status_int, 302)
     self.assertTrue(
         response.location.endswith(
             url(controller='package',
                 action='index',
                 packagename='testpackage')))
     self.app.post(url('login'), self._AUTHDATA)
     response = self.app.get(
         url(controller='package',
             action='comment',
             packagename='testpackage'))
     self.assertTrue(
         response.location.endswith(
             url(controller='package',
                 action='index',
                 packagename='testpackage')))
     self.assertEquals(response.status_int, 302)
     response = self.app.post(
         url(controller='package',
             action='comment',
             packagename='testpackage'), {
                 'package_version': 1,
                 'text': 'This is a test comment',
                 'outcome': constants.PACKAGE_COMMENT_OUTCOME_UNREVIEWED,
                 'commit': 'submit'
             })
     self.assertEquals(response.status_int, 302)
     self.assertTrue(
         response.location.endswith(
             url(controller='package',
                 action='index',
                 packagename='testpackage')))
     comment = meta.session.query(PackageComment).filter_by(
         package_version_id=1).one()
     self.assertEquals(comment.text, 'This is a test comment')
     self.assertEquals(comment.status,
                       constants.PACKAGE_COMMENT_STATUS_NOT_UPLOADED)
     meta.session.delete(comment)
     # test with a subscriber
     user = meta.session.query(User).filter(
         User.email == '*****@*****.**').one()
     packsub = PackageSubscription(
         package='testpackage', level=constants.SUBSCRIPTION_LEVEL_COMMENTS)
     packsub.user = user
     meta.session.add(packsub)
     meta.session.commit()
     response = self.app.post(
         url(controller='package',
             action='comment',
             packagename='testpackage'), {
                 'package_version': 1,
                 'text': 'This is a test comment',
                 'outcome': constants.PACKAGE_COMMENT_OUTCOME_UNREVIEWED,
                 'commit': 'submit',
                 'status': 'checked'
             })
     self.assertEquals(response.status_int, 302)
     self.assertTrue(
         response.location.endswith(
             url(controller='package',
                 action='index',
                 packagename='testpackage')))
     comment = meta.session.query(PackageComment).filter_by(
         package_version_id=1).one()
     self.assertEquals(comment.text, 'This is a test comment')
     self.assertEquals(comment.status,
                       constants.PACKAGE_COMMENT_STATUS_UPLOADED)
     meta.session.delete(packsub)
     meta.session.commit()
示例#7
0
    def subscribe(self, packagename):
        """
        Package subscripton.

        ``packagename``
            Package name to look at.
        """
        if 'user_id' not in session:
            log.debug('Requires authentication')
            session['path_before_login'] = request.path_info
            session.save()
            return redirect_to(h.url_for(controller='login'))

        package = self._get_package(packagename)
        if not isinstance(package, Package):
            return package

        query = meta.session.query(PackageSubscription).filter_by(
            package=packagename).filter_by(user_id=session['user_id'])
        subscription = query.first()

        if request.method == 'POST':
            # The form has been submitted.
            if subscription is None:
                # There is no previous subscription.
                if request.POST['level'] != -1:
                    log.debug('Creating new subscription on %s' % packagename)
                    subscribe = PackageSubscription(
                        package=packagename,
                        user_id=session['user_id'],
                        level=request.POST['level'])
                    meta.session.save(subscribe)

            else:
                # There is a previous subscription.
                if request.POST['level'] != -1:
                    log.debug('Changing previous subscription on %s' %
                              packagename)
                    subscription.level = request.POST['level']
                else:
                    log.debug('Deleting previous subscription on %s' %
                              packagename)
                    meta.session.delete(subscription)

            meta.session.commit()
            return redirect_to(h.url_for('package', packagename=packagename))

        c.subscriptions = {
            _('No subscription'):
            -1,
            _('Package upload notifications only'):
            constants.SUBSCRIPTION_LEVEL_UPLOADS,
            _('Package upload and comment notifications'):
            constants.SUBSCRIPTION_LEVEL_COMMENTS
        }

        if subscription is None:
            c.current_subscription = -1
        else:
            c.current_subscription = subscription.level

        log.debug('Rendering page')
        return render('/package/subscribe.mako')