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
Aurélien Bompard dcf6f6
from __future__ import unicode_literals
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 c43375
sys.path.insert(0, os.path.join(os.path.dirname(
Pierre-Yves Chibon c43375
    os.path.abspath(__file__)), '..'))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
import pagure
Pierre-Yves Chibon c43375
import pagure.lib
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 c43375
        tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon c43375
        repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git'))
Pierre-Yves Chibon c43375
        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 c43375
        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 c43375
            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
Aurélien Bompard 626417
            output.get_data(as_text=True))
Pierre-Yves Chibon c43375
        self.assertIn(
Ryan Lerch e2f045
            '#commit-overview-collapse',
Aurélien Bompard 626417
            output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertIn('Merged by Alice Author', output.get_data(as_text=True))
Ryan Lerch e2f045
        self.assertIn('Committed by Cecil Committer', output.get_data(as_text=True))
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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        msg = pagure.lib.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 c43375
            username='simple-koji-ci',
Pierre-Yves Chibon c43375
            status='pending',
Pierre-Yves Chibon c43375
            percent=None,
Pierre-Yves Chibon c43375
            comment='Build is running',
Pierre-Yves Chibon c43375
            url='https://koji.fp.o/koji...',
Pierre-Yves Chibon c43375
            uid='uid',
Pierre-Yves Chibon c43375
            user='foo',
Pierre-Yves Chibon c43375
            token='aaabbbcccddd'
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon c43375
        self.assertEqual(msg, ('Flag added', 'uid'))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon c43375
        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 c43375
            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Ryan Lerch e2f045
            '#commit-overview-collapse',
Pierre-Yves Chibon 77bdcd
            output_text)
Ryan Lerch e2f045
        self.assertIn('Merged by Alice Author', output_text)
Ryan Lerch e2f045
        self.assertIn('Committed by Cecil Committer', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    
Pierre-Yves Chibon 77bdcd
            'href="https://koji.fp.o/koji...">simple-koji-ci'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'pending'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        msg = pagure.lib.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 c43375
            username='simple-koji-ci',
Pierre-Yves Chibon c43375
            status='success',
Pierre-Yves Chibon c43375
            percent=100,
Pierre-Yves Chibon c43375
            comment='Build passed',
Pierre-Yves Chibon c43375
            url='https://koji.fp.o/koji...',
Pierre-Yves Chibon c43375
            uid='uid',
Pierre-Yves Chibon c43375
            user='foo',
Pierre-Yves Chibon c43375
            token='aaabbbcccddd'
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon c43375
        self.assertEqual(msg, ('Flag added', 'uid'))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon c43375
        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 c43375
            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Ryan Lerch e2f045
            '#commit-overview-collapse',
Pierre-Yves Chibon 77bdcd
            output_text)
Ryan Lerch e2f045
        self.assertIn('Merged by Alice Author', output_text)
Ryan Lerch e2f045
        self.assertIn('Committed by Cecil Committer', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    
Pierre-Yves Chibon 77bdcd
            'href="https://koji.fp.o/koji...">simple-koji-ci'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'success (100%)'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        msg = pagure.lib.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 c43375
            username='simple-koji-ci',
Pierre-Yves Chibon c43375
            status='error',
Pierre-Yves Chibon c43375
            percent=None,
Pierre-Yves Chibon c43375
            comment='Build errored',
Pierre-Yves Chibon c43375
            url='https://koji.fp.o/koji...',
Pierre-Yves Chibon c43375
            uid='uid',
Pierre-Yves Chibon c43375
            user='foo',
Pierre-Yves Chibon c43375
            token='aaabbbcccddd'
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon c43375
        self.assertEqual(msg, ('Flag added', 'uid'))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon c43375
        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 c43375
            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Ryan Lerch e2f045
            '#commit-overview-collapse',
Pierre-Yves Chibon 77bdcd
            output_text)
Ryan Lerch e2f045
        self.assertIn('Merged by Alice Author', output_text)
Ryan Lerch e2f045
        self.assertIn('Committed by Cecil Committer', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    
Pierre-Yves Chibon 77bdcd
            'href="https://koji.fp.o/koji...">simple-koji-ci'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'error'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        msg = pagure.lib.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 c43375
            username='simple-koji-ci',
Pierre-Yves Chibon c43375
            status='failure',
Pierre-Yves Chibon c43375
            percent=None,
Pierre-Yves Chibon c43375
            comment='Build failed',
Pierre-Yves Chibon c43375
            url='https://koji.fp.o/koji...',
Pierre-Yves Chibon c43375
            uid='uid',
Pierre-Yves Chibon c43375
            user='foo',
Pierre-Yves Chibon c43375
            token='aaabbbcccddd'
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon c43375
        self.assertEqual(msg, ('Flag added', 'uid'))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon c43375
        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 c43375
            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Ryan Lerch e2f045
            '#commit-overview-collapse',
Pierre-Yves Chibon 77bdcd
            output_text)
