Blame tests/test_pagure_flask_ui_repo_flag_commit.py

Pierre-Yves Chibon c43375
# -*- coding: utf-8 -*-
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
"""
Pierre-Yves Chibon c43375
 (c) 2017 - Copyright Red Hat Inc
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
 Authors:
Pierre-Yves Chibon c43375
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
"""
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 67d1cc
from __future__ import unicode_literals, absolute_import
Aurélien Bompard dcf6f6
Pierre-Yves Chibon c43375
import unittest
Pierre-Yves Chibon c43375
import sys
Pierre-Yves Chibon c43375
import os
Pierre-Yves Chibon c43375
Slavek Kabrda 45252f
from mock import patch
Pierre-Yves Chibon c43375
import pygit2
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 73d120
sys.path.insert(
Pierre-Yves Chibon 73d120
    0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 930073
import pagure.lib.query
Pierre-Yves Chibon c43375
import tests
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
class ViewCommitFlagtests(tests.SimplePagureTest):
Pierre-Yves Chibon c43375
    """ Tests for the UI related to commit flags """
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
    def setUp(self):
Pierre-Yves Chibon c43375
        """ Set up the environnment, ran before every tests. """
Pierre-Yves Chibon c43375
        super(ViewCommitFlagtests, self).setUp()
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        tests.create_projects(self.session)
Pierre-Yves Chibon c43375
        tests.create_tokens(self.session)
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # Add a README to the git repo - First commit
Pierre-Yves Chibon 73d120
        tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))
Pierre-Yves Chibon 73d120
        repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))
Pierre-Yves Chibon 73d120
        self.commit = repo.revparse_single("HEAD")
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
    def test_view_commit_no_flag(self):
Pierre-Yves Chibon c43375
        """ Test the view_commit endpoint. """
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon 73d120
        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
