Example #1
0
def flag_project(project_id):

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

    form = anitya.forms.FlagProjectForm(obj=project)

    if form.validate_on_submit():
        try:
            utilities.flag_project(
                Session,
                project=project,
                reason=form.reason.data,
                user_email=flask.g.user.email,
                user_id=flask.g.user.username,
            )
            flask.flash("Project flagged for admin review")
        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_flag.html",
        context="Flag",
        current="projects",
        form=form,
        project=project,
    )
Example #2
0
def flag_project(project_id):

    project = anitya.lib.model.Project.get(SESSION, project_id)
    if not project:
        flask.abort(404)

    form = anitya.forms.FlagProjectForm(obj=project)

    if form.validate_on_submit():
        try:
            utilities.flag_project(
                SESSION,
                project=project,
                reason=form.reason.data,
                user_email=flask.g.auth.email,
                user_id=flask.g.auth.openid,
            )
            flask.flash('Project flagged for admin review')
        except anitya.lib.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_flag.html',
        context='Flag',
        current='projects',
        form=form,
        project=project,
    )
Example #3
0
def create_flagged_project(session):
    """ Create and flag a project. Returns the ProjectFlag. """
    project = utilities.create_project(
        session,
        name='geany',
        homepage='http://www.geany.org/',
        version_url='http://www.geany.org/Download/Releases',
        regex='DEFAULT',
        user_id='*****@*****.**',
    )

    session.add(project)

    flag = utilities.flag_project(
        session,
        project,
        "This is a duplicate.",
        "*****@*****.**",
        "user_openid_id",
    )

    session.add(flag)

    session.commit()
    return flag
Example #4
0
    def test_flag_project(self):
        """ Test flag creation """
        create_project(self.session)

        project_obj = models.Project.get(self.session, 1)
        self.assertEqual(len(project_obj.flags), 0)

        utilities.flag_project(
            self.session,
            project=project_obj,
            reason="reason",
            user_email="*****@*****.**",
            user_id="*****@*****.**",
        )

        project_obj = models.Project.get(self.session, 1)
        self.assertEqual(len(project_obj.flags), 1)
        self.assertEqual(project_obj.flags[0].reason, "reason")
Example #5
0
    def test_flag_project(self):
        """ Test flag creation """
        create_project(self.session)

        project_obj = models.Project.get(self.session, 1)
        self.assertEqual(len(project_obj.flags), 0)

        utilities.flag_project(
            self.session,
            project=project_obj,
            reason="reason",
            user_email="*****@*****.**",
            user_id="*****@*****.**",
        )

        project_obj = models.Project.get(self.session, 1)
        self.assertEqual(len(project_obj.flags), 1)
        self.assertEqual(project_obj.flags[0].reason, "reason")
Example #6
0
    def test_flag_project(self):
        """ Test flag creation """
        create_project(self.session)

        project_obj = models.Project.get(self.session, 1)
        self.assertEqual(len(project_obj.flags), 0)

        with fml_testing.mock_sends(anitya_schema.ProjectFlag):
            utilities.flag_project(
                self.session,
                project=project_obj,
                reason="reason",
                user_email="*****@*****.**",
                user_id="*****@*****.**",
            )

        project_obj = models.Project.get(self.session, 1)
        self.assertEqual(len(project_obj.flags), 1)
        self.assertEqual(project_obj.flags[0].reason, "reason")
Example #7
0
    def test_project_flag_search_count(self):
        """
        Assert that 'ProjectFlag.search' returns correct project
        if count is set.
        """
        flag = create_flagged_project(self.session)
        flag_add = utilities.flag_project(
            self.session,
            flag.project,
            "This is a duplicate.",
            "*****@*****.**",
            "user_openid_id",
        )
        flag_add.state = "closed"
        self.session.add(flag_add)
        self.session.commit()

        flags = models.ProjectFlag.search(self.session, count=True)
        self.assertEqual(flags, 2)
Example #8
0
    def test_project_flag_search_by_state(self):
        """
        Assert that 'ProjectFlag.search' returns correct project
        if state is provided.
        """
        flag = create_flagged_project(self.session)
        flag_add = utilities.flag_project(
            self.session,
            flag.project,
            "This is a duplicate.",
            "*****@*****.**",
            "user_openid_id",
        )
        flag_add.state = "closed"
        self.session.add(flag_add)
        self.session.commit()

        flags = models.ProjectFlag.search(self.session, state="open")
        self.assertEqual(len(flags), 1)
Example #9
0
    def test_project_flag_search_count(self):
        """
        Assert that 'ProjectFlag.search' returns correct project
        if count is set.
        """
        flag = create_flagged_project(self.session)
        flag_add = utilities.flag_project(
            self.session,
            flag.project,
            "This is a duplicate.",
            "*****@*****.**",
            "user_openid_id",
        )
        flag_add.state = "closed"
        self.session.add(flag_add)
        self.session.commit()

        flags = models.ProjectFlag.search(self.session, count=True)
        self.assertEqual(flags, 2)
Example #10
0
    def test_project_flag_search_by_state(self):
        """
        Assert that 'ProjectFlag.search' returns correct project
        if state is provided.
        """
        flag = create_flagged_project(self.session)
        flag_add = utilities.flag_project(
            self.session,
            flag.project,
            "This is a duplicate.",
            "*****@*****.**",
            "user_openid_id",
        )
        flag_add.state = "closed"
        self.session.add(flag_add)
        self.session.commit()

        flags = models.ProjectFlag.search(self.session, state="open")
        self.assertEqual(len(flags), 1)
Example #11
0
    def test_project_flag_search_limit(self):
        """
        Assert that 'ProjectFlag.search' returns correct project
        if limit is set.
        """
        flag = create_flagged_project(self.session)
        with fml_testing.mock_sends(anitya_schema.ProjectFlag):
            flag_add = utilities.flag_project(
                self.session,
                flag.project,
                "This is a duplicate.",
                "*****@*****.**",
                "user_openid_id",
            )
        flag_add.state = "closed"
        self.session.add(flag_add)
        self.session.commit()

        flags = models.ProjectFlag.search(self.session, limit=1)
        self.assertEqual(len(flags), 1)