Ryan Lerch e2f045
        self.assertIn('Merged by Alice Author', output_text)
Ryan Lerch e2f045
        self.assertIn('Committed by Cecil Committer', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    '
Pierre-Yves Chibon 77bdcd
            'simple-koji-ci\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'failure'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '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 b130e5
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        msg = pagure.lib.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 c43375
            username='simple-koji-ci',
Pierre-Yves Chibon c43375
            status='canceled',
Pierre-Yves Chibon c43375
            percent=None,
Pierre-Yves Chibon c43375
            comment='Build canceled',
Pierre-Yves Chibon c43375
            url='https://koji.fp.o/koji...',
Pierre-Yves Chibon c43375
            uid='uid',
Pierre-Yves Chibon c43375
            user='foo',
Pierre-Yves Chibon c43375
            token='aaabbbcccddd'
Pierre-Yves Chibon c43375
        )
Pierre-Yves Chibon b130e5
        self.session.commit()
Pierre-Yves Chibon c43375
        self.assertEqual(msg, ('Flag added', 'uid'))
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
        # View first commit
Pierre-Yves Chibon c43375
        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 c43375
            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
Pierre-Yves Chibon 77bdcd
            output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Ryan Lerch e2f045
            '#commit-overview-collapse',
Pierre-Yves Chibon 77bdcd
            output_text)
Ryan Lerch e2f045
        self.assertIn('Merged by Alice Author', output_text)
Ryan Lerch e2f045
        self.assertIn('Committed by Cecil Committer', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    '
Pierre-Yves Chibon 77bdcd
            'simple-koji-ci\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'canceled'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Pierre-Yves Chibon c43375
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            'Build canceled', output_text)
Pierre-Yves Chibon c43375
Slavek Kabrda 45252f
    @patch.dict('pagure.config.config',
Slavek Kabrda 45252f
                {
Slavek Kabrda 45252f
                    'FLAG_STATUSES_LABELS':
Slavek Kabrda 45252f
                        {
Ryan Lerch 2aa95c
                            'status1': 'badge-warning',
Ryan Lerch 2aa95c
                            'otherstatus': 'badge-success',
Slavek Kabrda 45252f
                        },
Slavek Kabrda 45252f
                })
Slavek Kabrda 45252f
    def test_view_commit_with_custom_flags(self):
Slavek Kabrda 45252f
        """ Test the view_commit endpoint while having custom flags. """
Slavek Kabrda 45252f
        repo = pagure.lib.get_authorized_project(self.session, 'test')
Slavek Kabrda 45252f
Slavek Kabrda 45252f
        msg = pagure.lib.add_commit_flag(
Slavek Kabrda 45252f
            session=self.session,
Slavek Kabrda 45252f
            repo=repo,
Slavek Kabrda 45252f
            commit_hash=self.commit.oid.hex,
Slavek Kabrda 45252f
            username='simple-koji-ci',
Slavek Kabrda 45252f
            status='status1',
Slavek Kabrda 45252f
            percent=None,
Slavek Kabrda 45252f
            comment='Build canceled',
Slavek Kabrda 45252f
            url='https://koji.fp.o/koji...',
Slavek Kabrda 45252f
            uid='uid',
Slavek Kabrda 45252f
            user='foo',
Slavek Kabrda 45252f
            token='aaabbbcccddd'
Slavek Kabrda 45252f
        )
Slavek Kabrda 45252f
        self.session.commit()
Slavek Kabrda 45252f
        self.assertEqual(msg, ('Flag added', 'uid'))
Slavek Kabrda 45252f
Slavek Kabrda 45252f
        # View first commit
Slavek Kabrda 45252f
        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(
Slavek Kabrda 45252f
            '<title>Commit - test - %s - Pagure</title>' % self.commit.oid.hex,
Pierre-Yves Chibon 77bdcd
            output_text)
Slavek Kabrda 45252f
        self.assertIn(
Ryan Lerch e2f045
            '#commit-overview-collapse',
Pierre-Yves Chibon 77bdcd
            output_text)
Ryan Lerch e2f045
        self.assertIn('Merged by Alice Author', output_text)
Ryan Lerch e2f045
        self.assertIn('Committed by Cecil Committer', output_text)
Slavek Kabrda 45252f
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '\n                    '
Pierre-Yves Chibon 77bdcd
            'simple-koji-ci\n                  ', output_text)
Slavek Kabrda 45252f
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            '
\n '
Ryan Lerch 2aa95c
            'status1'
Pierre-Yves Chibon 77bdcd
            '\n                  ', output_text)
Slavek Kabrda 45252f
        self.assertIn(
Pierre-Yves Chibon 77bdcd
            'Build canceled', output_text)
Slavek Kabrda 45252f
Pierre-Yves Chibon c43375
Pierre-Yves Chibon c43375
if __name__ == '__main__':
Pierre-Yves Chibon c43375
    unittest.main(verbosity=2)