Example #1
0
    def _save_edit(self, id, context):
        try:
            data_dict = clean_dict(unflatten(
                tuplize_dict(parse_params(request.POST))))
            self._check_data_dict(data_dict)
            context['message'] = data_dict.get('log_message', '')
            if not context['moderated']:
                context['pending'] = False
            data_dict['id'] = id
            pkg = get_action('package_update')(context, data_dict)
            if request.params.get('save', '') == 'Approve':
                update.make_latest_pending_package_active(context, data_dict)
            c.pkg = context['package']
            c.pkg_dict = pkg

            if context['preview']:
                c.is_preview = True
                PackageSaver().render_package(pkg, context)
                c.preview = render('package/read_core.html')
                return self.edit(id, data_dict)

            self._form_save_redirect(pkg['name'], 'edit')
        except NotAuthorized:
            abort(401, _('Unauthorized to read package %s') % id)
        except NotFound, e:
            abort(404, _('Package not found'))
Example #2
0
    def test_12_make_active(self):

        model.repo.new_revision()
        anna1 = model.Session.query(model.Package).filter_by(name="annakarenina_changed2").one()
        context = {"model": model, "session": model.Session, "user": "******"}

        make_latest_pending_package_active(context, {"id": anna1.id})

        pkgrevisions = model.Session.query(model.PackageRevision).filter_by(id=anna1.id).all()
        sorted_packages = sorted(pkgrevisions, key=lambda x: x.revision_timestamp)[::-1]

        assert len(sorted_packages) == 4
        assert sorted_packages[0].state == "active", sorted_packages[0].state  # was pending
        assert sorted_packages[0].current == True

        assert sorted_packages[1].state == "pending"
        assert sorted_packages[2].state == "active"
        assert sorted_packages[3].state == "active"

        resources_revisions = (
            model.Session.query(model.ResourceRevision)
            .filter_by(resource_group_id=anna1.resource_groups_all[0].id)
            .all()
        )
        sorted_resources = sorted(resources_revisions, key=lambda x: (x.revision_timestamp, x.url))[::-1]

        assert len(sorted_resources) == 5
        for res in sorted_resources:
            print res.id, res.revision_timestamp, res.expired_timestamp, res.state
        assert sorted_resources[0].state == "active"
        assert sorted_resources[0].current == True
        assert sorted_resources[1].state == "active"
        assert sorted_resources[1].current == True
        assert sorted_resources[2].state == "active"
        assert sorted_resources[3].state == "active"
        assert sorted_resources[3].current == True
        assert sorted_resources[4].state == "active"

        assert str(sorted_resources[0].expired_timestamp) == "9999-12-31 00:00:00"
        assert str(sorted_resources[1].expired_timestamp) == "9999-12-31 00:00:00"
        assert str(sorted_resources[2].expired_timestamp) != "9999-12-31 00:00:00"
        assert str(sorted_resources[3].expired_timestamp) == "9999-12-31 00:00:00"
        assert str(sorted_resources[4].expired_timestamp) != "9999-12-31 00:00:00"

        tag_revisions = model.Session.query(model.PackageTagRevision).filter_by(package_id=anna1.id).all()

        sorted_tags = sorted(tag_revisions, key=lambda x: (x.revision_timestamp, x.tag.name))[::-1]

        print [(tag.state, tag.tag.name) for tag in sorted_tags]
    def test_12_make_active(self):

        anna1 = model.Session.query(model.Package).filter_by(name='annakarenina_changed2').one()
        context = {"model": model,
                   "session": model.Session,
                   'user': '******'}
        make_latest_pending_package_active(context, {'id': anna1.id})

        pkgrevisions = model.Session.query(model.PackageRevision).filter_by(id=anna1.id).all()
        sorted_packages = sorted(pkgrevisions, key=lambda x:x.revision_timestamp)[::-1]

        assert len(sorted_packages) == 4
        assert sorted_packages[0].state == 'active', sorted_packages[0].state #was pending
        assert sorted_packages[0].current == True 

        assert sorted_packages[1].state == 'pending' 
        assert sorted_packages[2].state == 'active'
        assert sorted_packages[3].state == 'active'

        resources_revisions = model.Session.query(model.ResourceRevision).filter_by(resource_group_id=anna1.resource_groups[0].id).all()
        sorted_resources = sorted(resources_revisions, key=lambda x: (x.revision_timestamp, x.url))[::-1]

        assert len(sorted_resources) == 5
        for res in sorted_resources:
            print res.id, res.revision_timestamp, res.expired_timestamp, res.state
        assert sorted_resources[0].state == 'active'
        assert sorted_resources[0].current == True
        assert sorted_resources[1].state == 'active'
        assert sorted_resources[1].current == True
        assert sorted_resources[2].state == 'active'
        assert sorted_resources[3].state == 'active'
        assert sorted_resources[3].current == True
        assert sorted_resources[4].state == 'active'

        assert str(sorted_resources[0].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_resources[1].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_resources[2].expired_timestamp) != '9999-12-31 00:00:00'
        assert str(sorted_resources[3].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_resources[4].expired_timestamp) != '9999-12-31 00:00:00'

        tag_revisions = model.Session.query(model.PackageTagRevision).filter_by(package_id=anna1.id).all()

        sorted_tags = sorted(tag_revisions, key=lambda x: (x.revision_timestamp, x.tag.name))[::-1]

        print [(tag.state, tag.tag.name) for tag in sorted_tags]
