Example #1
0
 def test_ecosystem_backend_links(self):
     """ Test the Ecosystem.by_name function. """
     import anitya.lib.plugins as plugins
     plugins.load_plugins(self.session)
     ecosystems = model.Ecosystem.all(self.session)
     for ecosystem in ecosystems:
         self.assertEqual(ecosystem.default_backend.default_ecosystem.name,
                          ecosystem.name)
Example #2
0
 def test_ecosystem_backend_links(self):
     """ Test the Ecosystem.by_name function. """
     import anitya.lib.plugins as plugins
     plugins.load_plugins(self.session)
     ecosystems = model.Ecosystem.all(self.session)
     for ecosystem in ecosystems:
         self.assertEqual(ecosystem.default_backend.default_ecosystem.name,
                          ecosystem.name)
Example #3
0
def edit_project(project_id):

    project = models.Project.get(Session, project_id)
    if not project:
        flask.abort(404)

    # Archived project is not editable
    if project.archived:
        flask.abort(404)

    backend_plugins = anitya_plugins.load_plugins(Session)
    plg_names = [plugin.name for plugin in backend_plugins]
    version_plugins = anitya_plugins.load_plugins(Session, family="versions")
    version_plg_names = [plugin.name for plugin in version_plugins]

    form = anitya.forms.ProjectForm(backends=plg_names,
                                    version_schemes=version_plg_names,
                                    obj=project)

    if form.validate_on_submit():
        try:
            changes = utilities.edit_project(
                Session,
                project=project,
                name=form.name.data.strip(),
                homepage=form.homepage.data.strip(),
                backend=form.backend.data.strip(),
                version_scheme=form.version_scheme.data.strip(),
                version_pattern=form.version_pattern.data.strip(),
                version_url=form.version_url.data.strip(),
                version_prefix=form.version_prefix.data.strip(),
                pre_release_filter=form.pre_release_filter.data.strip(),
                version_filter=form.version_filter.data.strip(),
                regex=form.regex.data.strip(),
                insecure=form.insecure.data,
                user_id=flask.g.user.username,
                check_release=form.check_release.data,
                releases_only=form.releases_only.data,
            )
            if changes:
                flask.flash("Project edited")
            else:
                flask.flash("Project edited - No changes were made")
            flask.session["justedit"] = True
        except exceptions.AnityaException as err:
            flask.flash(str(err), "errors")

        return flask.redirect(
            flask.url_for("anitya_ui.project", project_id=project_id))

    return flask.render_template(
        "project_new.html",
        context="Edit",
        current="projects",
        form=form,
        project=project,
        plugins=backend_plugins,
    )
Example #4
0
    def test_ecosystem_by_name(self):
        """ Test the Ecosystem.by_name function. """
        import anitya.lib.plugins as plugins
        plugins.load_plugins(self.session)
        ecosystem = model.Ecosystem.by_name(self.session, 'pypi')
        self.assertEqual(ecosystem.name, 'pypi')

        ecosystem = model.Ecosystem.by_name(self.session, 'PyPI')
        self.assertEqual(ecosystem, None)
Example #5
0
    def test_backend_by_name(self):
        """ Test the Backend.by_name function. """
        import anitya.lib.plugins as plugins
        plugins.load_plugins(self.session)
        backend = model.Backend.by_name(self.session, 'PyPI')
        self.assertEqual(backend.name, 'PyPI')

        backend = model.Backend.by_name(self.session, 'pypi')
        self.assertEqual(backend, None)
Example #6
0
    def test_backend_by_name(self):
        """ Test the Backend.by_name function. """
        import anitya.lib.plugins as plugins
        plugins.load_plugins(self.session)
        backend = model.Backend.by_name(self.session, 'PyPI')
        self.assertEqual(backend.name, 'PyPI')

        backend = model.Backend.by_name(self.session, 'pypi')
        self.assertEqual(backend, None)
Example #7
0
    def test_ecosystem_by_name(self):
        """ Test the Ecosystem.by_name function. """
        import anitya.lib.plugins as plugins
        plugins.load_plugins(self.session)
        ecosystem = model.Ecosystem.by_name(self.session, 'pypi')
        self.assertEqual(ecosystem.name, 'pypi')

        ecosystem = model.Ecosystem.by_name(self.session, 'PyPI')
        self.assertEqual(ecosystem, None)