Pierre-Yves Chibon c43375
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            output.get_data(as_text=True),
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn(
Pierre-Yves Chibon 73d120
            "#commit-overview-collapse", output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("Merged by Alice Author", output.get_data(as_text=True))
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "Committed by Cecil Committer", output.get_data(as_text=True)
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
    def test_view_commit_pending_flag(self):
Pierre-Yves Chibon c43375
        """ Test the view_commit endpoint with a pending flag. """
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_commit_flag(
Pierre-Yves Chibon c43375
            session=self.session,
Pierre-Yves Chibon c43375
            repo=repo,
Pierre-Yves Chibon c43375
            commit_hash=self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            username="simple-koji-ci",
Pierre-Yves Chibon 73d120
            status="pending",
Pierre-Yves Chibon c43375
            percent=None,
Pierre-Yves Chibon 73d120
            comment="Build is running",
Pierre-Yves Chibon 73d120
            url="https://koji.fp.o/koji...",
Pierre-Yves Chibon 73d120
            uid="uid",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            token="aaabbbcccddd",
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, ("Flag added", "uid"))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon 73d120
        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
Pierre-Yves Chibon c43375
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 77bdcd
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("#commit-overview-collapse", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Merged by Alice Author", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Committed by Cecil Committer", output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "\n                    
Pierre-Yves Chibon 77bdcd
            'href="https://koji.fp.o/koji...">simple-koji-ci'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'pending'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("Build is running", output_text)
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
    def test_view_commit_success_flag(self):
Pierre-Yves Chibon c43375
        """ Test the view_commit endpoint with a successful flag. """
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_commit_flag(
Pierre-Yves Chibon c43375
            session=self.session,
Pierre-Yves Chibon c43375
            repo=repo,
Pierre-Yves Chibon c43375
            commit_hash=self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            username="simple-koji-ci",
Pierre-Yves Chibon 73d120
            status="success",
Pierre-Yves Chibon c43375
            percent=100,
Pierre-Yves Chibon 73d120
            comment="Build passed",
Pierre-Yves Chibon 73d120
            url="https://koji.fp.o/koji...",
Pierre-Yves Chibon 73d120
            uid="uid",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            token="aaabbbcccddd",
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, ("Flag added", "uid"))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon 73d120
        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
Pierre-Yves Chibon c43375
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 77bdcd
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("#commit-overview-collapse", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Merged by Alice Author", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Committed by Cecil Committer", output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "\n                    
Pierre-Yves Chibon 77bdcd
            'href="https://koji.fp.o/koji...">simple-koji-ci'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'success (100%)'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("Build passed", output_text)
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
    def test_view_commit_error_flag(self):
Pierre-Yves Chibon c43375
        """ Test the view_commit endpoint with a error flag. """
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_commit_flag(
Pierre-Yves Chibon c43375
            session=self.session,
Pierre-Yves Chibon c43375
            repo=repo,
Pierre-Yves Chibon c43375
            commit_hash=self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            username="simple-koji-ci",
Pierre-Yves Chibon 73d120
            status="error",
Pierre-Yves Chibon c43375
            percent=None,
Pierre-Yves Chibon 73d120
            comment="Build errored",
Pierre-Yves Chibon 73d120
            url="https://koji.fp.o/koji...",
Pierre-Yves Chibon 73d120
            uid="uid",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            token="aaabbbcccddd",
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, ("Flag added", "uid"))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon 73d120
        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
Pierre-Yves Chibon c43375
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 77bdcd
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("#commit-overview-collapse", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Merged by Alice Author", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Committed by Cecil Committer", output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "\n                    
Pierre-Yves Chibon 77bdcd
            'href="https://koji.fp.o/koji...">simple-koji-ci'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'error'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("Build errored", output_text)
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
    def test_view_commit_failure_flag(self):
Pierre-Yves Chibon c43375
        """ Test the view_commit endpoint with a failure flag. """
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_commit_flag(
Pierre-Yves Chibon c43375
            session=self.session,
Pierre-Yves Chibon c43375
            repo=repo,
Pierre-Yves Chibon c43375
            commit_hash=self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            username="simple-koji-ci",
Pierre-Yves Chibon 73d120
            status="failure",
Pierre-Yves Chibon c43375
            percent=None,
Pierre-Yves Chibon 73d120
            comment="Build failed",
Pierre-Yves Chibon 73d120
            url="https://koji.fp.o/koji...",
Pierre-Yves Chibon 73d120
            uid="uid",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            token="aaabbbcccddd",
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, ("Flag added", "uid"))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon 73d120
        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
Pierre-Yves Chibon c43375
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 77bdcd
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("#commit-overview-collapse", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Merged by Alice Author", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Committed by Cecil Committer", output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    '
Pierre-Yves Chibon 73d120
            "simple-koji-ci\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'failure'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("Build failed", output_text)
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
    def test_view_commit_canceled_flag(self):
Pierre-Yves Chibon c43375
        """ Test the view_commit endpoint with a canceled flag. """
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_commit_flag(
Pierre-Yves Chibon c43375
            session=self.session,
Pierre-Yves Chibon c43375
            repo=repo,
Pierre-Yves Chibon c43375
            commit_hash=self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            username="simple-koji-ci",
Pierre-Yves Chibon 73d120
            status="canceled",
Pierre-Yves Chibon c43375
            percent=None,
Pierre-Yves Chibon 73d120
            comment="Build canceled",
Pierre-Yves Chibon 73d120
            url="https://koji.fp.o/koji...",
Pierre-Yves Chibon 73d120
            uid="uid",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            token="aaabbbcccddd",
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, ("Flag added", "uid"))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon 73d120
        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
Pierre-Yves Chibon c43375
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 77bdcd
        output_text = output.get_data(as_text=True)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 73d120
            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("#commit-overview-collapse", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Merged by Alice Author", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Committed by Cecil Committer", output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    '
Pierre-Yves Chibon 73d120
            "simple-koji-ci\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'canceled'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("Build canceled", output_text)
Pierre-Yves Chibon 73d120
Pierre-Yves Chibon 73d120
    @patch.dict(
Pierre-Yves Chibon 73d120
        "pagure.config.config",
Pierre-Yves Chibon 73d120
        {
Pierre-Yves Chibon 73d120
            "FLAG_STATUSES_LABELS": {
Pierre-Yves Chibon 73d120
                "status1": "badge-warning",
Pierre-Yves Chibon 73d120
                "otherstatus": "badge-success",
Pierre-Yves Chibon 73d120
            }
Pierre-Yves Chibon 73d120
        },
Pierre-Yves Chibon 73d120
    )
Slavek Kabrda 45252f
    def test_view_commit_with_custom_flags(self):
Slavek Kabrda 45252f
        """ Test the view_commit endpoint while having custom flags. """
Pierre-Yves Chibon 73d120
        repo = pagure.lib.query.get_authorized_project(self.session, "test")
Slavek Kabrda 45252f
Pierre-Yves Chibon 930073
        msg = pagure.lib.query.add_commit_flag(
Slavek Kabrda 45252f
            session=self.session,
Slavek Kabrda 45252f
            repo=repo,
Slavek Kabrda 45252f
            commit_hash=self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            username="simple-koji-ci",
Pierre-Yves Chibon 73d120
            status="status1",
Slavek Kabrda 45252f
            percent=None,
Pierre-Yves Chibon 73d120
            comment="Build canceled",
Pierre-Yves Chibon 73d120
            url="https://koji.fp.o/koji...",
Pierre-Yves Chibon 73d120
            uid="uid",
Pierre-Yves Chibon 73d120
            user="foo",
Pierre-Yves Chibon 73d120
            token="aaabbbcccddd",
Slavek Kabrda 45252f
        )
Slavek Kabrda 45252f
        self.session.commit()
Pierre-Yves Chibon 73d120
        self.assertEqual(msg, ("Flag added", "uid"))
Slavek Kabrda 45252f
Slavek Kabrda 45252f
        # View first commit
Pierre-Yves Chibon 73d120
        output = self.app.get("/test/c/%s" % self.commit.oid.hex)
Slavek Kabrda 45252f
        self.assertEqual(output.status_code, 200)
Pierre-Yves Chibon 77bdcd
        output_text = output.get_data(as_text=True)
Slavek Kabrda 45252f
        self.assertIn(
Pierre-Yves Chibon 73d120
            "<title>Commit - test - %s - Pagure</title>" % self.commit.oid.hex,
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("#commit-overview-collapse", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Merged by Alice Author", output_text)
Pierre-Yves Chibon 73d120
        self.assertIn("Committed by Cecil Committer", output_text)
Slavek Kabrda 45252f
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    '
Pierre-Yves Chibon 73d120
            "simple-koji-ci\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Slavek Kabrda 45252f
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'status1'
Pierre-Yves Chibon 73d120
            "\n                  ",
Pierre-Yves Chibon 73d120
            output_text,
Pierre-Yves Chibon 73d120
        )
Pierre-Yves Chibon 73d120
        self.assertIn("Build canceled", output_text)
Slavek Kabrda 45252f
Pierre-Yves Chibon c43375
Pierre-Yves Chibon 73d120
if __name__ == "__main__":
Pierre-Yves Chibon c43375
    unittest.main(verbosity=2)