Example #4
0
    def test_12_make_active(self):

        model.repo.new_revision()
        anna1 = model.Session.query(
            model.Package).filter_by(name='annakarenina_changed2').one()
        context = {
            "model": model,
            "session": model.Session,
            'user': '******'
        }

        make_latest_pending_package_active(context, {'id': anna1.id})

        pkgrevisions = model.Session.query(
            model.PackageRevision).filter_by(id=anna1.id).all()
        sorted_packages = sorted(pkgrevisions,
                                 key=lambda x: x.revision_timestamp)[::-1]

        assert len(sorted_packages) == 4
        assert sorted_packages[0].state == 'active', sorted_packages[
            0].state  #was pending
        assert sorted_packages[0].current == True

        assert sorted_packages[1].state == 'pending'
        assert sorted_packages[2].state == 'active'
        assert sorted_packages[3].state == 'active'

        resources_revisions = model.Session.query(
            model.ResourceRevision).filter_by(
                resource_group_id=anna1.resource_groups[0].id).all()
        sorted_resources = sorted(resources_revisions,
                                  key=lambda x:
                                  (x.revision_timestamp, x.url))[::-1]

        assert len(sorted_resources) == 5
        for res in sorted_resources:
            print res.id, res.revision_timestamp, res.expired_timestamp, res.state
        assert sorted_resources[0].state == 'active'
        assert sorted_resources[0].current == True
        assert sorted_resources[1].state == 'active'
        assert sorted_resources[1].current == True
        assert sorted_resources[2].state == 'active'
        assert sorted_resources[3].state == 'active'
        assert sorted_resources[3].current == True
        assert sorted_resources[4].state == 'active'

        assert str(
            sorted_resources[0].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(
            sorted_resources[1].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(
            sorted_resources[2].expired_timestamp) != '9999-12-31 00:00:00'
        assert str(
            sorted_resources[3].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(
            sorted_resources[4].expired_timestamp) != '9999-12-31 00:00:00'

        tag_revisions = model.Session.query(
            model.PackageTagRevision).filter_by(package_id=anna1.id).all()

        sorted_tags = sorted(tag_revisions,
                             key=lambda x:
                             (x.revision_timestamp, x.tag.name))[::-1]

        print[(tag.state, tag.tag.name) for tag in sorted_tags]

        assert len(sorted_tags) == 6, len(sorted_tags)
        assert sorted_tags[0].state == 'active'  # newnew_tag
        assert sorted_tags[1].state == 'active'  # new_tag
        assert sorted_tags[2].state == 'deleted'  # Flexible
        assert sorted_tags[3].state == 'active'  # tolstoy
        assert sorted_tags[4].state == 'active'  # russian
        assert sorted_tags[5].state == 'active'  # Flexible
        assert sorted_tags[0].current
        assert sorted_tags[1].current
        assert sorted_tags[2].current
        assert not sorted_tags[5].current

        assert str(sorted_tags[0].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_tags[1].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_tags[2].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_tags[3].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_tags[4].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_tags[5].expired_timestamp) != '9999-12-31 00:00:00'

        extras_revisions = model.Session.query(
            model.PackageExtraRevision).filter_by(package_id=anna1.id).all()

        sorted_extras = sorted(extras_revisions,
                               key=lambda x:
                               (x.revision_timestamp, x.key))[::-1]

        print[(extra.state, extra.key, extra.value) for extra in sorted_extras]

        assert sorted_extras[0].state == 'active'
        assert sorted_extras[1].state == 'active'
        assert sorted_extras[2].state == 'active'
        assert sorted_extras[3].state == 'active'

        assert str(sorted_extras[0].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_extras[1].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_extras[2].expired_timestamp) == '9999-12-31 00:00:00'
        assert str(sorted_extras[3].expired_timestamp) != '9999-12-31 00:00:00'