Example #8
0
def edit_project(project_id):

    project = models.Project.get(Session, project_id)
    if not project:
        flask.abort(404)

    backend_plugins = anitya_plugins.load_plugins(Session)
    plg_names = [plugin.name for plugin in backend_plugins]
    version_plugins = anitya_plugins.load_plugins(Session, family='versions')
    version_plg_names = [plugin.name for plugin in version_plugins]

    form = anitya.forms.ProjectForm(
        backends=plg_names,
        version_schemes=version_plg_names,
        obj=project)

    if form.validate_on_submit():
        try:
            changes = utilities.edit_project(
                Session,
                project=project,
                name=form.name.data.strip(),
                homepage=form.homepage.data.strip(),
                backend=form.backend.data.strip(),
                version_scheme=form.version_scheme.data.strip(),
                version_url=form.version_url.data.strip(),
                version_prefix=form.version_prefix.data.strip(),
                regex=form.regex.data.strip(),
                insecure=form.insecure.data,
                user_id=flask.g.user.username,
                check_release=form.check_release.data,
            )
            if changes:
                flask.flash('Project edited')
            else:
                flask.flash('Project edited - No changes were made')
            flask.session['justedit'] = True
        except exceptions.AnityaException as err:
            flask.flash(str(err), 'errors')

        return flask.redirect(
            flask.url_for('anitya_ui.project', project_id=project_id)
        )

    return flask.render_template(
        'project_new.html',
        context='Edit',
        current='projects',
        form=form,
        project=project,
        plugins=backend_plugins,
    )
Example #9
0
    def test_load_plugins(self):
        """ Test the plugins.load_plugins function. """
        plgns = [plg.name for plg in plugins.load_plugins(self.session)]
        self.assertEqual(len(plgns), 23)
        exp = [
            'CPAN (perl)',
            'Debian project',
            'Drupal6',
            'Drupal7',
            'Freshmeat',
            'GNOME',
            'GNU project',
            'GitHub',
            'Google code',
            'Hackage',
            'Launchpad',
            'Maven Central',
            'PEAR',
            'PECL',
            'Packagist',
            'PyPI',
            'Rubygems',
            'Sourceforge',
            'Stackage',
            'custom',
            'folder',
            'npmjs',
            'pagure',
        ]

        self.assertEqual(sorted(plgns), exp)
Example #10
0
    def test_load_plugins(self):
        """ Test the plugins.load_plugins function. """
        backend_plugins = plugins.load_plugins(self.session)
        self.assertEqual(len(backend_plugins), len(EXPECTED_BACKENDS))
        backend_names = sorted(plugin.name for plugin in backend_plugins)
        self.assertEqual(sorted(backend_names), sorted(EXPECTED_BACKENDS))

        self._check_db_contents(EXPECTED_BACKENDS, EXPECTED_ECOSYSTEMS)
Example #11
0
    def test_load_plugins(self):
        """ Test the plugins.load_plugins function. """
        backend_plugins = plugins.load_plugins(self.session)
        self.assertEqual(len(backend_plugins), len(EXPECTED_BACKENDS))
        backend_names = sorted(plugin.name for plugin in backend_plugins)
        self.assertEqual(backend_names, EXPECTED_BACKENDS)

        self._check_db_contents(EXPECTED_BACKENDS, EXPECTED_ECOSYSTEMS)
Example #12
0
    def test_load_plugins(self):
        """ Test the plugins.load_plugins function. """
        plgns = [plg.name for plg in plugins.load_plugins(self.session)]
        self.assertEqual(len(plgns), 21)
        exp = [
            'CPAN (perl)', 'Debian project', 'Drupal6', 'Drupal7', 'Freshmeat',
            'GNOME', 'GNU project', 'Github', 'Google code', 'Hackage',
            'Launchpad', 'Maven Central', 'PEAR', 'PECL', 'Packagist', 'PyPI',
            'Rubygems', 'Sourceforge', 'custom', 'folder', 'npmjs',
        ]

        self.assertEqual(sorted(plgns), exp)
