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