Example #13
0
def new_project():
    """
    View for creating a new project.

    This function accepts GET and POST requests. POST requests can result in
    a HTTP 400 for invalid forms, a HTTP 409 if the request conflicts with an
    existing project, or a HTTP 302 redirect to the new project.
    """
    backend_plugins = anitya_plugins.load_plugins(Session)
    plg_names = [plugin.name for plugin in backend_plugins]
    version_plugins = anitya_plugins.load_plugins(Session, family="versions")
    version_plg_names = [plugin.name for plugin in version_plugins]
    # Get all available distros name
    distros = models.Distro.all(Session)
    distro_names = []
    for distro in distros:
        distro_names.append(distro.name)

    form = anitya.forms.ProjectForm(backends=plg_names,
                                    version_schemes=version_plg_names,
                                    distros=distro_names)

    if flask.request.method == "GET":
        form.name.data = flask.request.args.get("name", "")
        form.homepage.data = flask.request.args.get("homepage", "")
        form.backend.data = flask.request.args.get("backend", "")
        form.version_scheme.data = flask.request.args.get("version_scheme", "")
        form.distro.data = flask.request.args.get("distro", "")
        form.package_name.data = flask.request.args.get("package_name", "")
        return flask.render_template(
            "project_new.html",
            context="Add",
            current="Add projects",
            form=form,
            plugins=backend_plugins,
        )
    elif form.validate_on_submit():
        project = None
        try:
            project = utilities.create_project(
                Session,
                name=form.name.data.strip(),
                homepage=form.homepage.data.strip(),
                backend=form.backend.data.strip(),
                version_scheme=form.version_scheme.data.strip(),
                version_url=form.version_url.data.strip() or None,
                version_prefix=form.version_prefix.data.strip() or None,
                pre_release_filter=form.pre_release_filter.data.strip()
                or None,
                version_filter=form.version_filter.data.strip() or None,
                regex=form.regex.data.strip() or None,
                user_id=flask.g.user.username,
                releases_only=form.releases_only.data,
            )
            Session.commit()

            # Optionally, the user can also map a distro when creating a proj.
            if form.distro.data and form.package_name.data:
                utilities.map_project(
                    Session,
                    project=project,
                    package_name=form.package_name.data,
                    distribution=form.distro.data,
                    user_id=flask.g.user.username,
                )
                Session.commit()

            flask.flash("Project created")
        except exceptions.AnityaException as err:
            flask.flash(str(err))
            return (
                flask.render_template(
                    "project_new.html",
                    context="Add",
                    current="Add projects",
                    form=form,
                    plugins=backend_plugins,
                ),
                409,
            )

        if form.check_release.data is True:
            try:
                utilities.check_project_release(project, Session)
            except exceptions.AnityaException:
                flask.flash("Check failed")

        return flask.redirect(
            flask.url_for("anitya_ui.project", project_id=project.id))

    return (
        flask.render_template(
            "project_new.html",
            context="Add",
            current="Add projects",
            form=form,
            plugins=backend_plugins,
        ),
        400,
    )
Example #14
0
def new_project():
    """
    View for creating a new project.

    This function accepts GET and POST requests. POST requests can result in
    a HTTP 400 for invalid forms, a HTTP 409 if the request conflicts with an
    existing project, or a HTTP 302 redirect to the new project.
    """
    backend_plugins = anitya_plugins.load_plugins(Session)
    plg_names = [plugin.name for plugin in backend_plugins]
    version_plugins = anitya_plugins.load_plugins(Session, family='versions')
    version_plg_names = [plugin.name for plugin in version_plugins]
    form = anitya.forms.ProjectForm(backends=plg_names,
                                    version_schemes=version_plg_names)

    if flask.request.method == 'GET':
        form.name.data = flask.request.args.get('name', '')
        form.homepage.data = flask.request.args.get('homepage', '')
        form.backend.data = flask.request.args.get('backend', '')
        form.version_scheme.data = flask.request.args.get('version_scheme', '')
        form.distro.data = flask.request.args.get('distro', '')
        form.package_name.data = flask.request.args.get('package_name', '')
        return flask.render_template(
            'project_new.html',
            context='Add',
            current='Add projects',
            form=form,
            plugins=backend_plugins,
        )
    elif form.validate_on_submit():
        project = None
        try:
            project = utilities.create_project(
                Session,
                name=form.name.data.strip(),
                homepage=form.homepage.data.strip(),
                backend=form.backend.data.strip(),
                version_scheme=form.version_scheme.data.strip(),
                version_url=form.version_url.data.strip() or None,
                version_prefix=form.version_prefix.data.strip() or None,
                regex=form.regex.data.strip() or None,
                user_id=flask.g.user.username,
                check_release=form.check_release.data,
            )
            Session.commit()

            # Optionally, the user can also map a distro when creating a proj.
            if form.distro.data and form.package_name.data:
                utilities.map_project(
                    Session,
                    project=project,
                    package_name=form.package_name.data,
                    distribution=form.distro.data,
                    user_id=flask.g.user.username,
                )
                Session.commit()

            flask.flash('Project created')
        except exceptions.AnityaException as err:
            flask.flash(str(err))
            return flask.render_template('project_new.html',
                                         context='Add',
                                         current='Add projects',
                                         form=form,
                                         plugins=backend_plugins), 409

        return flask.redirect(
            flask.url_for('anitya_ui.project', project_id=project.id))

    return flask.render_template('project_new.html',
                                 context='Add',
                                 current='Add projects',
                                 form=form,
                                 plugins=backend_plugins), 400
Example #15
0
 def test_load_plugins(self):
     """ Test the plugins.load_plugins function. """
     backend_plugins = plugins.load_plugins(self.session)
     self.assertEqual(len(backend_plugins), len(EXPECTED_BACKENDS))
     backend_names = sorted(plugin.name for plugin in backend_plugins)
     self.assertEqual(sorted(backend_names), sorted(EXPECTED_BACKENDS))